Dim i As Integer = 0
Dim dt As Table = Tables("按账户查账窗体_azhcxTable")
Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
Dim flg As New SaveExcelFlags
dlg.Filter= "Excel文件|*.xlsx" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
Tables("按账户查账窗体_azhcxTable").SaveExcel(dlg.FileName, "按账户查账",flg.CellStyle=True ) '保存文件
End If
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 '新建一个样式
Dim Style4 As Xls.Style = Book.NewStyle '新建一个样式
Style.ForeColor = Color.Red '字体颜色设为红色
Style.Font =new font("宋体", 9,FontStyle.Bold ) ''字体为宋体12加粗
Style.Format =Format ("0.00") '格式化样式的字体颜色设为红色
Style1.ForeColor = Color.Blue '字体颜色设为蓝色
Style1.Font =new font("宋体", 9,FontStyle.Bold ) ''字体为宋体12加粗
Style1.Format =Format ("0.00")''格式化样式的字体颜色设为红色
Style2.ForeColor = Color.Red '字体颜色设为蓝色
Style2.Font =new font("宋体", 9,FontStyle.Bold ) ''字体为宋体12加粗
Style2.Format =Format ("0.00")''格式化样式的字体颜色设为红色
Style2.BackColor =Color.PaleGreen '格式背景颜色设为红色
Style3.BackColor =Color.PaleGreen '格式背景颜色设为红色
Style3.Font =new font("宋体", 10,FontStyle.Bold ) ''字体为宋体12加粗
Style3.BackColor =Color.LightGray '格式背景颜色设为红色
Style4.BackColor =Color.Azure '格式背景颜色设为红色
For Each c As Col In dt.Cols
If c.visible Then i+=1
Next
For r As Integer = 0 To dt.Rows.Count '填入数据
Sheet(r + 1,dt.Cols("支出金额").Index).Style = Style '设置折扣单元格的样式
Sheet(r + 1,dt.Cols("收入金额").Index).Style = Style1 '设置折扣单元格的样式
If r Mod 2 =0 Then '如果是偶数行
For lzs As Integer = 0 To i-1 'dt.Cols.Count-5 '填入数据
Sheet( r+1 ,lzs ).Style =Style4 '设置单元格样式
Next
End If
Next
Sheet(dt.Rows.Count+1,0).value = "记录数" & dt.Rows.Count
Sheet(dt.Rows.Count+1,dt.Cols("支出金额").Index).value = dt.compute("sum(支出金额)")
Sheet(dt.Rows.Count+1,dt.Cols("收入金额").Index).value = dt.compute("sum(收入金额)")
For cc As Integer = 0 To i-1 '填入数据
Sheet(dt.Rows.Count+1,cc).Style = Style2
Sheet(0,cc).Style = Style3
Next
Book.Save(ProjectPath & "按账户查账_" & Format(Date.Now,"yyyyMMdd HHmmss") & ".xls" )
Dim Proc As New Process
Proc.File =ProjectPath & "按账户查账_" & Format(Date.Now,"yyyyMMdd HHmmss") & ".xls"
Proc.Start()
MessageBox.Show(dlg.FileName)
If FileSys.FileExists("dlg.FileName") Then '如果指定的文件存在
FileSys.DeleteFile("dlg.FileName",2,2) '则彻底删除之
End If