以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  EXCEL报表  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=90860)

--  作者:mamuaiqing
--  发布时间:2016/9/23 1:48:00
--  EXCEL报表

请教老师,用代码生成的EXCEL报表,在数据生成最后一行底下增加个数值列合计,该怎么弄

Dim Book As New XLS.Book() \'定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表
Dim Style As XLS.Style = Book.NewStyle() \'定义新样式
Style.AlignHorz = XLS.AlignHorzEnum.Center
Style.AlignVert = XLS.AlignVertEnum.Center
Sheet.Rows(0).Height = 26
Sheet.Cols(0).Width = 120
Sheet.Cols(1).Width = 120
Sheet.Cols(2).Width = 180
Sheet.Cols(3).Width = 120
Sheet.Cols(4).Width = 100
Sheet.Cols(5).Width = 150
Sheet(0,0).Value = "日期"
Sheet(0,1).Value = "单号"
Sheet(0,2).Value = "产品名称"
Sheet(0,3).Value = "数量"
Sheet(0,4).Value = "单价"
Sheet(0,5).Value = "金额"
Sheet(0,6).Value = "制版费"
Style.FontBold = True
Sheet.Locked = True
Sheet.Rows(0).Style = Style
Dim Style1 As XLS.Style = Book.NewStyle() \'定义新样式
Style1.AlignHorz = XLS.AlignHorzEnum.Right
\'Style1.AlignVert = XLS.AlignVertEnum.Undefined
Sheet.Cols(5).Style = Style1
Sheet.Cols(3).Style = Style1
Sheet.Cols(4).Style = Style1
Sheet.Cols(6).Style = Style1


--  作者:mamuaiqing
--  发布时间:2016/9/23 1:49:00
--  
Dim cmd As New SQLCommand
Dim dt As DataTable
Dim bh As String = "1606-0002"
Dim rq1 As Date = #09/01/2016#
Dim rq2 As Date = #09/20/2016#

--  作者:mamuaiqing
--  发布时间:2016/9/23 1:49:00
--  
For t As Integer = 0 To dt.DataRows.Count -1
    If dt.DataRows(t)("日期") <> #01/01/0001# Then
        Sheet(t + 1,0).Value = Format(dt.DataRows(t)("日期"),"yyyy年MM月dd日")
    End If
    Sheet(t + 1,1).Value = dt.DataRows(t)("单号")
    Sheet(t + 1,2).Value = dt.DataRows(t)("产品名称")
    Sheet(t + 1,3).Value = Format(dt.DataRows(t)("数量"),"0.00") & "公斤"
    Sheet(t + 1,4).Value = Format(dt.DataRows(t)("单价"),"0.00")
    Sheet(t + 1,5).Value = "¥" & Format(dt.DataRows(t)("金额"),"#,###.00")
Next

--  作者:mamuaiqing
--  发布时间:2016/9/23 1:51:00
--  

这个上传就错误


图片点击可在新窗口打开查看此主题相关图片如下:qq截图20160923015045.jpg
图片点击可在新窗口打开查看

--  作者:有点蓝
--  发布时间:2016/9/23 8:46:00
--  
Dim t As Integer
For t = 0 To dt.DataRows.Count -1
    If dt.DataRows(t)("日期") <> #01/01/0001# Then
        Sheet(t + 1,0).Value = Format(dt.DataRows(t)("日期"),"yyyy年MM月dd日")
    End If
    Sheet(t + 1,1).Value = dt.DataRows(t)("单号")
    Sheet(t + 1,2).Value = dt.DataRows(t)("产品名称")
    Sheet(t + 1,3).Value = Format(dt.DataRows(t)("数量"),"0.00") & "公斤"
    Sheet(t + 1,4).Value = Format(dt.DataRows(t)("单价"),"0.00")
    Sheet(t + 1,5).Value = "¥" & Format(dt.DataRows(t)("金额"),"#,###.00")
Next
Sheet(t + 1,0).Value = "合计"
Sheet(t + 1,3).Value = dt.Compute("sum(数量)") & "公斤"
Sheet(t + 1,5).Value = "¥" & Format(dt.Compute("sum(金额)"),"#,###.00")

--  作者:mamuaiqing
--  发布时间:2016/9/23 22:02:00
--  

感谢有点蓝老师