关于将datagrid导入excel 现在已经将要查询的内容显示到datagrid中,现在想把已经查询好的在datagrid中的内容导入excel中,请问这部分的代码该如何写???? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 引用Excel对象!open开一个Xls文件,写入,Close就行。csdn上很多,找找 CdlZPCP.Filter = "Excel(*.xls)|*.xls" CdlZPCP.ShowSave If CdlZPCP.FileName = "" Then Exit Sub FileName = CdlZPCP.FileName Set xlApp = CreateObject("Excel.Application") Set xlBook = xlApp.Workbooks.Add Set xlSheet = xlApp.Worksheets(1) With msgZPCPIn ReDim DBArray(.Rows - 1, .Cols - 1) frmPercent.iPerc = .Rows frmPercent.Show xlSheet.Cells(2, 1).Value = Label2(0).Caption xlSheet.Cells(2, 2).Value = "'" & txtZPCP(0).Text xlSheet.Cells(2, 2).Select For intCount = 1 To 5 xlSheet.Cells(intCount + 2, 1) = Label2(intCount).Caption xlSheet.Cells(intCount + 2, 2) = "'" & txtZPCP(intCount).Text Next intCount xlSheet.Range(xlSheet.Cells(2, 2), xlSheet.Cells(7, 2)).Select UnderLine For intCount = 6 To 10 xlSheet.Cells(intCount - 3, 3) = Label2(intCount).Caption xlSheet.Cells(intCount - 3, 4) = "'" & txtZPCP(intCount).Text Next intCount xlSheet.Range(xlSheet.Cells(3, 4), xlSheet.Cells(7, 4)).Select UnderLine For intCount = 11 To 15 xlSheet.Cells(intCount - 8, 5) = Label2(intCount).Caption xlSheet.Cells(intCount - 8, 6) = "'" & txtZPCP(intCount).Text xlSheet.Cells(intCount - 8, 6).Select Next intCount xlSheet.Range(xlSheet.Cells(3, 6), xlSheet.Cells(7, 6)).Select UnderLine For iRow = 0 To .Rows - 1 For iCol = 0 To .Cols - 1 frmPercent.Show frmPercent.lblPercent = CStr(Round(((iRow + 1) / .Rows) * 100)) & "%" frmPercent.lblPercent.Refresh frmPercent.PrgBar.Value = iRow + 1 DBArray(iRow, iCol) = "'" & .TextMatrix(iRow, iCol) Next iCol Next iRow xlSheet.Cells(9, 1).Resize(.Rows, .Cols).Value = DBArray xlSheet.Range(xlSheet.Cells(9, 1), xlSheet.Cells(.Rows + 9, .Cols)).Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With xlSheet.Cells(.Rows + 10, 1) = Label2(16).Caption xlSheet.Cells(.Rows + 10, 2) = "'" & txtZPCP(16).Text xlSheet.Cells(.Rows + 10, 3) = Label2(17).Caption xlSheet.Cells(.Rows + 10, 4) = "'" & txtZPCP(17).Text Unload frmPercent xlSheet.Columns.AutoFit xlSheet.Cells(1, 1).Value = Label1.Caption xlSheet.Cells(1, 1).Font.Name = "宋体" xlSheet.Cells(1, 1).Font.Size = 22 xlSheet.Cells(1, 1).Font.Bold = True xlSheet.Cells(1, 1).Select xlSheet.SaveAs FileName CdlZPCP.FileName = "" xlSheet.Application.Quit Set xlBook = Nothing Set xlSheet = Nothing End With 使用循环的话 ,海量数据插入excel就很慢考虑一下这样的sqlsql = "SELECT * INTO [Excel 8.0;DATABASE=" & xPath & "FROM [" & tableNameDLTDLT & "] where " & DateField & " between #" & CDate(startDate) & "# and #" & CDate(endDate) & "# order by " & DateField & " desc" 自定义类型 ADO访问数据库 数据读取或者上传 进度问题 求解 HELP SSOleDBGrid控件如何排序? 求教:“12”替换为“12速度”会无限循环!? 简单问题——ByVal是什么 怎麼才能輸出到指定的打印機? 1、如何在VB中调用API函数来得到CPU的频率? 2、如何调用API函数来改变LISTBOX的滚动条样式?有复必谢!回信[email protected] 大家都来帮帮新手哈!!! SOS如何在vb中实现文字的平滑的移动无闪烁,还有如何调用windows的画布 请教ADO更新数据问题 求助:关于SQL语句方面的问题.急死我了..... 高分求助
csdn上很多,找找
CdlZPCP.ShowSave
If CdlZPCP.FileName = "" Then Exit Sub
FileName = CdlZPCP.FileName
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlApp.Worksheets(1)
With msgZPCPIn
ReDim DBArray(.Rows - 1, .Cols - 1)
frmPercent.iPerc = .Rows
frmPercent.Show
xlSheet.Cells(2, 1).Value = Label2(0).Caption
xlSheet.Cells(2, 2).Value = "'" & txtZPCP(0).Text
xlSheet.Cells(2, 2).Select
For intCount = 1 To 5
xlSheet.Cells(intCount + 2, 1) = Label2(intCount).Caption
xlSheet.Cells(intCount + 2, 2) = "'" & txtZPCP(intCount).Text
Next intCount
xlSheet.Range(xlSheet.Cells(2, 2), xlSheet.Cells(7, 2)).Select
UnderLine
For intCount = 6 To 10
xlSheet.Cells(intCount - 3, 3) = Label2(intCount).Caption
xlSheet.Cells(intCount - 3, 4) = "'" & txtZPCP(intCount).Text
Next intCount
xlSheet.Range(xlSheet.Cells(3, 4), xlSheet.Cells(7, 4)).Select
UnderLine
For intCount = 11 To 15
xlSheet.Cells(intCount - 8, 5) = Label2(intCount).Caption
xlSheet.Cells(intCount - 8, 6) = "'" & txtZPCP(intCount).Text
xlSheet.Cells(intCount - 8, 6).Select
Next intCount
xlSheet.Range(xlSheet.Cells(3, 6), xlSheet.Cells(7, 6)).Select
UnderLine
For iRow = 0 To .Rows - 1
For iCol = 0 To .Cols - 1
frmPercent.Show
frmPercent.lblPercent = CStr(Round(((iRow + 1) / .Rows) * 100)) & "%"
frmPercent.lblPercent.Refresh
frmPercent.PrgBar.Value = iRow + 1
DBArray(iRow, iCol) = "'" & .TextMatrix(iRow, iCol)
Next iCol
Next iRow
xlSheet.Cells(9, 1).Resize(.Rows, .Cols).Value = DBArray
xlSheet.Range(xlSheet.Cells(9, 1), xlSheet.Cells(.Rows + 9, .Cols)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
xlSheet.Cells(.Rows + 10, 1) = Label2(16).Caption
xlSheet.Cells(.Rows + 10, 2) = "'" & txtZPCP(16).Text
xlSheet.Cells(.Rows + 10, 3) = Label2(17).Caption
xlSheet.Cells(.Rows + 10, 4) = "'" & txtZPCP(17).Text
Unload frmPercent
xlSheet.Columns.AutoFit
xlSheet.Cells(1, 1).Value = Label1.Caption
xlSheet.Cells(1, 1).Font.Name = "宋体"
xlSheet.Cells(1, 1).Font.Size = 22
xlSheet.Cells(1, 1).Font.Bold = True
xlSheet.Cells(1, 1).Select
xlSheet.SaveAs FileName
CdlZPCP.FileName = ""
xlSheet.Application.Quit
Set xlBook = Nothing
Set xlSheet = Nothing
End With
考虑一下这样的sql
sql = "SELECT * INTO [Excel 8.0;DATABASE=" & xPath & "FROM [" & tableNameDLTDLT & "] where " & DateField & " between #" & CDate(startDate) & "# and #" & CDate(endDate) & "# order by " & DateField & " desc"