完善一下:判断(29-31日)是否可见
Dim Filter,fl,fl1 As String
Dim Y,M,Days As Integer
Filter = "[姓名]<>''"
Y= e.Form.Controls("TextBox1").Value
M = e.Form.Controls("TextBox2").Value
Days = Date.DaysInMonth(Y,M)
Dim SD As Date = New Date(Y,M,1)
Dim ED As Date = New Date(Y,M,Days)
Filter = Filter & "And [日期] >= #" & SD & "# And [日期]<= #" & ED & "#"
Dim Ts As String() = {"","C","G","小线","开后","小后","佳洁云"}
For n As Integer = 1 To 6
If e.Form.Controls("CheckBox" & n).Checked = False Then
Filter = Filter & " And [部门] <> '" & Ts(n) & "'"
End If
Next
Dim g As New CrossTableBuilder("计件工资", DataTables("计件表"), Filter)
g.HGroups.AddDef("部门")
g.HGroups.AddDef("姓名")
g.VGroups.AddDef("日期", DateGroupEnum.Day, "{0}日")
g.Totals.AddDef("金额")
g.HorizontalTotal = True
g.VerticalTotal = True
g.Decimals = 1
g.Build()
Dim t As Table = Tables("计件工资")
fl = ProjectPath & "Attachments\计件工资模板.xls"
fl1 = ProjectPath & "Reports\计件工资" & Y & "-" & M & ".xls"
Dim Book As New XLS.Book(fl)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
For Y = 3 To 33
sheet(2,Y).value = ""
Next
For Y = 3 To 33
For M = 2 To t.cols.count-1
If sheet(1,Y).value = t.cols(M).Caption Then
sheet(2,Y).value = "[" & t.cols(M).name & "]"
End If
Next
if Y > 30 Then
Sheet.Cols(Y).Visible = Y-2<= Days
End if
Next
Book.Save(fl)
Book.Build() '生成细节区
Book.Save(fl1) '保存工作簿
Dim Proc As New Process '打开工作簿
Proc.File = fl1
Proc.Start()
e.form.close()
[此贴子已经被作者于2011-8-25 17:53:13编辑过]