桑葚膏的价格:vb6如何打印EXCEL工作表插件,name=SHEET1

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/20 01:54:46
我在FORM1中加入一个EXCEL工作表sheet1怎么将它在打印机上打出来
最好有代码

这个是VB导出listview的数据到EXCEL的,看看吧

Private Function ExportDetail(strFileName As String) As Boolean

Dim iRow As Long
Dim myExcel As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

On Error GoTo ErrAction
ExportDetail = False
Me.MousePointer = 13

Set myExcel = New Excel.Application
myExcel.Visible = False
myExcel.SheetsInNewWorkbook = 1
Set xlBook = myExcel.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)

xlSheet.Name = "物料BOM" 工作表的名字
xlSheet.Columns.ClearFormats
xlSheet.Cells(1, 1) = "物料BOM【" & TreeFile.SelectedItem.Text & "】"
xlSheet.Range("A1:U1").MergeCells = True

xlSheet.Cells(2, 1) = "标题项"
xlSheet.Cells(2, 2) = "中文名称"
xlSheet.Cells(2, 3) = "英文名称"
xlSheet.Cells(2, 4) = "文档号"
xlSheet.Cells(2, 5) = "物料号"
xlSheet.Cells(2, 6) = "数量"
xlSheet.Cells(2, 7) = "总数量"
xlSheet.Cells(2, 8) = "单位"
xlSheet.Cells(2, 9) = "物料关联文档1"
xlSheet.Cells(2, 10) = "物料关联文档2"
xlSheet.Cells(2, 11) = "所属装配文档号"
xlSheet.Cells(2, 12) = "所属装配物料号"
xlSheet.Cells(2, 13) = "装配物料关联文档1"
xlSheet.Cells(2, 14) = "装配物料关联文档2"
xlSheet.Cells(2, 15) = "物料技术参数"
xlSheet.Cells(2, 16) = "物料类型"
xlSheet.Cells(2, 17) = "物料备注"
xlSheet.Cells(2, 18) = "重量"
xlSheet.Cells(2, 19) = "备注"
xlSheet.Cells(2, 20) = "清单文档号"
xlSheet.Cells(2, 21) = "工艺分工"

For iRow = 1 To DocList.ListItems.Count
xlSheet.Cells(iRow + 2, 1) = DocList.ListItems(iRow).ListSubItems(1)
xlSheet.Cells(iRow + 2, 2) = DocList.ListItems(iRow).ListSubItems(2)
xlSheet.Cells(iRow + 2, 3) = DocList.ListItems(iRow).ListSubItems(3)
xlSheet.Cells(iRow + 2, 4) = DocList.ListItems(iRow).ListSubItems(4)
xlSheet.Cells(iRow + 2, 5) = DocList.ListItems(iRow).ListSubItems(5)
xlSheet.Cells(iRow + 2, 6) = DocList.ListItems(iRow).ListSubItems(6)
xlSheet.Cells(iRow + 2, 7) = DocList.ListItems(iRow).ListSubItems(7)
xlSheet.Cells(iRow + 2, 8) = DocList.ListItems(iRow).ListSubItems(8)
xlSheet.Cells(iRow + 2, 9) = DocList.ListItems(iRow).ListSubItems(9)
xlSheet.Cells(iRow + 2, 10) = DocList.ListItems(iRow).ListSubItems(10)
xlSheet.Cells(iRow + 2, 11) = DocList.ListItems(iRow).ListSubItems(11)
xlSheet.Cells(iRow + 2, 12) = DocList.ListItems(iRow).ListSubItems(12)
xlSheet.Cells(iRow + 2, 13) = DocList.ListItems(iRow).ListSubItems(13)
xlSheet.Cells(iRow + 2, 14) = DocList.ListItems(iRow).ListSubItems(14)
xlSheet.Cells(iRow + 2, 15) = DocList.ListItems(iRow).ListSubItems(15)
xlSheet.Cells(iRow + 2, 16) = DocList.ListItems(iRow).ListSubItems(16)
xlSheet.Cells(iRow + 2, 17) = DocList.ListItems(iRow).ListSubItems(17)
xlSheet.Cells(iRow + 2, 18) = DocList.ListItems(iRow).ListSubItems(18)
xlSheet.Cells(iRow + 2, 19) = DocList.ListItems(iRow).ListSubItems(19)
xlSheet.Cells(iRow + 2, 20) = DocList.ListItems(iRow).ListSubItems(20)
xlSheet.Cells(iRow + 2, 21) = DocList.ListItems(iRow).ListSubItems(21)
Next

xlSheet.Columns.AutoFit
xlSheet.Rows(2).Font.Bold = True
xlBook.SaveAs strFileName
myExcel.Quit
Set myExcel = Nothing

ExportDetail = True
Me.MousePointer = 1
Exit Function

ErrAction:
ExportDetail = False
MsgBox "导出失败:" & Err.Description, vbCritical, "导出到EXCEL"
End Function