TA的每日心情 | 开心 2018-4-22 12:50 |
---|
签到天数: 393 天 连续签到: 1 天 [LV.9]测试副司令
|
'调用
Call SaveDatatable("c:\a.xls",3)
'实现
Sub SaveDatatable(sfilePath,irow)
Dim i, j
Dim ExcelObj, ExlSheet
i=datatable.GetSheet(1).GetParameterCount '取列数
Set ExcelObj = CreateObject("Excel.Application")
ExcelObj.Visible = False
ExcelObj.Workbooks.Open sfilePath ,ForWriting, False
Set ExlSheet = ExcelObj.Workbooks(1).Worksheets(1)
For j=1 to i
ExlSheet.Cells(irow,j) = datatable.Value(j, 1)
next
ExcelObj.ActiveWorkbook.Save
ExcelObj.Application.Quit
Set ExcelObj = Nothing
set ExlSheet = Nothing
End Sub
当然,前提是要在C盘先创建一个a.xls的文件. |
|