16,554
社区成员
发帖
与我相关
我的任务
分享
#Region "打印家访单"
Private Sub 打印ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打印ToolStripMenuItem.Click
Dim xlsapp As New Excel.Application
Dim xlswkbk As Excel.Workbook
Dim xlsst As Excel.Worksheet
xlswkbk = xlsapp.Workbooks.Add
xlsst = xlswkbk.Sheets(1)
xlsapp.Visible = True
For i As Integer = 0 To TaskDatag.SelectedRows.Count - 1
Try
xlsst.Cells(1, 1) = "地区"
xlsst.Cells(1, 2) = "经销店/派单人"
xlsst.Cells(1, 3) = "单号"
xlsst.Cells(1, 4) = "申请人"
xlsst.Cells(1, 5) = "联系电话"
xlsst.Cells(1, 6) = "家访地点"
xlsst.Cells(1, 7) = "家访需求"
xlsst.Cells(1, 8) = "其它资料"
xlsst.Cells(2, 1) = TaskDatag.SelectedRows(i).Cells("地区").Value.ToString.Trim
xlsst.Cells(2, 2) = TaskDatag.SelectedRows(i).Cells("4S店名称(派单人)").Value.ToString.Trim
xlsst.Cells(2, 3) = TaskDatag.SelectedRows(i).Cells("单号").Value.ToString.Trim
xlsst.Cells(2, 4) = TaskDatag.SelectedRows(i).Cells("申请人姓名").Value.ToString.Trim
xlsst.Cells(2, 5) = TaskDatag.SelectedRows(i).Cells("联系电话").Value.ToString.Trim
xlsst.Cells(2, 6) = TaskDatag.SelectedRows(i).Cells("家访地点").Value.ToString.Trim
xlsst.Cells(2, 7) = TaskDatag.SelectedRows(i).Cells("家访需求").Value.ToString.Trim
Dim other As DataTable = myfunc.getdatatable("select 联系类型,数据 from information where 任务编号='" & TaskDatag.SelectedRows(i).Cells("任务编号").Value.ToString.Trim & "'") ‘getdatatable是一个返回查询结果的函数
Dim str As String = ""
For Each otherrow As DataRow In other.Rows
str = str & otherrow("联系类型").ToString.Trim & ":" & otherrow("数据").ToString.Trim & vbCrLf
Next
xlsst.Cells(2, 8) = str
xlsapp.Range("B2").Select() '从这里开始都是Excel的版式设置
With xlsapp.Selection
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.MergeCells = False
End With
xlsapp.Range("G2").Select()
With xlsapp.Selection
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.MergeCells = False
End With
xlsapp.Range("F2").Select()
With xlsapp.Selection
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.MergeCells = False
End With
xlsst.Columns("F:F").ColumnWidth = 12
xlsst.Columns("G:G").ColumnWidth = 41.5
xlsst.Rows("2:2").RowHeight = 173.25
xlsst.Columns("B:B").ColumnWidth = 18
xlsst.Columns("E:E").ColumnWidth = 12
xlsst.Columns("H:H").ColumnWidth = 26
xlsapp.Range("A1:H2").Select()
With xlsapp.Selection.Borders(7)
.LineStyle = 1
.Weight = 2
.ColorIndex = -4105
End With
With xlsapp.Selection.Borders(8)
.LineStyle = 1
.Weight = 2
.ColorIndex = -4105
End With
With xlsapp.Selection.Borders(9)
.LineStyle = 1
.Weight = 2
.ColorIndex = -4105
End With
With xlsapp.Selection.Borders(10)
.LineStyle = 1
.Weight = 2
.ColorIndex = -4105
End With
With xlsapp.Selection.Borders(11)
.LineStyle = 1
.Weight = 2
.ColorIndex = -4105
End With
With xlsapp.Selection.Borders(12)
.LineStyle = 1
.Weight = 2
.ColorIndex = -4105
End With
With xlsapp.ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
xlsapp.ActiveSheet.PageSetup.PrintArea = ""
With xlsapp.ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = -4142
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = 2
.Draft = False
.PaperSize = 9
.FirstPageNumber = -4105
.Order = 1
.BlackAndWhite = False
.Zoom = 80
.PrintErrors = 0
End With '设置结束
xlsapp.Selection.PrintOut(Copies:=1, Collate:=True) '打印
Catch
MessageBox.Show(TaskDatag.SelectedRows(i).Cells("申请人姓名").Value.ToString.Trim & "的家访单打印时出错未知错误,系统已自动忽略。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
Next
If File.Exists(Application.StartupPath & "\temp.xls") Then File.Delete(Application.StartupPath & "\temp.xls")
xlswkbk.SaveAs(Application.StartupPath & "\temp.xls")
xlsapp.Quit()
xlsst = Nothing
xlswkbk = Nothing
xlsapp = Nothing
GC.Collect()
End Sub
#End Region