📄 baobiaoguanli.frm
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form baobiaoguanli
Caption = "报表管理"
ClientHeight = 9060
ClientLeft = 60
ClientTop = 450
ClientWidth = 9975
LinkTopic = "Form1"
LockControls = -1 'True
MDIChild = -1 'True
ScaleHeight = 9060
ScaleWidth = 9975
WindowState = 2 'Maximized
Begin VB.Frame Frame1
Height = 9015
Left = 240
TabIndex = 0
Top = 240
Width = 14895
Begin MSAdodcLib.Adodc Adodc1
Height = 495
Left = 4440
Top = 7080
Width = 2895
_ExtentX = 5106
_ExtentY = 873
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 8
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 1
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=master;Data Source=2NBPC026"
OLEDBString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=master;Data Source=2NBPC026"
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = ""
Password = ""
RecordSource = ""
Caption = "Adodc1"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_Version = 393216
End
Begin VB.CommandButton Command2
Caption = "报表输出excel"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 6120
TabIndex = 3
Top = 6000
Width = 1935
End
Begin VB.CommandButton Command1
Caption = "报表输出word"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 3360
TabIndex = 2
Top = 6000
Width = 1935
End
Begin MSDataGridLib.DataGrid DataGrid1
Height = 5055
Left = 120
TabIndex = 1
Top = 480
Width = 14535
_ExtentX = 25638
_ExtentY = 8916
_Version = 393216
HeadLines = 1
RowHeight = 15
BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ColumnCount = 2
BeginProperty Column00
DataField = ""
Caption = ""
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 0
EndProperty
EndProperty
BeginProperty Column01
DataField = ""
Caption = ""
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 0
EndProperty
EndProperty
SplitCount = 1
BeginProperty Split0
BeginProperty Column00
EndProperty
BeginProperty Column01
EndProperty
EndProperty
End
End
End
Attribute VB_Name = "baobiaoguanli"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim conn As New ADODB.Connection
Dim rs As New Recordset
Dim n% '用于记录字段数
Private Sub Command1_Click()
Dim w As New Word.Application
Dim wdoc As Word.Document
Dim wtable As table
Set wdoc = w.Documents.Add
w.Visible = True
Set wtable = wdoc.Tables.Add(wdoc.Range, 1, n) '插入一个1行N列的表格
'填表头
For i = 0 To n - 1
wtable.Cell(1, i + 1).Range.InsertAfter rs.Fields(i).Name
Next i
p = 2
Do Until rs.EOF
wtable.Rows(wtable.Rows.Count).Select '选中表的最后一行
w.Selection.InsertRowsBelow 1 '在表的最后一行后插入一行,以备写新的内容
For i = 0 To n - 1
wtable.Cell(p, i + 1).Range.InsertAfter rs.Fields(i).Value
Next i
rs.MoveNext
p = p + 1
Loop
For i = 0 To n - 1
wtable.Cell(1, i + 1).Range.InsertAfter rs.Fields(i).Name
Next i
End Sub
Private Sub Command2_Click()
Dim x As New Excel.Application '创建一个excel应用程序对象
Dim xbook As Excel.Workbook '创建一个excel工作薄对象
Dim xsheet As Excel.Worksheet '创建一个excel工作表对象
Dim i%, p%
x.Visible = True '将excel应用程序置前台
Set xbook = x.Workbooks.Add '添加一个工作薄
Set xsheet = xbook.ActiveSheet '为xsheet对象赋值
For i = 0 To n - 1
xsheet.Cells(1, i + 1) = rs.Fields(i).Name
Next i
p = 2 '记录数据写入excel的起始行
Do Until rs.EOF
'输出数据表中的数据
For i = 0 To n - 1
xsheet.Cells(p, i + 1) = rs.Fields(i).Value
Next i
p = p + 1
rs.MoveNext
Loop
End Sub
Private Sub Form_Load()
conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=lisq;Data Source=2NBPC026"
conn.Open
conn.CursorLocation = adUseClient
rs.Open "select 商品名称,计量单位,进货日期,供应商名,地址,电话,进价,数量,出产地 from shangpinrukuxinxi ", conn
Set DataGrid1.DataSource = rs
n = rs.Fields.Count
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -