老师好,关于文件导出代码出现不了想要的结果,请老师看看代码问题出在哪儿,具体问题描述见压缩文件, 谢谢老师
老师好,也就是是说报表编程中的导出数据支持临时表导出数据吗?
老师好,还是实现不了所需的目的,具体情况还是和上午提的一样,我把上午的问题(压缩文件)再发过去,下面是我写的导出数据代码,还是解决不了,请老师看看代码的问题
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
老师好,在报表这块代码就是实现不了想要的功能,我有点迷惘,写不出来,老师说我重点再学一下基础的哪一部分,基础我也学了好多次,还是写出来的代码实现不了功能,请老师点拨一下,谢谢老师
Dim dlg As New SaveFileDialog
dlg.filter = "Excel文件|*.xls"
dlg.OverwritePrompt = True '弹出覆盖警告
If dlg.ShowDialog = DialogResult.OK Then
Dim bms() As String = {"全隐框玻璃幕墙单价分析表", "全明框玻璃幕墙单价分析表", "半明半隐框玻璃幕墙单价分析表"}
Dim cmd As New SQLCommand
Dim Book As New XLS.Book()
Dim Sheet As XLS.Sheet
Dim dt As DataTable
For Each bm As String In bms
Sheet = Book.Sheets.Add(bm) '增加一个工作表
If e.Form.Controls("导出理论数据").Checked = True Then
cmd.CommandText = "select 序号,项目构成,单位,用量 as 理论用量 ,单价 as 理论单价,合价 as 理论合价,备注 from {" & bm & "}" '该行代码不能加主键,否则出错
Else If e.Form.Controls("导出投标数据").Checked = True Then
cmd.CommandText = "select 序号,项目构成,单位,报价调整1 as 投标用量,报价调整2 as 投标单价,报价调整3 as 投标合价 ,备注 from {" & bm & "}" '该行代码不能加主键,否则出错
End If
dt = cmd.ExecuteReader()
For c As Integer = 0 To dt.DataCols.Count - 1
Sheet(0, c).Value = dt.DataCols(c).Name
Next
For r As Integer = 0 To dt.DataRows.Count - 1
For c As Integer = 0 To dt.DataCols.Count - 1
Sheet(r + 1, c).Value = dt.DataRows(r)(dt.DataCols(c).Name)
Next
Next
Next
End If