以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]报表多层表头  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=88368)

--  作者:鸡蛋
--  发布时间:2016/8/1 17:57:00
--  [求助]报表多层表头
在报表编程的自动生成表头中。可不可以自己筛选某一些列显示,而不要全部可见列显示出来?


--  作者:大红袍
--  发布时间:2016/8/1 18:53:00
--  
  你代码怎么写的?贴出代码,或者做实例发上来。
--  作者:鸡蛋
--  发布时间:2016/8/1 22:44:00
--  [求助]
Dim dt As Table = Tables("T222") Dim hdr As Integer = dt.HeaderRows Dim cnt As Integer Dim Book As New XLS.Book() Dim Sheet As XLS.Sheet = Book.Sheets(0) Dim Style As XLS.Style = Book.NewStyle() Dim St1 As xls.style = book.newstyle dt.CreateSheetHeader(Sheet,1,0) Style.BorderTop = XLS.LineStyleEnum.Thin Style.BorderBottom = XLS.LineStyleEnum.Thin Style.BorderLeft = XLS.LineStyleEnum.Thin Style.BorderRight = XLS.LineStyleEnum.Thin Style.BorderColorTop = Color.black Style.BorderColorBottom = Color.black Style.BorderColorLeft = Color.black Style.BorderColorRight = Color.black Sheet(0,9).Value = "打印日期:" & Format(Date.Today, "yyyy年MM月dd日") St1.FontBold = True Sheet(0,2).Style = St1 For r As Integer = 1 To 6 For c As Integer =1 To 21 Sheet(r,c).Style = Style Next Next For c As Integer = 0 To dt.Cols.Count - 1 If dt.Cols(c).Visible Then For r As Integer = 0 To dt.Rows.Count - 1 sheet(r + hdr+1,cnt).value = dt(r,c) Next cnt = cnt + 1 End If Next Book.Build() Dim dlg As New SaveFileDialog dlg.Filter= "Excel文件|*.xls" If dlg.ShowDialog = DialogResult.Ok Then Book.Save(dlg.FileName) Dim Proc As New Process Proc.File = dlg.FileName Proc.Start() End If
图片点击可在新窗口打开查看此主题相关图片如下:f@k}4sqauu88)v`6fu}rk9.png
图片点击可在新窗口打开查看

--  作者:鸡蛋
--  发布时间:2016/8/2 8:40:00
--  [求助]
Dim dt As Table = Tables("T222") Dim hdr As Integer = dt.HeaderRows Dim cnt As Integer Dim Book As New XLS.Book() Dim Sheet As XLS.Sheet = Book.Sheets(0) Dim Style As XLS.Style = Book.NewStyle() Dim St1 As xls.style = book.newstyle dt.CreateSheetHeader(Sheet,1,0) Style.BorderTop = XLS.LineStyleEnum.Thin Style.BorderBottom = XLS.LineStyleEnum.Thin Style.BorderLeft = XLS.LineStyleEnum.Thin Style.BorderRight = XLS.LineStyleEnum.Thin Style.BorderColorTop = Color.black Style.BorderColorBottom = Color.black Style.BorderColorLeft = Color.black Style.BorderColorRight = Color.black Sheet(0,9).Value = "打印日期:" & Format(Date.Today, "yyyy年MM月dd日") St1.FontBold = True Sheet(0,2).Style = St1 For r As Integer = 1 To 6 For c As Integer =1 To 21 Sheet(r,c).Style = Style Next Next For c As Integer = 0 To dt.Cols.Count - 1 If dt.Cols(c).Visible Then For r As Integer = 0 To dt.Rows.Count - 1 sheet(r + hdr+1,cnt).value = dt(r,c) Next cnt = cnt + 1 End If Next Book.Build() Dim dlg As New SaveFileDialog dlg.Filter= "Excel文件|*.xls" If dlg.ShowDialog = DialogResult.Ok Then Book.Save(dlg.FileName) Dim Proc As New Process Proc.File = dlg.FileName Proc.Start() End If
--  作者:狐狸爸爸
--  发布时间:2016/8/2 11:28:00
--  

可以看看这里的示例二:

http://www.foxtable.com/webhelp/scr/1148.htm

 


--  作者:鸡蛋
--  发布时间:2016/8/2 11:55:00
--  
这个里面没有多层表头的设置勒。如果在多层表头里面呢?我昨天设置过,好像它是把全部表头都显示出来了
--  作者:狐狸爸爸
--  发布时间:2016/8/2 12:30:00
--  
你可以先常规生成,生成后再删除多余的列:

http://www.foxtable.com/webhelp/scr/1157.htm

例如生成后,删除对于的第5列和第3列:

Dim tbl As Table = Tables("订单")
Dim hdr As Integer = tbl.HeaderRows \'获得表头的层数
Dim cnt As Integer
Dim Book As New XLS.Book
Dim Sheet As XLS.Sheet = Book.Sheets(0)
tbl.CreateSheetHeader(Sheet) \'生成表头
For c As Integer = 0 To tbl.Cols.Count - 1
    If tbl.Cols(c).Visible Then
        For r As Integer = 0 To tbl.Rows.Count - 1
            sheet(r + hdr,cnt).value = tbl(r,c)
        Next
        cnt = cnt + 1
    End If
Next
Sheet.Cols.RemoveAt(4)
Sheet.Cols.RemoveAt(2)
Book.Save("c:\\reports\\test.xls")
Dim Proc As New Process
Proc.File = "c:\\reports\\test.xls"
Proc.Start()

注意先删除靠后的列

--  作者:鸡蛋
--  发布时间:2016/8/2 15:27:00
--  
您好 我试过之后,它的第一层表头就是最上面那一个,不会跟着删除列,导致数据对应错乱了
--  作者:Hyphen
--  发布时间:2016/8/2 15:33:00
--  
贴出代码
--  作者:鸡蛋
--  发布时间:2016/8/2 16:26:00
--  [求助]
Dim dt As Table = Tables("T222") 
Dim hdr As Integer = dt.HeaderRows 
Dim cnt As Integer Dim Book As New XLS.Book() \'定义一个Excel工作簿 
Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表 
Dim Style As XLS.Style = Book.NewStyle() \'定义新样式 
Dim St1 As xls.style = book.newstyle dt.CreateSheetHeader(Sheet,1,0) 
Style.BorderTop = XLS.LineStyleEnum.Thin 
Style.BorderBottom = XLS.LineStyleEnum.Thin 
Style.BorderLeft = XLS.LineStyleEnum.Thin 
Style.BorderRight = XLS.LineStyleEnum.Thin 
Style.BorderColorTop = Color.black 
Style.BorderColorBottom = Color.black 
Style.BorderColorLeft = Color.black 
Style.BorderColorRight = Color.black 
Sheet(0,2).Value = "滨湖热力厂节能空间管理" 
Sheet(0,9).Value = "打印日期:" & Format(Date.Today, "yyyy年MM月dd日") 
St1.FontBold = True 
Sheet(0,2).Style = St1 
For r As Integer = 1 To 6 
 For c As Integer =1 To 21 
 Sheet(r,c).Style = Style 
 Next 
Next 
For c As Integer = 0 To dt.Cols.Count - 1 
 If dt.Cols(c).Visible Then 
 For r As Integer = 0 To dt.Rows.Count - 1 
 sheet(r + hdr+1,cnt).value = dt(r,c) 
 Next 
 cnt = cnt + 1 
 End If 
Next 
 Book.Build() 
Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog 
dlg.Filter= "Excel文件|*.xls" \'设置筛选器 
If dlg.ShowDialog = DialogResult.Ok Then 
 Book.Save(dlg.FileName) 
 Dim Proc As New Process 
 Proc.File = dlg.FileName Proc.Start() 
End If
[此贴子已经被作者于2016/8/2 16:28:54编辑过]