以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  下载  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=105653)

--  作者:刘林
--  发布时间:2017/8/23 16:51:00
--  下载

Dim e As RequestEventArgs = args(0)
Dim  cmd As new SQLCommand
cmd.Co
Dim dr As DataRow = DataTables("用户").sqlfind("身份证号 = \'" & e.Cookies("username") & "\'")
Dim  nms() As String
Dim zds() As String
If e.postvalues("bj")="初中"
    If e.PostValues.ContainsKey("cjms") Then
        If e.postvalues("cjms") = "普通模式" Then
            nms = new String() {"班级全称","姓名","语文","数学","英语","政治","历史","生物","地理","物理","化学","总分","总分班序","总分校序"}
            zds = new String() {"班级全称","姓名","语文_语总","数学_数总","英语_英总","政治_政总","历史_历总","生物_","地理_","物理_物总","化学_化总","总分","总分班序","总分校序"}
            cmd.CommandText= "selt 班级全称,考试名称,姓名,语文_语总,数学_数总,英语_英总,政治_政总,历史_历总,生物_,地理_,物理_物总,化学_化总,总分,总分班序,总分校序,免统审核 From {成绩}  where 单位名称 = \'" & dr("group") & "\' And 考试名称 =  \'" & e.PostValues("ksmc") & "\' order by 班级全称,总分 desc"  \'班级全称 = \'" & e.postvalues("bj") & "\' and
        End If
        If e.postvalues("cjms") = "加试模式" Then
            nms = new String() {"班级全称","姓名","语文A","语文B","数学A","数学B","英语A","英语B","政治A","政治B","历史A","历史B","生物","地理","物理A","物理B","化学A","化学B","折总","班序","校序"}
            zds = new String() {"班级全称","姓名","语文_A","语文_B","数学_A","数学_B","英语_A","英语_B","政治_A","政治_B","历史_A","历史_B","生物_","地理_","物理_A","物理_B","化学_A","化学_B","折总","班序","校序"}
            cmd.CommandText= "set 班级全称,考试名称,姓名,语文_A,语文_B,数学_A,数学_B,英语_A,英语_B,政治_A,政治_B,历史_A,历史_B,生物_,地理_,物理_A,物理_B,化学_A,化学_B,折总,班序,校序,免统审核 From {成绩} where 单位名称 = \'" & dr("group") & "\' And 考试名称 =  \'" & e.PostValues("ksmc") & "\' order by 班级全称,折总 desc"
        End If
    End If
End If
If e.postvalues("bj")="小学"
    nms = new String() {"班级全称","姓名","语文","数学","英语","思品","科学","双科总分","总分班序","总分校序"}
    zds = new String() {"班级全称","姓名","语文_语总","数学_数总","英语","思品","科学","总分","总分班序","总分校序"}
    cmd.CommandText= "se 班级全称,考试名称,姓名,语文_语总,数学_数总,英语,思品,科学,总分,总分班序,总分校序,免统审核 From {成绩}  where 单位名称 = \'" & dr("group") & "\' And 考试名称 =  \'" & e.PostValues("ksmc") & "\' order by 班级全称,总分 desc"
End If
Dim dt As DataTable = cmd.ExecuteReader
Dim  Book As New XLS.Book
Dim  Sheet As XLS.Sheet = Book.Sheets(0)
sheet(0,0).value = dr("group") & e.postvalues("ksmc") & "成绩表"
For c As Integer = 0 To nms.Length - 1
    Sheet(1, c).Value = nms(c)
Next
For r As Integer = 0 To dt.DataRows.Count - 1
    For c As Integer = 0 To zds.Length - 1
        Sheet(r+2, c).Value = dt.Datarows(r)(zds(c))
    Next
Next
Dim h As Integer = dt.DataRows.count
For c As Integer = 2 To nms.Length - 1
 Sheet(h+2, c).Value = nms(c)
Next
Dim i As Integer=1
Dim bjqcs As List(Of String) = dt.GetValues("班级全称")
For Each bjqc As String In bjqcs
 sheet(h+2+i,0).value=bjqc & "平均分"
   For c1 As Integer = 2 To dt.DataCols.count -5
      sheet(h+2+i,c1).value = Format(dt.compute("avg(" & zds(c1) & ")","[班级全称] = \'" & bjqc & "\' and 免统审核 =false"),"0.00")
   Next
    i=i+1
Next
book.PreBuild = False  \'非报表模请将PreBuild  属性设置为False
e.WriteBook(book,"成绩.xls",False)

 

 

老师,请问上面代码用于生成EXCL表,但同样的代码同样的选项,有时能下载,有时点确定后不动定,是什么原因?


--  作者:有点蓝
--  发布时间:2017/8/23 18:04:00
--  
生成的Excel表有多少行的数据?

调试一下,点确定后不动定,后台会不会弹出msgbox提示

--  作者:有点甜
--  发布时间:2017/8/23 18:10:00
--  

 这种问题,加入msgbox调试,看是否执行到最后

 

msgbox(1)

e.WriteBook(book,"成绩.xls",False)

msgbox(2)

 

 


--  作者:刘林
--  发布时间:2017/8/23 21:36:00
--  

关键是什么也没变,有时能下载,有时不能,没找出问题


--  作者:有点甜
--  发布时间:2017/8/23 21:46:00
--  
以下是引用刘林在2017/8/23 21:36:00的发言:

关键是什么也没变,有时能下载,有时不能,没找出问题

 

msgbox是否弹出?是否触发了代码?会不会是你重复访问同一个网址浏览器没有触发响应?


--  作者:刘林
--  发布时间:2017/8/23 22:46:00
--  

Dim e As RequestEventArgs = args(0)
Dim  cmd As new SQLCommand
Dim wb As new WeUI
cmd.ConnectionName =
Dim dr As DataRow = DataTables("用户").sqlfind("身份证号 = \'" & e.Cookies("username") & "\'")
Dim  nms() As String
Dim zds() As String
If e.postvalues("bj")="初中"
    \'If e.PostValues.ContainsKey("cjms") Then
    If e.postvalues("cjms") = "普通模式" Then
        nms = new String() {"班级全称","姓名","语文","数学","英语","政治","历史","生物","地理","物理","化学","总分","总分班序","总分校序"}
        zds = new String() {"班级全称","姓名","语文_语总","数学_数总","英语_英总","政治_政总","历史_历总","生物_","地理_","物理_物总","化学_化总","总分","总分班序","总分校序"}
        cmd.CommandText= "selt 班级全称,考试名称,姓名,语文_语总,数学_数总,英语_英总,政治_政总,历史_历总,生物_,地理_,物理_物总,化学_化总,总分,总分班序,总分校序,免统审核 From {成绩}  where 单位名称 = \'" & dr("group") & "\' And 考试名称 =  \'" & e.PostValues("ksmc") & "\' order by 班级全称,总分 desc"  \'班级全称 = \'" & e.postvalues("bj") & "\' and
    End If
    If e.postvalues("cjms") = "加试模式" Then
        nms = new String() {"班级全称","姓名","语文A","语文B","数学A","数学B","英语A","英语B","政治A","政治B","历史A","历史B","生物","地理","物理A","物理B","化学A","化学B","折总","班序","校序"}
        zds = new String() {"班级全称","姓名","语文_A","语文_B","数学_A","数学_B","英语_A","英语_B","政治_A","政治_B","历史_A","历史_B","生物_","地理_","物理_A","物理_B","化学_A","化学_B","折总","班序","校序"}
        cmd.CommandText= "selt 班级全称,考试名称,姓名,语文_A,语文_B,数学_A,数学_B,英语_A,英语_B,政治_A,政治_B,历史_A,历史_B,生物_,地理_,物理_A,物理_B,化学_A,化学_B,折总,班序,校序,免统审核 From {成绩} where 单位名称 = \'" & dr("group") & "\' And 考试名称 =  \'" & e.PostValues("ksmc") & "\' order by 班级全称,折总 desc"
    End If
    \' End If
End If
If e.postvalues("bj")="小学"
    nms = new String() {"班级全称","姓名","语文","数学","英语","思品","科学","双科总分","总分班序","总分校序"}
    zds = new String() {"班级全称","姓名","语文_语总","数学_数总","英语","思品","科学","总分","总分班序","总分校序"}
    cmd.CommandText= "sect 班级全称,考试名称,姓名,语文_语总,数学_数总,英语,思品,科学,总分,总分班序,总分校序,免统审核 From {成绩}  where 单位名称 = \'" & dr("group") & "\' And 考试名称 =  \'" & e.PostValues("ksmc") & "\' order by 班级全称,总分 desc"
End If
Dim dt As DataTable = cmd.ExecuteReader
Dim  Book As New XLS.Book
Dim  Sheet As XLS.Sheet = Book.Sheets(0)
sheet(0,0).value = dr("group") & e.postvalues("ksmc") & "成绩表"
For c As Integer = 0 To nms.Length - 1
    Sheet(1, c).Value = nms(c)
Next
For r As Integer = 0 To dt.DataRows.Count - 1
    For c As Integer = 0 To zds.Length - 1
        Sheet(r+2, c).Value = dt.Datarows(r)(zds(c))
    Next
Next
Dim h As Integer = dt.DataRows.count
For c As Integer = 2 To nms.Length - 1
 Sheet(h+2, c).Value = nms(c)
Next
Dim i As Integer=1
Dim bjqcs As List(Of String) = dt.GetValues("班级全称")
For Each bjqc As String In bjqcs
 sheet(h+2+i,0).value=bjqc & "平均分"
  For c1 As Integer = 2 To dt.DataCols.count -5
    sheet(h+2+i,c1).value = Format(dt.compute("avg(" & zds(c1) & ")","[班级全称] = \'" & bjqc & "\' and 免统审核 =false"),"0.00")
  Next
  i=i+1
Next
book.PreBuild = False  \'非报表模请将PreBuild  属性设置为False
messagebox.show("到这里了")
e.WriteBook(book,"成绩.xls",False)
messagebox.show("到这里了")

老师,在上面加了这两句测试,点两次提示的确定,不论什么情况都打得开EXCL,但只要不要这两句就有时打得开,有时打不开,是什么情况?怎么办?


--  作者:有点甜
--  发布时间:2017/8/23 23:22:00
--  

如果改成这样呢?不能下载的时候,命令窗口是否有提示?

 

output.show(date.now)
e.WriteBook(book,"成绩.xls",False)
output.show(date.now)

output.show("----------------------------")

 

还有就是,你通过什么方式触发下载的?贴出来看看。


--  作者:刘林
--  发布时间:2017/8/24 8:20:00
--  
跟6楼的结果差不多
book.PreBuild = False  \'非报表模请将PreBuild  属性设置为False
messagebox.show(Date.now)
e.WriteBook(book,"成绩.xls",False)
messagebox.show(Date.now)
messagebox.show("----------------------------")

只要用这个方式测试每次都能下载打开,但把show语句删了就不行,整晕完了,前面反复检查应该没问题,请老师救救我

--  作者:有点甜
--  发布时间:2017/8/24 8:46:00
--  

1、用7楼代码;

 

2、做个具体例子发上来测试。