-- 作者:cnsjroom
-- 发布时间:2022/10/22 18:39:00
-- excel生成文件,如何加载满足值的所有数据
excel生成文件,如何加载满足值的所有数据
e.Values("姓名") 是多值内容 传递过来的 如A,B,C
当前代码如下:【当前e.Values("姓名") 为单个值的时候,表生成对应的当行数据;为多个值的时候,表生成空表,没有对应生成多行】
Dim time As String =Format(Date.now,"yyyyMMddHHmmss") msg(e.Values("登记编号")) msg(e.Values("姓名")) Dim Book As New XLS.Book(ProjectPath & "Attachments\\调取证据人员信息附件.xls") \'打开模板 Dim fl As String = ProjectPath & "Reports\\调取证据人员信息附件" & e.Values("创建人") & e.Values("guid") & time &".xls" Dim f2 As String = ProjectPath & "Reports\\调取证据人员信息附件" & e.Values("创建人") & e.Values("guid") & time &".pdf" Dim Sheet As XLS.Sheet = Book.Sheets(0) book.AddDataTable("人员信息表","主数据源","Sel ect * from {人员信息表} where 登记编号 = \'" & e.Values("登记编号") & "\' and 姓名 =\'" & e.Values("姓名") & "\'") Book.Build() \'生成报表 Book.SaveToPDF(f2)
代码二:bb(Col.name)得到的是空值,麻烦老师帮忙看看 为什么没有获取到值呢? bb1(Col.name) 获取到的对应值是正确的!
输出:
……
]=[身份证 2022-10-22 19:34:33 ]=[男 2022-10-22 19:34:33 ]=[张三 2022-10-22 19:34:33
……
代码内容:
Dim e As RequestEventArgs = rq.e Dim cmd As SQLCo mmand = rq.cmd Dim str As String =e.Values("姓名") cmd.Comm andText = "sel ect * from {人员信息表} where 登记编号=\'" & e.Values("登记编号") & "\'" If cmd.Execut eScalar > 0 Then \'查找到数据 For Each s As String In str.split(",") \'对传入的值进行拆分 If s.Length>0 Then \'如果拆分的值大于0 cmd.Comma ndText = "sel ect * from {人员信息表} where 姓名=\'" & s & "\' and 登记编号=\'" & e.Values("登记编号") & "\'" Dim dt1 As DataTable = cmd.Execut eReader(True) Dim bb1 As DataRow = dt1.DataRows(0) cmd.Comm andText = "sel ect * from {人员信息附件表} where 姓名=\'" & s & "\' and 登记编号=\'" & e.Values("登记编号") & "\'" Dim dt As DataTable = cmd.Execu teReader(True) Dim bb As DataRow If dt.DataRows.Count>0 Then \'如果S数据存在,暂时不做操作 \' dt.Delet eFor("姓名=\'" & s & "\' and 登记编号=\'" & e.Values("登记编号") & "\'") \' dt.save Else \'如果s数据不存在,则新增数据 bb=dt.AddNew \' 新增dt表行 msg(1) \'For Each Row As DataRow In dt.DataRows \'遍历dt1的所有行 For Each Col As DataCol In dt.datacols \'遍历dt1的所有列 msg(bb(Col.name) & "]=[" & bb1(Col.name)) bb(Col.name)=bb1(Col.name) \'其他列直接对应列名赋值相应的数据 Next \'Next End If dt.save End If Next End If
Dim time As String =Format(Date.now,"yyyyMMddHHmmss") Dim Book As New XLS.Book(ProjectPath & "Attachments\\调取证据人员信息附件.xls") \'打开模板 Dim fl As String = ProjectPath & "Reports\\调取证据人员信息附件" & e.Values("创建人") & e.Values("guid") & time &".xls" Dim f2 As String = ProjectPath & "Reports\\调取证据人员信息附件" & e.Values("创建人") & e.Values("guid") & time &".pdf" Dim Sheet As XLS.Sheet = Book.Sheets(0) book.AddDataTable("人员信息表","主数据源","Se lect * from {人员信息附件明细} where 登记编号 = \'" & e.Values("登记编号") & "\'") Book.Build() \'生成报表 Book.SaveToPDF(f2) e.WriteString("\\Reports\\调取证据人员信息附件" & e.Values("创建人") & e.Values("guid") & time &".pdf")
[此贴子已经被作者于2022/10/22 19:35:14编辑过]
|