我用MSFlexGrid1显示了数据,如何保存到word中啊??我在书上看了些例子,但总不好使!我把我做的错误程序放在下面,大家帮我改改,或者有什么好点的方法??Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
Set wapp = CreateObject("word.application")
Set wddoc = wapp.Documents.Add()
With wdapp
.Visible = True
.Activate
.Caption = "床位表"
End With
Set atable = wdapp.ActiveDocument.Table.Add(wdapp.Selection.Range, Grid1.Rows + 1, 2)
For i = 1 To Grid1.Rows
atable.Cell(i, 1).Range.InsertAfter Grid1.TextMatrix(i, 1)
atable.Cell(i, 2).Range.InsertAfter Grid1.TextMatrix(i, 2)
Next i
wddoc.SaveAs "e:\1.Doc"
Set wdapp = Nothing
Set wddoc = Nothing
End Sub
Private Sub Form_Load()
Dim str As String
Dim rs As ADODB.Recordset
Grid1.FormatString = "|^床号|^姓名|"
Grid1.ColWidth(0) = 0
Grid1.ColWidth(1) = 500
Grid1.ColWidth(2) = 1000
Grid1.ColWidth(3) = 0
str = "select bed_no ,patient_name from bed_rec where bed_status='占' order by bed_no"
Set rs = ExecuteSQL(str, True, 1)
Dim n As Integer
If rs.RecordCount > 0 Then
n = 1
Grid1.Rows = rs.RecordCount + 1
While Not rs.EOF
Grid1.row = n
Grid1.Col = 1
Grid1.CellAlignment = 4
Grid1.Text = rs.Fields(0)
Grid1.Col = 2
Grid1.CellAlignment = 4
Grid1.Text = rs.Fields(1)
rs.MoveNext
n = n + 1
Wend
End If
rs.Close
End Sub
Dim i As Integer
Dim j As Integer
Set wapp = CreateObject("word.application")
Set wddoc = wapp.Documents.Add()
With wdapp
.Visible = True
.Activate
.Caption = "床位表"
End With
Set atable = wdapp.ActiveDocument.Table.Add(wdapp.Selection.Range, Grid1.Rows + 1, 2)
For i = 1 To Grid1.Rows
atable.Cell(i, 1).Range.InsertAfter Grid1.TextMatrix(i, 1)
atable.Cell(i, 2).Range.InsertAfter Grid1.TextMatrix(i, 2)
Next i
wddoc.SaveAs "e:\1.Doc"
Set wdapp = Nothing
Set wddoc = Nothing
End Sub
Private Sub Form_Load()
Dim str As String
Dim rs As ADODB.Recordset
Grid1.FormatString = "|^床号|^姓名|"
Grid1.ColWidth(0) = 0
Grid1.ColWidth(1) = 500
Grid1.ColWidth(2) = 1000
Grid1.ColWidth(3) = 0
str = "select bed_no ,patient_name from bed_rec where bed_status='占' order by bed_no"
Set rs = ExecuteSQL(str, True, 1)
Dim n As Integer
If rs.RecordCount > 0 Then
n = 1
Grid1.Rows = rs.RecordCount + 1
While Not rs.EOF
Grid1.row = n
Grid1.Col = 1
Grid1.CellAlignment = 4
Grid1.Text = rs.Fields(0)
Grid1.Col = 2
Grid1.CellAlignment = 4
Grid1.Text = rs.Fields(1)
rs.MoveNext
n = n + 1
Wend
End If
rs.Close
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货