我要手工打印一个报表,采用的是直接向excel写入,excel工作表的上部分是表头,下部分是表尾,各页都一样,中间从第6行插入table明细的数据,每页插入5行,要实现分页打印,下面的代码赋值部分不对,请帮助看看?'------计算表头需要的数据并赋值 Dim shzb As WinForm.Table = e.Form.Controls("收货主表") Dim shmx As WinForm.Table = e.Form.Controls("收货明细") Dim shtj As WinForm.Table = e.Form.Controls("Table1") Dim r As Row = shzb.Table.Current Dim ryear As String = Format(r("供货日期"), "yyyy") Dim rmonth As String = Format(r("供货日期"), "MM")
Dim hs As Integer = shmx.Table.Rows.Count 'hs是收货明细表的行数 Dim totalPages As Integer = Math.Ceiling(shmx.Table.Count / 5) '计算总页数'按每页5行明细进行分页打印
Dim lms As String() = {"供货日期","品名","单位","数量","单价","金额"} Dim sheetRows As Integer() = {0,1,3,4,5,6} For page As Integer = 1 To totalPages Dim Book As New XLS.Book("c:\打印模板.xlsx") '定义一个Excel工作簿 Dim Sheet As XLS.Sheet = Book.Sheets("sheet1") '引用工作簿的第一个工作表 '打印表头 Sheet(0, 9).Value = ryear '填写报表头之年 Sheet(1, 9).Value = rmonth '填写报表头之月 Sheet(2, 9).Value = r("收货单号") '填写报表头之收货单号 Dim St As XLS.Style = Book.NewStyle St.Format = "yyyy-MM-dd"
For i As Integer = (page - 1) * 5 To Math.Min(page * 5, hs - 1) 'i代表table收货明细的行号 For j As Integer = 0 To sheetRows.Length - 1 'j代表sheet 表的行号 For k As Integer = 6 To 10 'Sheet(i+5, sheetrows(j)).Value = shmx.Table(i,lms(j)) Sheet((k+(i Mod 5)), sheetRows(j)).Value = shmx.Table.Rows(i)(lms(j)) 'MessageBox.show(shmx.Table.Rows(i)(lms(j))) 此值取出正确 'MessageBox.show(i & "-" & i Mod 5) Next Next Next Book.Save("c:\reports\test " & page & ".xls") '保存工作簿 Next
'-------打印预览
'Dim Proc As New Process '打开工作簿 'Proc.File = "c:\reports\test.xls" 'Proc.Start()
|