以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  内部函数  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=105539)

--  作者:刘林
--  发布时间:2017/8/22 8:19:00
--  内部函数
Dim e As RequestEventArgs = args(0)
Dim  flt As  String
Dim  cmd As new SQLCommand
cmd.Co = "180.153.108.50"
Dim dr As DataRow = DataTables("用户").sqlfind("身份证号 = \'" & e.Cookies("username") & "\'")
Dim  nms() As String
Dim zds() As String
If e.postvalues("bj").Substring(0,2)="初中"
    If e.PostValues.ContainsKey("cjms") Then
        If e.postvalues("cjms") = "普通模式" Then
            nms = new String() {"姓名","语文","数学","英语","政治","历史","生物","地理","物理","化学","总分","总分班序","总分校序"}
            zds = new String() {"姓名","语文_语总","数学_数总","英语_英总","政治_政总","历史_历总","生物_","地理_","物理_物总","化学_化总","总分","总分班序","总分校序"}
            cmd.CommandText= "set 班级全称,考试名称,姓名,语文_语总,数学_数总,英语_英总,政治_政总,历史_历总,生物_,地理_,物理_物总,化学_化总,总分,总分班序,总分校序 From {成绩}  where 班级全称 = \'" & e.postvalues("bj") & "\' and 单位名称 = \'" & dr("group") & "\' And 考试名称 =  \'" & e.PostValues("ksmc") & "\' order by 总分 desc"
        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= "selc 班级全称,考试名称,姓名,语文_A,语文_B,数学_A,数学_B,英语_A,英语_B,政治_A,政治_B,历史_A,历史_B,生物_,地理_,物理_A,物理_B,化学_A,化学_B,折总,班序,校序 From {成绩} where 班级全称 = \'" & e.postvalues("bj") & "\' and 单位名称 = \'" & dr("group") & "\' And 考试名称 =  \'" & e.PostValues("ksmc") & "\' order by 折总 desc"
        End If
    End If
End If
If e.postvalues("bj").Substring(0,2)="小学"
    nms = new String() {"姓名","语文","数学","英语","思品","科学","双科总分","总分班序","总分校序"}
    zds = new String() {"姓名","语文_语总","数学_数总","英语","思品","科学","总分","总分班序","总分校序"}
    cmd.CommandText= "set 班级全称,考试名称,姓名,语文_语总,数学_数总,英语,思品,科学,总分,总分班序,总分校序 From {成绩}  where 班级全称 = \'" & e.postvalues("bj") & "\' and 单位名称 = \'" & 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("bj") & e.PostValues("ksmc") & "成绩表"
Sheet.MergeCell(0,0,0,20)
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
sheet(h+2,0).value="班级平均分"
SHEET(H+3,0).VALUE="最高分值"
sheet(h+4,0).value="最低分值"
For c1 As Integer = 1 To dt.DataCols.count -5
    sheet(h+2,c1).value = dt.compute("avg(" & zds(c1) & ")")
    sheet(h+3,c1).value = dt.compute("max(" & zds(c1) & ")")
    sheet(h+4,c1).value = dt.compute("min(" & zds(c1) & ")")
Next
book.PreBuild = False  \'非报表模请将PreBuild  属性设置为False
e.WriteBook(book,"成绩.xls",False)
Return

在HttpRequest事件可下载,但写成内部函数提示:错误:retren呢

--  作者:刘林
--  发布时间:2017/8/22 8:20:00
--  
错误提示:" 错误:rerurn
--  作者:zhy400137
--  发布时间:2017/8/22 9:14:00
--  
return ""
--  作者:有点甜
--  发布时间:2017/8/22 10:14:00
--  

1、没必要写return,你在函数里面写return 也是无效的。

 

2、如果去掉return导致无法下载,说明你httpRequest事件有问题。


--  作者:刘林
--  发布时间:2017/8/22 16:07:00
--  
 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") & 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
        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 = 1 To dt.DataCols.count -5
                sheet(h+2+i,c1).value = dt.compute("avg(" & zds(c1) & ")","[班级全称] = \'" & bjqc & "\'")
            Next
        Next
        book.PreBuild = False  \'非报表模请将PreBuild  属性设置为False
        e.WriteBook(book,"成绩.xls",False)
        Return
老师,你好,我现在想在EXCL的表尾加入汇总统计内容,这样写是想将各班的平均分写在后面,提示:无效的聚合函数 Mean()和类型 String 的用法。是什么原因

--  作者:刘林
--  发布时间:2017/8/22 16:16:00
--  
发现问题了,c1=1时是字符列
--  作者:有点甜
--  发布时间:2017/8/22 16:24:00
--  
判断一下列类型呗。
 
    For c1 As Integer = 1 To dt.DataCols.count -5
        If dt.DataCols(zds(c1)).IsNumeric Then
            sheet(h+2+i,c1).value = dt.compute("avg(" & zds(c1) & ")","[班级全称] = \'" & bjqc & "\'")
        End If
    Next