分享
 
 
 

DBF文件输出到WORD

王朝vb·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

Private i As Integer

Private MacroName As String

Private WordApp As Word.Application

Private doc As Word.Document

Private se1 As Word.Selection

Private db As Database

Private rs As Recordset

Private Sub cmdAdd_Click()

Dim sTmp As String

sTmp = InputBox("输入要添加的新项目:")

If Len(sTmp) = 0 Then Exit Sub

lstItems.AddItem sTmp

End Sub

Private Sub cmdDelete_Click()

If lstItems.ListIndex > -1 Then

If MsgBox("删除 '" & lstItems.Text & "'?", vbQuestion + vbYesNo) = vbYes Then

lstItems.RemoveItem lstItems.ListIndex

End If

End If

End Sub

Private Sub cmdUp_Click()

On Error Resume Next

Dim nItem As Integer

With lstItems

If .ListIndex < 0 Then Exit Sub

nItem = .ListIndex

If nItem = 0 Then Exit Sub '不能将第一个项目向上移动

'向上移动项目

.AddItem .Text, nItem - 1

'删除旧项目

.RemoveItem nItem + 1

'选择刚刚移动的项目

.Selected(nItem - 1) = True

End With

End Sub

Private Sub cmdDown_Click()

On Error Resume Next

Dim nItem As Integer

With lstItems

If .ListIndex < 0 Then Exit Sub

nItem = .ListIndex

If nItem = .ListCount - 1 Then Exit Sub '不能将最后的项目向下移动

'向下移动项目

.AddItem .Text, nItem + 2

'删除旧的项目

.RemoveItem nItem

'选择刚刚移动的项目

.Selected(nItem + 1) = True

End With

End Sub

Private Sub lstItems_DragDrop(Source As Control, X As Single, Y As Single)

Dim i As Integer

Dim nID As Integer

Dim sTmp As String

If Source.Name <> "lstItems" Then Exit Sub

If lstItems.ListCount = 0 Then Exit Sub

With lstItems

i = (Y \ TextHeight("A")) + .TopIndex

If i = .ListIndex Then

'将它放在它自己的上面

Exit Sub

End If

If i > .ListCount - 1 Then i = .ListCount - 1

nID = .ListIndex

sTmp = .Text

If (nID > -1) Then

sTmp = .Text

.RemoveItem nID

.AddItem sTmp, i

.ListIndex = .NewIndex

End If

End With

SetListButtons

End Sub

Sub lstItems_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button = vbLeftButton Then lstItems.Drag

End Sub

Private Sub lstItems_Click()

SetListButtons

End Sub

Sub SetListButtons()

Dim i As Integer

i = lstItems.ListIndex

'设置移动按钮的状态

cmdUp.Enabled = (i > 0)

cmdDown.Enabled = ((i > -1) And (i < (lstItems.ListCount - 1)))

cmdDelete.Enabled = (i > -1)

End Sub

Private Sub Command1_Click()

With dlgCommonDialog

Label4.Caption = .InitDir

.DialogTitle = "打开dbf文件"

.CancelError = False

'ToDo: 设置 common dialog 控件的标志和属性

.Filter = "所有dbf文件 (*.dbf)|*.dbf"

.ShowOpen

If Len(.FileName) = 0 Then

Exit Sub

End If

sfile = .FileName

Label1.Caption = sfile

Label2.Caption = .FileTitle

Label3.Caption = Left(sfile, Len(sfile) - Len(.FileTitle) - 1)

Data1.Caption = .FileTitle

End With

' Data1.Database = Label3.Caption

Data1.DatabaseName = Label3.Caption

Data1.RecordSource = Label2.Caption

' On Error Resume Next

Data1.Refresh

' Form1.MSFlexGrid1.Refresh

Form1.DBGrid1.Refresh

Form1.Refresh

End Sub

Private Sub Command2_Click()

End

End Sub

Private Sub Command3_Click()

If Label2.Caption = "DbfFile:" Then

Call Command1_Click

End If

Set db = Data1.Database

Set rs = Data1.Recordset

Data1.Refresh

Set WordApp = New Word.Application

WordApp.Documents.Add

Set doc = WordApp.ActiveDocument

Set se1 = WordApp.Selection

With doc.PageSetup

.LineNumbering.Active = False

.Orientation = wdOrientLandscape

.TopMargin = CentimetersToPoints(2)

.BottomMargin = CentimetersToPoints(2)

.LeftMargin = CentimetersToPoints(2)

.RightMargin = CentimetersToPoints(2)

.Gutter = CentimetersToPoints(0)

.HeaderDistance = CentimetersToPoints(1.5)

.FooterDistance = CentimetersToPoints(1.75)

.PageWidth = CentimetersToPoints(29.7)

.PageHeight = CentimetersToPoints(21)

.FirstPageTray = wdPrinterDefaultBin

.OtherPagesTray = wdPrinterDefaultBin

.SectionStart = wdSectionNewPage

.OddAndEvenPagesHeaderFooter = False

.DifferentFirstPageHeaderFooter = False

.VerticalAlignment = wdAlignVerticalTop

.SuppressEndnotes = False

.MirrorMargins = False

.TwoPagesOnOne = False

.GutterPos = wdGutterPosLeft

.LayoutMode = wdLayoutModeLineGrid

End With

se1.TypeText Text:="20" & CStr(Date) & " " & CStr(Time())

'doc.Tables.Add Range:=se1.Range, numrows:=1, numcolumns:=List2.ListCount

doc.Tables.Add Range:=se1.Range, numrows:=1, numcolumns:=rs.Fields.Count

For i = 0 To rs.Fields.Count - 1

Screen.MousePointer = 11

'se1.TypeText Text:=rs.Fields(i).Name

se1.TypeText Text:=rs.Fields(i).Name

se1.MoveRight unit:=12

Next

'se1.TypeText Text:="产品名称"

'se1.MoveRight unit:=12

Do Until rs.EOF

For i = 0 To rs.Fields.Count - 1

On Error Resume Next

se1.TypeText Text:=rs.Fields(i).Value

' se1.TypeText Text:=rs.Fields(rs.Fields(i)).Value

se1.MoveRight unit:=12

Next

'se1.TypeText Text:=rs!产品名称

'se1.MoveRight unit:=12

'se1.TypeText Text:=rs!中止

'se1.MoveRight unit:=12

rs.MoveNext

Loop

WordApp.Run MacroName:="AutoFitContent"

se1.InsertBreak

se1.Delete Count:=rs.Fields.Count

se1.Sections(1).Footers(1).PageNumbers.Add PageNumberAlignment:= _

wdAlignPageNumberRight, FirstPage:=True

WordApp.Visible = True

' WordApp.Run MacroName:="InsertDateTime"

Set WordApp = Nothing

Screen.MousePointer = 1

'data1.Recordset.Fields()

End Sub

Private Sub exit_Click()

Close

End

End Sub

Private Sub open_Click()

Call Command1_Click

End Sub

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有