建议自己用Select计算其结果以后导出到Excel
解决方案 »
- VB有Release和Debug版之分吗?
- 枕善居祝所有女同胞节日快乐.
- DATAGRID属性页问题!
- 怎样使在图片框中显示的图片居中显示?
- 通过网路连接服务器,直接操作数据库,如果此时连接断裂了,程序就没有响应了,cpu:100%,如何解决?
- 请教一个奇怪的问题?没有头绪,谢谢大家指点,谢谢
- 如何编辑一个文本的内容?
- 请问如下Inet的设置,因何就是连不上?这个服务器我用CuteFTP测试,可以连通
- 注册OCX/DLL问题?
- 怎样在定义变量时就赋值?
- 不用第三方控件,没有数据库,vb6,打印出表格及内容怎样实现?
- dbcontrols(泰山__抛砖引玉) 怎样才能够把ado记录集写到EXECL并进行打印呢?
Row As Long
Col As Long
End TypeDim ExcelSheet As Excel.Application
Dim ValuesArray() As StringPublic Function MakeExcelFile(MasterRs As ADODB.Recordset, FieldsArray() As String, _
ReportCaption As String, MasterForm As frmCreateReport)
Dim WS As Worksheet
Dim StCell As ExlCell
Screen.MousePointer = vbHourglass Set ExcelSheet = CreateObject("Excel.Application")
ExcelSheet.Workbooks.Add
ExcelSheet.Worksheets(1).Name = ReportCaption
Set WS = ExcelSheet.Worksheets(1)
StCell.Col = 1
StCell.Row = 3
Call CopyRecords(MasterRs, WS, StCell, FieldsArray, MasterForm)
Screen.MousePointer = vbDefault
ExcelSheet.Visible = True
ExcelSheet.Interactive = True
Set ExcelSheet = Nothing
End Function
Private Sub CopyRecords(RST As ADODB.Recordset, WS As Worksheet, StartingCell As ExlCell, _
FieldsArray() As String, MasterForm As frmCreateReport)
Dim SomeArray() As Variant
Dim Row As Long
Dim Col As Long
Dim Recs As Integer
Dim Counter As Integer
Dim i As Integer
If RST.EOF And RST.BOF Then Exit Sub
RST.MoveLast
ReDim SomeArray(RST.RecordCount + 1, UBound(FieldsArray))
Col = 0
For Col = 0 To UBound(FieldsArray)
SomeArray(0, Col) = FieldsArray(Col)
Next
RST.MoveFirst
Recs = RST.RecordCount
Counter = 0
For Row = 1 To RST.RecordCount
Counter = Counter + 1
If Counter <= Recs Then i = (Counter / Recs) * 100
MasterForm.UpdateProgress i
For Col = 0 To UBound(FieldsArray)
SomeArray(Row, Col) = RST.Fields(FieldsArray(Col)).Value
If IsNull(SomeArray(Row, Col)) Then _
SomeArray(Row, Col) = ""
Next
RST.MoveNext
Next WS.Range(WS.Cells(StartingCell.Row, StartingCell.Col), _
WS.Cells(StartingCell.Row + RST.RecordCount, _
StartingCell.Col + UBound(FieldsArray))).Value = SomeArray
WS.Range(WS.Cells(StartingCell.Row, StartingCell.Col), _
WS.Cells(StartingCell.Row + RST.RecordCount, _
StartingCell.Col + UBound(FieldsArray))).HorizontalAlignment = xlRight
WS.Range(WS.Cells(StartingCell.Row, StartingCell.Col), _
WS.Cells(StartingCell.Row + RST.RecordCount, _
StartingCell.Col + UBound(FieldsArray))).Borders.LineStyle = xlContinuous
WS.Range(WS.Cells(1, 1), WS.Cells(1, StartingCell.Col + UBound(FieldsArray))).Merge
WS.Range(WS.Cells(1, 1), WS.Cells(1, StartingCell.Col + UBound(FieldsArray))).Font.Size = 20
WS.Range(WS.Cells(1, 1), WS.Cells(1, StartingCell.Col + UBound(FieldsArray))).Font.Bold = True
WS.Range(WS.Cells(1, 1), WS.Cells(1, StartingCell.Col + UBound(FieldsArray))).Value = WS.Name
WS.Range(WS.Cells(1, 1), WS.Cells(1, StartingCell.Col + UBound(FieldsArray))).HorizontalAlignment = xlCenter
WS.Columns.AutoFit
MasterForm.UpdateProgress 100
End Sub