$EXCEL = _ExcelBookNew(0)
If @error = 1 Then
MsgBox(262144, "错误!", "本机未安装Office EXCEL,请安装后再试!")
Else
$Rows = 1
$EXCEL.DisplayAlerts = False ;不提示操作信息
$EXCEL.Worksheets("Sheet2").Delete ;删除Sheet2
$EXCEL.Worksheets("Sheet3").Delete ;删除Sheet3
$EXCEL.DisplayAlerts = True
$EXCEL.Worksheets("Sheet1").Activate
$EXCEL.Cells.VerticalAlignment = -4108 ;设置垂直对齐方式为居中
$EXCEL.Cells.HorizontalAlignment = -4108 ;设置水平对齐方式为居中
$EXCEL.ActiveSheet.Columns(1).ColumnWidth = 10 ;设置列宽
$EXCEL.ActiveSheet.Columns(2).ColumnWidth = 18
$EXCEL.ActiveSheet.Columns(3).ColumnWidth = 8
$EXCEL.ActiveSheet.Columns(4).ColumnWidth = 14
$EXCEL.ActiveSheet.Columns(5).ColumnWidth = 8
$EXCEL.ActiveSheet.Columns(6).ColumnWidth = 8.88
$EXCEL.ActiveSheet.Columns(7).ColumnWidth = 8
$EXCEL.ActiveSheet.Columns(8).ColumnWidth = 9
;$EXCEL.Windows(1).DisplayGridlines=False ;是否显示网格
;$EXCEL.Columns.AutoFit ;自动调整列以获得更佳视图
;$EXCEL.Rows.AutoFit ;自动调整行以获得更佳视图
$EXCEL.Rows($Rows).RowHeight = 20
_range($EXCEL, "A" & $Rows & ":H" & $Rows);合并单元格
_ExcelFontSetProperties($EXCEL, 1, 1, 1, 1, True, False, False)
If $tempC[1][9] = 0 Then
_ExcelWriteCell($EXCEL, "<" & $QLKS & "> " & "汇总单", $Rows, 1)
Else
_ExcelWriteCell($EXCEL, "<" & $QLKS & "> " & "汇总单 (重打)", $Rows, 1)
EndIf
$Rows += 1
$EXCEL.Rows($Rows).RowHeight = 15
$EXCEL.workbooks(1).activesheet.range("A" & $Rows).numberformatlocal = "@" ;设置为文本格式
_ExcelWriteCell($EXCEL, "汇总单号", $Rows, 1)
_ExcelWriteCell($EXCEL, $tempC[1][1], $Rows, 2)
_ExcelWriteCell($EXCEL, "日期", $Rows, 3)
_ExcelWriteCell($EXCEL, $tempC[1][4], $Rows, 4)
_ExcelWriteCell($EXCEL, "时间", $Rows, 5)
_ExcelWriteCell($EXCEL, $tempC[1][5], $Rows, 6)
_ExcelWriteCell($EXCEL, "人员", $Rows, 7)
_ExcelWriteCell($EXCEL, $tempC[1][6], $Rows, 8)
$Rows += 1
$EXCEL.Rows($Rows).RowHeight = 15
_ExcelWriteCell($EXCEL, "编码", $Rows, 1)
_ExcelWriteCell($EXCEL, "名称", $Rows, 2)
_ExcelWriteCell($EXCEL, "单价", $Rows, 3)
_ExcelWriteCell($EXCEL, "规格", $Rows, 4)
_ExcelWriteCell($EXCEL, "申请数量", $Rows, 5)
_ExcelWriteCell($EXCEL, "冲减数量", $Rows, 6)
_ExcelWriteCell($EXCEL, "实发数量", $Rows, 7)
_ExcelWriteCell($EXCEL, "金额", $Rows, 8)
$Rows += 1
$KSRows = $Rows
$JE = 0
For $i = 1 To $tempD[0][0]
$EXCEL.workbooks(1).activesheet.range("A" & $Rows).numberformatlocal = "@" ;设置为文本格式
For $A = 1 To 8
_ExcelWriteCell($EXCEL, $tempD[$i][$A], $Rows, $A)
If $A <= 4 And $A <> 3 Then _ExcelHorizontalAlignSet($EXCEL, $Rows, $A, $Rows, $A)
Next
$JE += $tempD[$i][8]
$Rows += 1
Next
_ExcelWriteCell($EXCEL, "合计", $Rows, 1)
_ExcelWriteCell($EXCEL, $tempD[0][0] & " 种", $Rows, 2)
_ExcelWriteCell($EXCEL, "合计", $Rows, 7)
_ExcelWriteCell($EXCEL, $JE, $Rows, 8)
$Rows += 1
$EXCEL.Rows($Rows).RowHeight = 20
_range($EXCEL, "A" & $Rows & ":C" & $Rows)
_range($EXCEL, "E" & $Rows & ":H" & $Rows)
_ExcelWriteCell($EXCEL, "开始日期:" & $tempC[1][10], $Rows, 1)
_ExcelWriteCell($EXCEL, $tempC[1][2], $Rows, 4)
_ExcelWriteCell($EXCEL, "结束日期:" & $tempC[1][11], $Rows, 5)
If $HZDDY = 0 Then
If $tempC[1][7] <> "" Then
$Rows += 1
$FYRows = $Rows
_range($EXCEL, "B" & $Rows & ":H" & $Rows)
$EXCEL.workbooks(1).activesheet.range("B" & $Rows).numberformatlocal = "@" ;设置为文本格式
_ExcelWriteCell($EXCEL, "申请单", $Rows, 1)
$FYARR = StringSplit($tempC[1][7], ",")
$FYTYD = ""
$E = 1
For $D = 1 To $FYARR[0]
If $E <= 11 Then
If $D = $FYARR[0] Or $E = 11 Then
$FYTYD = $FYTYD & $FYARR[$D]
Else
$FYTYD = $FYTYD & $FYARR[$D] & ","
EndIf
Else
_ExcelWriteCell($EXCEL, $FYTYD, $Rows, 2)
$E = 1
$FYTYD = ""
$FYTYD = $FYTYD & $FYARR[$D] & ","
If $D <> $FYARR[0] Then
$Rows += 1
_range($EXCEL, "A" & $FYRows & ":A" & $Rows)
_range($EXCEL, "B" & $Rows & ":H" & $Rows)
$EXCEL.workbooks(1).activesheet.range("B" & $Rows).numberformatlocal = "@" ;设置为文本格式
EndIf
EndIf
$E += 1
Next
If $Rows = $FYRows And $FYTYD <> "" Then
_ExcelWriteCell($EXCEL, $FYTYD, $Rows, 2)
ElseIf $Rows <> $FYRows And $FYTYD <> "" Then
_range($EXCEL, "A" & $FYRows & ":A" & $Rows)
_range($EXCEL, "B" & $Rows & ":H" & $Rows)
$EXCEL.workbooks(1).activesheet.range("B" & $Rows).numberformatlocal = "@" ;设置为文本格式
_ExcelWriteCell($EXCEL, $FYTYD, $Rows, 2)
EndIf
$Rows += 1
_range($EXCEL, "A" & $FYRows & ":A" & $Rows)
_range($EXCEL, "B" & $Rows & ":H" & $Rows)
_ExcelWriteCell($EXCEL, "申请单共计: " & $FYARR[0] & " 张", $Rows, 2)
EndIf
If $tempC[1][8] <> "" Then
$Rows += 1
$FYRows = $Rows
_range($EXCEL, "B" & $Rows & ":H" & $Rows)
$EXCEL.workbooks(1).activesheet.range("B" & $Rows).numberformatlocal = "@" ;设置为文本格式
_ExcelWriteCell($EXCEL, "冲减单号", $Rows, 1)
$FYARR = StringSplit($tempC[1][8], ",")
$FYTYD = ""
$E = 1
For $D = 1 To $FYARR[0]
If $E <= 11 Then
If $D = $FYARR[0] Or $E = 11 Then
$FYTYD = $FYTYD & $FYARR[$D]
Else
$FYTYD = $FYTYD & $FYARR[$D] & ","
EndIf
Else
_ExcelWriteCell($EXCEL, $FYTYD, $Rows, 2)
$E = 1
$FYTYD = ""
$FYTYD = $FYTYD & $FYARR[$D] & ","
If $D <> $FYARR[0] Then
$Rows += 1
_range($EXCEL, "A" & $FYRows & ":A" & $Rows)
_range($EXCEL, "B" & $Rows & ":H" & $Rows)
$EXCEL.workbooks(1).activesheet.range("B" & $Rows).numberformatlocal = "@" ;设置为文本格式
EndIf
EndIf
$E += 1
Next
If $Rows = $FYRows And $FYTYD <> "" Then
_ExcelWriteCell($EXCEL, $FYTYD, $Rows, 2)
ElseIf $Rows <> $FYRows And $FYTYD <> "" Then
_range($EXCEL, "A" & $FYRows & ":A" & $Rows)
_range($EXCEL, "B" & $Rows & ":H" & $Rows)
$EXCEL.workbooks(1).activesheet.range("B" & $Rows).numberformatlocal = "@" ;设置为文本格式
_ExcelWriteCell($EXCEL, $FYTYD, $Rows, 2)
EndIf
$Rows += 1
_range($EXCEL, "A" & $FYRows & ":A" & $Rows)
_range($EXCEL, "B" & $Rows & ":H" & $Rows)
_ExcelWriteCell($EXCEL, "冲减单共计: " & $FYARR[0] & " 张", $Rows, 2)
EndIf
EndIf
$Rows += 1
$EXCEL.Rows($Rows).RowHeight = 20
_range($EXCEL, "E" & $Rows & ":F" & $Rows)
_range($EXCEL, "G" & $Rows & ":H" & $Rows)
_ExcelWriteCell($EXCEL, "打印时间", $Rows, 1)
_ExcelWriteCell($EXCEL, _NowCalc(), $Rows, 2)
_ExcelWriteCell($EXCEL, "打印", $Rows, 3)
_ExcelWriteCell($EXCEL, $LoginName, $Rows, 4)
_ExcelWriteCell($EXCEL, "签收", $Rows, 5)
$EXCEL.Range("A" & $KSRows - 1 & ":H" & $Rows).Borders(2).LineStyle = 1
$EXCEL.Range("A" & $KSRows - 1 & ":H" & $Rows).Borders(3).LineStyle = 1
$EXCEL.Range("A" & $KSRows - 1 & ":H" & $Rows).Borders(7).LineStyle = 1
$EXCEL.Range("A" & $KSRows - 1 & ":H" & $Rows).Borders(8).LineStyle = 1
$EXCEL.Range("A" & $KSRows - 1 & ":H" & $Rows).Borders(9).LineStyle = 1
$EXCEL.Range("A" & $KSRows - 1 & ":H" & $Rows).Borders(10).LineStyle = 1
_GUICtrlListView_SetItemText($YPHZListView[1], $CKIndex, "已打", 4)
_ExcelBookSave($EXCEL)
$EXCEL.ActiveWorkbook.PrintOut()
_ExcelBookClose($EXCEL)
EndIf
请问是不是从$EXCEL.ActiveWorkbook.PrintOut()这个函数上下手啊。 PS:真心求教。。。希望能指点一下