老师好,还是实现不了所需的目的,具体情况还是和上午提的一样,我把上午的问题(压缩文件)再发过去,下面是我写的导出数据代码,还是解决不了,请老师看看代码的问题
Dim LK As WinForm.CheckedListBox = e.Form.Controls("lbk")
Dim bms() As String = {"全隐框玻璃幕墙单价分析表", "全明框玻璃幕墙单价分析表", "半明半隐框玻璃幕墙单价分析表"}
For Each bm As String In bms
Dim dlg As New SaveFileDialog
dlg.filter = "Excel文件|*.xls|Access文件|*.mdb"
dlg.OverwritePrompt = True '弹出覆盖警告
If dlg.ShowDialog = DialogResult.OK Then
Dim Book As New XLS.Book("dlg.filter")
MessageBox.Show(1)
'定义工作表
Book.Sheets.Add("& bm &") '增加一个工作表
Dim Sheet As XLS.Sheet = Book.Sheets("bm")
MessageBox.Show(2)
Dim nms() As String = {"序号", "项目构成", "单位", "用量", "单价", "合价", "备注"}
If DataTables.Contains(bm) = False Then
Dim cmd As New SQLCommand
'cmd.C
If e.Form.Controls("导出理论数据").Checked = True Then
cmd.CommandText = "s elect 序号,项目构成,单位,用量 as 理论用量 ,单价 as 理论单价,合价 as 理论合价,备注 from {" & bm & "}" '该行代码不能加主键,否则出错
Else If e.Form.Controls("导出投标数据").Checked = True Then
cmd.CommandText = "s elect 序号,项目构成,单位,报价调整1 as 投标用量,报价调整2 as 投标单价,报价调整3 as 投标合价 ,备注 from {" & bm & "}" '该行代码不能加主键,否则出错
End If
Dim dt As DataTable = cmd.ExecuteReader()
MessageBox.Show(3)
' Dim Sheet As XLS.Sheet = Book.Sheets(0)
' Dim Style As Xls.Style = Book.NewStyle
' Style.BackColor = Color.Red
For c As Integer = 0 To nms.Count - 1
Sheet(0, c).Value = nms(c)
Next
MessageBox.Show(4)
For r As Integer = 0 To dt.DataRows.Count - 1
For c As Integer = 0 To nms.Count - 1
Sheet(r + 1, c).Value = dt.DataRows(r)(nms(c))
Next
Next
End If
MessageBox.Show(5)
'打开工作簿
Book.Save("dlg.filter")
Dim Proc As New Process
Proc.File = "dlg.filter"
Proc.Start()
End If
Next