具体问题:数据表
工程 材料1 材料2 材料3 材料4
1 2元 3元 3元 0元
2 1 5 4 5
3 12 0 6 3
。。。。。。。
excel格式
总计 元
工程 小计 材料1 材料2 材料3 材料4
1
2
。。。。。。。
5 个解决方案
#1
I can,but money.
#2
自己写查询语句查询后写添加语句添加
#3
'存字段长度值
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
With Rs_Dzgl_Receipt
If .RecordCount < 1 Then
MsgBox ("没有记录!")
Exit Sub
End If
xlSheet.Cells(1, 4).Value = .Fields("bt")
xlSheet.Cells(2, 1).Value = .Fields("invoice")
xlSheet.Cells(2, 9).Value = .Fields("packdate")
xlSheet.Cells(3, 1).Value = .Fields("mark")
'合并单元格
Dim nIcol As Integer
xlSheet.Range(xlSheet.Cells(3, 1), xlSheet.Cells(5, 9)).Select
With xlApp.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(1, 9)).Select
With xlApp.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
'网格线
With xlSheet
.Range(.Cells(1, 1), .Cells(1, 9)).Font.Name = "黑体"
'设标题为黑体字
.Range(.Cells(1, 1), .Cells(1, 9)).Font.Bold = True
'标题字体加粗
.Range(.Cells(1, 1), .Cells(1, 9)).Borders.LineStyle = xlContinuous
'设表格边框样式
End With
'显示表格
Dim ExclFileName As String
ExclFileName = App.Path & "\箱单" & Text1(1).Text & ".xls"
If Dir(ExclFileName) <> "" Then
Kill ExclFileName
End If
xlSheet.SaveAs (ExclFileName)
xlApp.Application.Visible = True
'交还控制给Excel
xlSheet.PrintPreview
' xlApp.Application.Quit
' xlApp.Quit
End With
#4
你可以将记录集导入excel
http://www.csdn.net/develop/read_article.asp?id=14952
或者将特定的数据写入excel的每个单元格
http://www.csdn.net/develop/read_article.asp?id=14952
或者将特定的数据写入excel的每个单元格
#5
Dim cn as Adodb.Connection
Dim rs as Adodb.Recordset
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
数据库连接,查询
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
Dim iCurrentRow,iCurrentCol,i as integer
iCurrentRow =1:iCurrentCol =1
For i = 0 to rs.Fields.Count - 1
xlsheet.cells(iCurrentRow,iCurrentCol) = rs.Fields(i).Name
iCurrentCol = iCurrentCol + 1
Next
iCurrentRow = iCurrentRow+1:iCurrentCol =1
Do While Not rs.Eof
For i = 0 to rs.Fields.Count - 1
xlsheet.cells(iCurrentRow,iCurrentCol) = rs.Fields(i).Value
iCurrentCol = iCurrentCol +1
Next
iCurrentRow = iCurrentRow+1:iCurrentCol =1
rs.Movenext
Loop
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
Dim rs as Adodb.Recordset
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
数据库连接,查询
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
Dim iCurrentRow,iCurrentCol,i as integer
iCurrentRow =1:iCurrentCol =1
For i = 0 to rs.Fields.Count - 1
xlsheet.cells(iCurrentRow,iCurrentCol) = rs.Fields(i).Name
iCurrentCol = iCurrentCol + 1
Next
iCurrentRow = iCurrentRow+1:iCurrentCol =1
Do While Not rs.Eof
For i = 0 to rs.Fields.Count - 1
xlsheet.cells(iCurrentRow,iCurrentCol) = rs.Fields(i).Value
iCurrentCol = iCurrentCol +1
Next
iCurrentRow = iCurrentRow+1:iCurrentCol =1
rs.Movenext
Loop
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
#1
I can,but money.
#2
自己写查询语句查询后写添加语句添加
#3
'存字段长度值
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
With Rs_Dzgl_Receipt
If .RecordCount < 1 Then
MsgBox ("没有记录!")
Exit Sub
End If
xlSheet.Cells(1, 4).Value = .Fields("bt")
xlSheet.Cells(2, 1).Value = .Fields("invoice")
xlSheet.Cells(2, 9).Value = .Fields("packdate")
xlSheet.Cells(3, 1).Value = .Fields("mark")
'合并单元格
Dim nIcol As Integer
xlSheet.Range(xlSheet.Cells(3, 1), xlSheet.Cells(5, 9)).Select
With xlApp.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(1, 9)).Select
With xlApp.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
'网格线
With xlSheet
.Range(.Cells(1, 1), .Cells(1, 9)).Font.Name = "黑体"
'设标题为黑体字
.Range(.Cells(1, 1), .Cells(1, 9)).Font.Bold = True
'标题字体加粗
.Range(.Cells(1, 1), .Cells(1, 9)).Borders.LineStyle = xlContinuous
'设表格边框样式
End With
'显示表格
Dim ExclFileName As String
ExclFileName = App.Path & "\箱单" & Text1(1).Text & ".xls"
If Dir(ExclFileName) <> "" Then
Kill ExclFileName
End If
xlSheet.SaveAs (ExclFileName)
xlApp.Application.Visible = True
'交还控制给Excel
xlSheet.PrintPreview
' xlApp.Application.Quit
' xlApp.Quit
End With
#4
你可以将记录集导入excel
http://www.csdn.net/develop/read_article.asp?id=14952
或者将特定的数据写入excel的每个单元格
http://www.csdn.net/develop/read_article.asp?id=14952
或者将特定的数据写入excel的每个单元格
#5
Dim cn as Adodb.Connection
Dim rs as Adodb.Recordset
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
数据库连接,查询
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
Dim iCurrentRow,iCurrentCol,i as integer
iCurrentRow =1:iCurrentCol =1
For i = 0 to rs.Fields.Count - 1
xlsheet.cells(iCurrentRow,iCurrentCol) = rs.Fields(i).Name
iCurrentCol = iCurrentCol + 1
Next
iCurrentRow = iCurrentRow+1:iCurrentCol =1
Do While Not rs.Eof
For i = 0 to rs.Fields.Count - 1
xlsheet.cells(iCurrentRow,iCurrentCol) = rs.Fields(i).Value
iCurrentCol = iCurrentCol +1
Next
iCurrentRow = iCurrentRow+1:iCurrentCol =1
rs.Movenext
Loop
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
Dim rs as Adodb.Recordset
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
数据库连接,查询
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
Dim iCurrentRow,iCurrentCol,i as integer
iCurrentRow =1:iCurrentCol =1
For i = 0 to rs.Fields.Count - 1
xlsheet.cells(iCurrentRow,iCurrentCol) = rs.Fields(i).Name
iCurrentCol = iCurrentCol + 1
Next
iCurrentRow = iCurrentRow+1:iCurrentCol =1
Do While Not rs.Eof
For i = 0 to rs.Fields.Count - 1
xlsheet.cells(iCurrentRow,iCurrentCol) = rs.Fields(i).Value
iCurrentCol = iCurrentCol +1
Next
iCurrentRow = iCurrentRow+1:iCurrentCol =1
rs.Movenext
Loop
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing