回复 10楼 bczgvip
额 斑竹没看清楚呀。。我说的是导出excel的时候没有头呀
Dim ex As Object Dim i As Integer Dim j As Integer Dim xlapp As Excel.Application Dim xlbook As Excel.Workbook Dim xlsheet As Excel.Worksheet Set xlapp = CreateObject("Excel.Application") xlapp.Visible = True Set xlbook = xlapp.Workbooks.Add Set xlsheet = xlbook.Worksheets(1) '******************************************************************** For i = 0 To DataGrid1.Columns.Count - 1 xlssheet.Cells(1, i + 1).Value2 = DataGrid1.Columns(i).DataField Next i '******************************************************************** For j = 0 To DataGrid1.ApproxCount - 1 For i = 0 To DataGrid1.Columns.Count - 1 DataGrid1.Col = i On Error Resume Next DataGrid1.Row = j xlsheet.Cells(j + 2, i + 1) = DataGrid1.Columns.Item(i).Text Next i Next j我已帮你修改了你的代码,特别注意*号之间的内容,是我添加的,其功能就是获取列头到你Excel表中去。另外你的代码逻辑上不是太清晰,所以我也做了改动。但由于我没有你代码中使用的数据库,所以代码我无法测试,我估计应该能够正常运行。只是你这问题点数居然为0,大哥,兄弟我也要吃饭的啊!