以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 多行合并为一行 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=185476) |
-- 作者:lihe60 -- 发布时间:2023/2/25 10:25:00 -- 多行合并为一行 上表为数据库,下表为要生成的excel表,如何实现。 此主题相关图片如下:无标题.png |
-- 作者:有点蓝 -- 发布时间:2023/2/25 10:45:00 -- http://www.foxtable.com/webhelp/topics/1530.htm |
-- 作者:lihe60 -- 发布时间:2023/2/25 10:59:00 -- 科目和分数要在同一个单元格中。 |
-- 作者:有点蓝 -- 发布时间:2023/2/25 11:24:00 -- Dim Book As New XLS.Book \'定义一个Excel工作簿 Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表 For c As Integer = 0 To datatables("A").Cols.Count -1 \'添加列标题
Sheet(0, c).Value = dt.Cols(c).Name Next dim m as inreger = 1 For each s as string in datatables("A").getvalues("姓名") Sheet(m, 0).Value = s Sheet(m, 1).Value = datatables("A").GetComboListString("科目",“姓名=‘“ & s & ”’”).replace("|",vbcrlf) m=m+1 Next Book.Save("c:\\reports\\test.xls") \'保存工作簿 |
-- 作者:lihe60 -- 发布时间:2023/2/25 11:58:00 -- Dim cmd As New sqlcommand cmd.commandtext = "Sele\\ct Distinct 科目, STUFF((Sel\\ect ChAr(10)+ 姓名 FROM {班级} WH\\ERE 科目 = T.科目 FOR XML PATH(\'\')), 1, 1, \'\') AS Course FROM {g_业务} AS T" e.Form.controls("table1").Table.datasource = cmd.executereader() Dim t0 As Table = e.Form.controls("table1").Table Dim hdr As Integer = t0.HeaderRows \'获得表头的层数 Dim cnt As Integer Dim Book As New XLS.Book Dim Sheet As XLS.Sheet = Book.Sheets(0) t0.CreateSheetHeader(Sheet) \'生成表头 For c As Integer = 0 To t0.Cols.Count - 1 If t0.Cols(c).Visible Then For r As Integer = 0 To t0.Rows.Count - 1 sheet(r + hdr, cnt).value = t0(r, c) Next cnt = cnt + 1 End If Next For Each c As Col In t0.Cols If c.name Like "*日期*" Then Dim St2 As XLS.Style = Book.NewStyle St2.Format = "yyyy-MM-dd" Sheet.Cols(c.Index).Style = st2 End If Next \'打开工作簿 Book.Save("c:\\reports\\test.xls") Dim Proc As New Process Proc.File = "c:\\reports\\test.xls" Proc.Start() |
-- 作者:lihe60 -- 发布时间:2023/2/25 11:58:00 -- 这个代码如何改? |
-- 作者:有点蓝 -- 发布时间:2023/2/25 13:32:00 -- 表结构和数据是怎么样的 |
-- 作者:lihe60 -- 发布时间:2023/2/25 13:37:00 -- 1楼 |
-- 作者:有点蓝 -- 发布时间:2023/2/25 13:41:00 -- Dim t0 As Table = e.Form.controls("table1").Table Dim hdr As Integer = t0.HeaderRows \'获得表头的层数 Dim cnt As Integer Dim Book As New XLS.Book Dim Sheet As XLS.Sheet = Book.Sheets(0) For c As Integer = 0 To t0.Cols.Count -1 \'添加列标题 Sheet(0, c).Value = t0.Cols(c).Name Next dim m as inreger = 1 For each s as string in t0.datatable.getvalues("姓名") Sheet(m, 0).Value = s Sheet(m, 1).Value = t0.datatable.GetComboListString("科目",“姓名=‘“ & s & ”’”).replace("|",vbcrlf) m=m+1 Next Book.Save("c:\\reports\\test.xls")
|
-- 作者:lihe60 -- 发布时间:2023/2/25 21:34:00 -- 请上传一个案例 [此贴子已经被作者于2023/2/25 21:36:42编辑过]
|