久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

VB DataGrid 的導(dǎo)出或打印

 云端的流浪 2010-12-01
導(dǎo)出到d:\text2.xls中
Private Sub Command2_Click()
Dim i     As Integer
  Dim j     As Integer
  Dim xlApp     As New Excel.Application
  Dim xlBook     As New Excel.Workbook
  Dim xlSheet     As New Excel.Worksheet
  Set xlApp = CreateObject("Excel.Application")
  xlApp.Visible = True
  Set xlBook = xlApp.Workbooks.Add
  On Error Resume Next
  Set xlBook = xlApp.Workbooks.Open("d:\text2.xls")
  Set xlSheet = xlBook.Worksheets(1)
  For j = 0 To DataGrid1.Columns.Count - 1
  xlSheet.Cells(1, j + 1) = DataGrid1.Columns.Item(j).Caption
  Next j
  xlSheet.Cells(6, 1) = "i"
  adodc1.Recordset.MoveFirst
  For i = 0 To adodc1.Recordset.recordcount - 1
  'For j = 0 To DataGrid1.Columns.Count - 1 '這一行跟下一行效果一樣
  For j = 0 To adodc1.Recordset.fields.Count - 1
  xlSheet.Cells(i + 1, j + 1) = adodc1.Recordset(j)
  Next j
  adodc1.Recordset.movenext
  Next i
End Sub
提問人的追問   2009-08-15 14:30
用戶類型未定義
回答人的補充   2009-08-15 14:49

不好意思,忘記說了 。

在工程——引用里,,添加Microsoft Excel 11.0 Object Library即可

回答人的補充   2009-08-15 14:49
提問人的追問   2009-08-15 14:52

恩~~除了標題外~~沒有任何內(nèi)容~

回答人的補充   2009-08-15 14:58
Dim i     As Integer
  Dim j     As Integer
  Dim xlApp     As New Excel.Application
  Dim xlBook     As New Excel.Workbook
  Dim xlSheet     As New Excel.Worksheet
  Set xlApp = CreateObject("Excel.Application")
  xlApp.Visible = True
  Set xlBook = xlApp.Workbooks.Add
  On Error Resume Next
  Set xlBook = xlApp.Workbooks.Open("d:\text2.xls")
  Set xlSheet = xlBook.Worksheets(1)
  For j = 0 To DataGrid1.Columns.Count - 1
  xlSheet.Cells(1, j + 1) = DataGrid1.Columns.Item(j).Caption
  Next j
  xlSheet.Cells(6, 1) = "i"
  Adodc1.Recordset.MoveFirst
  For i = 0 To Adodc1.Recordset.RecordCount - 1
  DataGrid1.Row = i
  For j = 0 To DataGrid1.Columns.Count - 1
  DataGrid1.Col = j
  'MsgBox   DataGrid1.Text
   
  If IsNull(DataGrid1.Text) = False Then
  xlSheet.Cells(i + 2, j + 1) = DataGrid1.Text
  End If
  Next j
  Next i

提問人的追問   2009-08-15 14:59
問下~要是不導(dǎo)出可以直接打印那個DataGrid1里面的內(nèi)容嗎,?
回答人的補充   2009-08-15 15:02

可以的,!

 

Private Sub Command3_Click()
On Error GoTo ErrMsg
fnt = 15
X = 1000
Y = 1000
Dim i As Long, J As Long, K As Long
Dim PrintString As String
Y = 4400
Printer.CurrentX = 1000
Printer.CurrentY = 4000
Printer.FontSize = 13
Printer.Print "學(xué)號/姓名 /課程/成績/班級"
For i = 0 To DataGrid1.Row
If K = DataGrid1.VisibleRows Then
DataGrid1.Scroll 0, DataGrid1.VisibleRows
K = 0
End If
For J = 0 To DataGrid1.Columns.Count - 1
PrintString = PrintString & _
DataGrid1.Columns(J).CellText(DataGrid1.RowBookmark(K)) & "/"
Next
Printer.CurrentX = 1000
Printer.CurrentY = Y
Printer.FontSize = 10
Printer.Print PrintString
PrintString = ""
K = K + 1
Y = Y + 300
DoEvents
   If i = DataGrid1.Row Then    '無此條件則打印機與計算機不斷開,,不能進行新的打印任務(wù)
Printer.EndDoc
End If
Next
ErrMsg:
  If Err.Number <> 0 Then
     MsgBox CStr(Err.Number) + Err.Description, vbOKOnly + vbCritical, "錯誤提示"
     Exit Sub
  End If
End Sub

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點,。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,,謹防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報,。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多