用我这个
If Adodc1.Recordset.RecordCount = 0 Then
MsgBox "没有数据可导出!"
Else
MsgBox "将把数据导出到EXCLE里,请稍等.......", vbExclamation, "导出"
Set oexcel = CreateObject("Excel.Application")
Set obook = oexcel.Workbooks.Add
Set osheet = obook.Worksheets(1)
osheet.Range("A1").Value = " "
osheet.Range("B1").Value = "名"
osheet.Range("C1").Value = "名称"
osheet.Range("A2").CopyFromRecordset Adodc1.Recordset
With oexcel
.Cells(1).ColumnWidth = 14
.Cells(2).ColumnWidth = 10 '第一列
.Cells(3).ColumnWidth = 16 '第二列
.Cells(4).ColumnWidth = 12 '第三列
.Cells(5).ColumnWidth = 12 '第四列
'字体 边框
居中
.Cells.Font.Size = 9
.Cells(1, 1).Borders.LineStyle = 1 '边框
.Cells(1, 2).Borders.LineStyle = 1
.Cells(1, 3).Borders.LineStyle = 1
.Cells(1, 4).Borders.LineStyle = 1
.Cells(1, 5).Borders.LineStyle = 1
.Cells.HorizontalAlignment = xlCenter
.Cells.WrapText = True
'自动换行
.Cells.EntireColumn.AutoFit
'行高根据内容自动调整
.Cells.EntireRow.AutoFit
End With
obook.SaveAs "d:\1.xls"
oexcel.Quit
Set osheet = Nothing
Set obook = Nothing
Set oexcel = Nothing
MsgBox "报表生成成功"
End If
[
本帖最后由 jxawgya 于 2011-5-14 11:36 编辑 ]