以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]汇总行的位置 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=149542) |
-- 作者:lgj716330 -- 发布时间:2020/5/5 22:02:00 -- [求助]汇总行的位置 Dim dt As Table = CurrentTable Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog dlg.Filter= "Excel文件|*.xls" \'设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮 dt.SaveExcel(dlg.FileName, "表_table1") \'保存文件 Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表 Dim Style As XLS.Style = Book.NewStyle() \'定义新样式 Dim Style1 As XLS.Style = Book.NewStyle() \'定义新样式 Style.Format = "0.00%" Style1.BackColor = Color.pink For c As Integer = 0 To sheet.Cols.count-1 If sheet(0,c).text = "占比" Then For i As Integer = 2 To sheet.Rows.count-1 sheet(i, c).Style=Style Next End If Next book.save(dlg.FileName) End If 共两级汇总,标颜色处如果是第一个汇总要怎么表示
|
-- 作者:有点蓝 -- 发布时间:2020/5/5 22:21:00 -- 截图说明一下,要表示成什么样子? |
-- 作者:lgj716330 -- 发布时间:2020/5/6 9:08:00 -- 导出数据的过程中,将“占比”列百分比格式化后,原来分组行的背景颜色也没掉了,想恢复背景颜色 |
-- 作者:有点蓝 -- 发布时间:2020/5/6 9:13:00 -- 加一个背景颜色 Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表 Dim Style As XLS.Style = Book.NewStyle() \'定义新样式 Dim Style1 As XLS.Style = Book.NewStyle() \'定义新样式 Style.Format = "0.00%" Style.BackColor = Color.pink Style1.BackColor = Color.pink For c As Integer = 0 To sheet.Cols.count-1
|
-- 作者:lgj716330 -- 发布时间:2020/5/6 11:01:00 -- 这样是整列的背景颜色,我只是想弄汇总行的背景颜色,不知在这里怎么表示汇总行,分组一和分组二的背景颜色不一样 Dim dt As Table = CurrentTable Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog dlg.Filter= "Excel文件|*.xls" \'设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮 dt.SaveExcel(dlg.FileName, "表_table1") \'保存文件 Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表 Dim Style As XLS.Style = Book.NewStyle() \'定义新样式 Dim Style1 As XLS.Style = Book.NewStyle() \'定义新样式 Style.Format = "0.00%" Style1.BackColor = Color.pink For c As Integer = 0 To sheet.Cols.count-1 If sheet(0,c).text = "占比" Then For i As Integer = 2 To sheet.Rows.count-1 sheet(i, c).Style=Style Next End If Dim r1 As Row For i As Integer = 0 To dt.Rows.Count(True) - 1 r1 = dt.Rows(i,True) If r1.IsGroup And r1.level=1 Then r1.Style=Style1 End If Next Next book.save(dlg.FileName) End If 上面代码怎么调整
[此贴子已经被作者于2020/5/6 11:23:47编辑过]
|
-- 作者:有点蓝 -- 发布时间:2020/5/6 11:40:00 -- 就是4楼的用法 |
-- 作者:lgj716330 -- 发布时间:2020/5/6 12:08:00 -- 四楼的用法是对整列生效,背景颜色我只想对汇总行生效,我再测试测试吧 |
-- 作者:有点蓝 -- 发布时间:2020/5/6 13:38:00 -- 另外再添加一个样式 Dim Style3 As XLS.Style = Book.NewStyle() \'定义新样式 Style3.Format = "0.00%" Style3.BackColor = Color.pink For c As Integer = 0 To sheet.Cols.count-1 If sheet(0,c).text = "占比" Then For i As Integer = 2 To sheet.Rows.count-1 if sheet(i, c).text like "*小计*" sheet(i, c).Style=Style3 else sheet(i, c).Style=Style endif Next End If Dim r1 As Row For i As Integer = 0 To dt.Rows.Count(True) - 1 r1 = dt.Rows(i,True) If r1.IsGroup And r1.level=1 Then r1.Style=Style1 End If Next Next |
-- 作者:lgj716330 -- 发布时间:2020/5/6 15:11:00 -- 已解决 Dim dt As Table = CurrentTable Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog dlg.Filter= "Excel文件|*.xls" \'设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮 dt.SaveExcel(dlg.FileName, "表_table1") \'保存文件 Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表 Dim Style As XLS.Style = Book.NewStyle() \'定义新样式 Dim Style1 As XLS.Style = Book.NewStyle() \'定义新样式 Dim Style2 As XLS.Style = Book.NewStyle() \'定义新样式 Dim Style3 As XLS.Style = Book.NewStyle() \'定义新样式 Style.Format = "0.00%" Style1.BackColor = Color.SkyBlue Style1.Format = "0.00%" Style2.BackColor = Color.pink Style2.Format = "0.00%" Style3.BackColor = Color.GreenYellow Style3.Format = "0.00%" For c As Integer = 0 To sheet.Cols.count-1 For i As Integer = 0 To dt.Rows.count(True)-1 If sheet(0,c).text = "销售占比" Then sheet(i+2, c).Style=Style End If If sheet(0,c).text = "销售占比" And dt.Rows(i, True).IsGroup And dt.Rows(i, True).level=1 Then Dim a As Integer =dt.grid.Rows(i+2).Index sheet(a, c).Style=Style1 End If If sheet(0,c).text = "销售占比" And dt.Rows(i, True).IsGroup And dt.Rows(i, True).level=0 Then Dim a As Integer =dt.grid.Rows(i+2).Index sheet(a, c).Style=Style2 End If If sheet(0,c).text = "销售占比" And dt.Rows(i, True).IsGroup And dt.Rows(i, True).level=-1 Then Dim a As Integer =dt.grid.Rows(i+2).Index sheet(a, c).Style=Style3 End If Next Next book.save(dlg.FileName) End If 但sheet(0,c).text = "销售占比" 我想改成sheet(0,c).text like "%占比%"这样又不行,标题行有两层,第一层是名称“销售占比”,如果用like要怎么表示 [此贴子已经被作者于2020/5/6 15:11:46编辑过]
|
-- 作者:有点蓝 -- 发布时间:2020/5/6 15:19:00 -- sheet(0,c).text like "*占比*" |