注:DataGrid 中的数据是通过ADO.NET编程得到的数据集,并已填充到DataGrid 中,
急,,,,,,,,,,
Dim i As Integer
Dim j As Integer
Dim rs As New ADODB.Recordset
Dim ex As Object
Dim exwbook As Object
Dim exsheet As Object
Dim sqlstring As String
If DateTimePickerOver.Text < DateTimePickerBegin.Text Then
MsgBox("日期顺序不对,请重新选择", MsgBoxStyle.Information, "提示")
Else
SaveFileDialogSave.Filter = "(*.xls)|*.xls"
SaveFileDialogSave.FilterIndex = 1
SaveFileDialogSave.ShowDialog()
sqlstring = "select * from DRV_TEMP_MIDTJ where DateDiff('d',czsj ,'" + DateTimePickerBegin.Text + "')<=0" + "and DateDiff('d',czsj,'" + DateTimePickerOver.Text + "')>=0"
ex = CreateObject("Excel.Application")
exwbook = Nothing
exsheet = Nothing
exwbook = ex.Workbooks().Add
exsheet = exwbook.Worksheets("sheet1")
rs.Open(sqlstring, connect, 1, 3)
' If Not rs.BOF Then
For i = 1 To rs.RecordCount
For j = 2 To rs.Fields.Count
exsheet.cells(i, j - 1).value = rs(rs(j - 1).Name).Value
Next
rs.MoveNext()
Next
exwbook.SaveAs(SaveFileDialogSave.FileName)
ex.Quit()
rs.Close()
'End If
End If
这个是我刚刚写的一个,你看看能看