vb中我把datagrid里面的数据如何导出到excel表里面,但是。。。木有数据啊,Excel里面
PrivateSubCommand1_Click()Dimdata(3000,77)AsStringFori=1ToData1.Recordset.Fields.Coun...
Private Sub Command1_Click()
Dim data(3000, 77) As String
For i = 1 To Data1.Recordset.Fields.Count - 1
data(0, i - 1) = Data1.Recordset.Fields(i).Name
Next i
i = 1
Do While Not Data1.Recordset.EOF And Not Data1.Recordset.BOF
Data1.Recordset.Fields.Item("fdd1").Value = i - 1
Data1.Recordset.UpdateBatch adAffectAllChapters
For j = 1 To Data1.Recordset.Fields.Count - 1
data(i, j - 1) = IIf(IsNull(Data1.Recordset.Fields(j).Value), "", Data1.Recordset.Fields(j).Value)
Next j
i = i + 1
Data1.Recordset.MoveNext
Loop
'遍历DATAGRID对象,将内容放到DATA数组。
Dim XLSAPP As excel.Application '定义excel对象并初始化
Set XLSAPP = CreateObject("Excel.Application")
With XLSAPP
.Visible = False
.Workbooks.Add
.ActiveSheet.Range("A1:by" & i).Value = data
.Dialogs(xlDialogSaveAs).Show
.ActiveWorkbook.Close 0
.Quit
End With
End Sub
这是导入到Excel表格的代码,我也是找的,可以生成excel表格,但是表格里面只有datagrid里面的表格的标题(所购图书、数量、价格),却没有内容,改怎么解决啊。 展开
Dim data(3000, 77) As String
For i = 1 To Data1.Recordset.Fields.Count - 1
data(0, i - 1) = Data1.Recordset.Fields(i).Name
Next i
i = 1
Do While Not Data1.Recordset.EOF And Not Data1.Recordset.BOF
Data1.Recordset.Fields.Item("fdd1").Value = i - 1
Data1.Recordset.UpdateBatch adAffectAllChapters
For j = 1 To Data1.Recordset.Fields.Count - 1
data(i, j - 1) = IIf(IsNull(Data1.Recordset.Fields(j).Value), "", Data1.Recordset.Fields(j).Value)
Next j
i = i + 1
Data1.Recordset.MoveNext
Loop
'遍历DATAGRID对象,将内容放到DATA数组。
Dim XLSAPP As excel.Application '定义excel对象并初始化
Set XLSAPP = CreateObject("Excel.Application")
With XLSAPP
.Visible = False
.Workbooks.Add
.ActiveSheet.Range("A1:by" & i).Value = data
.Dialogs(xlDialogSaveAs).Show
.ActiveWorkbook.Close 0
.Quit
End With
End Sub
这是导入到Excel表格的代码,我也是找的,可以生成excel表格,但是表格里面只有datagrid里面的表格的标题(所购图书、数量、价格),却没有内容,改怎么解决啊。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询