Bez popisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

估價單.vb 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. Option Strict Off
  2. Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
  3. Imports Microsoft.Office.Interop.Excel.Constants
  4. Imports Microsoft.Office.Interop.Excel.XlBordersIndex
  5. Imports Microsoft.Office.Interop.Excel.XlLineStyle
  6. Imports Microsoft.Office.Interop.Excel.XlBorderWeight
  7. Imports Microsoft.Office.Interop.Excel.XlThemeFont
  8. Imports Microsoft.Office.Interop.Excel.XlThemeColor
  9. Imports Microsoft.Office.Interop.Excel.XlWindowState
  10. Imports Microsoft.Office.Interop.Excel
  11. Imports System.IO
  12. Public Class 估價單
  13. ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet : Dim boo As Boolean : Dim 新項次 As String
  14. Dim NUM1, NUM2 As Integer
  15. Dim xlApp As New Microsoft.Office.Interop.Excel.Application
  16. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  17. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  18. Dim 位置1 As String
  19. Dim N2 As Integer : Dim N3 As Integer
  20. Private Sub 估價單_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  21. Me.MdiParent = ICS_ASMS_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  22. 選擇日期_dtp.CustomFormat = "yyyy/MM/dd"
  23. 選擇日期_dtp.Format = DateTimePickerFormat.Custom
  24. 確認新增_bt.Enabled = False : 修改_bt.Enabled = False : boo = False
  25. Set_清單1()
  26. SQL_讀取公司名稱()
  27. If dr.Read() Then
  28. 公司_tb.Text = dr("公司名稱")
  29. End If
  30. End Sub
  31. Private Sub Set_清單1()
  32. 控制表_dgv.DataSource = Nothing : ds.Clear()
  33. 控制表_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  34. 控制表_dgv.ColumnHeadersHeight = 25
  35. 控制表_dgv.AllowUserToAddRows = False
  36. 控制表_dgv.RowTemplate.Height = 30
  37. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  38. SQL_估價單_控制表清單()
  39. da.Fill(ds) : 控制表_dgv.DataSource = ds.Tables(0) : conn.Close()
  40. 控制表_dgv.Columns(1).FillWeight = 50 : 控制表_dgv.Columns(3).FillWeight = 50
  41. 控制表_dgv.Columns(0).Visible = False : 控制表_dgv.Columns(2).Visible = False
  42. 控制表_dgv.Columns(4).Visible = False : 控制表_dgv.Columns(5).Visible = False : 控制表_dgv.Columns(6).Visible = False
  43. 控制表_dgv.Columns(9).Visible = False : 控制表_dgv.Columns(8).Visible = False : 控制表_dgv.Columns(7).Visible = False
  44. End Sub
  45. Private Sub 控制表_dgv_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles 控制表_dgv.CellClick
  46. If boo = False Then
  47. If e.RowIndex = -1 Then : Else
  48. 確認新增_bt.Enabled = False : 修改_bt.Enabled = True
  49. 單號_tb.Text = 控制表_dgv(0, e.RowIndex).Value.ToString : 客戶_tb.Text = 控制表_dgv(1, e.RowIndex).Value.ToString
  50. 選擇日期_dtp.Text = 控制表_dgv(2, e.RowIndex).Value.ToString
  51. 選擇日期_dtp.CustomFormat = "yyyy/MM/dd"
  52. 選擇日期_dtp.Format = DateTimePickerFormat.Custom
  53. 廠牌_tb.Text = 控制表_dgv(3, e.RowIndex).Value.ToString : 進廠_tb.Text = 控制表_dgv(4, e.RowIndex).Value.ToString
  54. 年分_tb.Text = 控制表_dgv(5, e.RowIndex).Value.ToString : 業務_tb.Text = 控制表_dgv(6, e.RowIndex).Value.ToString
  55. Dim value As String = 控制表_dgv(7, e.RowIndex).Value.ToString()
  56. Dim intValue As Integer
  57. If Int32.TryParse(value, intValue) Then
  58. ' 值是整數,格式化為千分位
  59. 總價_tb.Text = Strings.Format(intValue, "#,##0")
  60. Else
  61. ' 值不是整數,不格式化
  62. 總價_tb.Text = value
  63. End If
  64. 備註_tb.Text = 控制表_dgv(8, e.RowIndex).Value.ToString : 付款_tb.Text = 控制表_dgv(9, e.RowIndex).Value.ToString
  65. Set_清單2()
  66. End If
  67. End If
  68. End Sub
  69. Private Sub Set_清單2()
  70. 明細表_dgv.DataSource = Nothing : ds1.Clear()
  71. 明細表_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  72. 明細表_dgv.ColumnHeadersHeight = 25
  73. 明細表_dgv.AllowUserToAddRows = False
  74. 明細表_dgv.RowTemplate.Height = 35
  75. 明細表_dgv.EditMode = DataGridViewEditMode.EditOnEnter
  76. SQL_估價單_查詢明細表() : da.Fill(ds1) : 明細表_dgv.DataSource = ds1.Tables(0) : conn.Close()
  77. 明細表_dgv.Columns("項次").ReadOnly = True
  78. 明細表_dgv.Columns(0).Visible = False : 明細表_dgv.Columns(1).FillWeight = 30 : 明細表_dgv.Columns(2).FillWeight = 400
  79. End Sub
  80. Private Sub 明細表_dgv_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles 明細表_dgv.CellEnter
  81. If e.RowIndex = -1 Then : Else
  82. 項次_tb.Text = 明細表_dgv(1, e.RowIndex).Value.ToString
  83. End If
  84. End Sub
  85. Private Sub 總價_tb_Leave(sender As Object, e As EventArgs) Handles 總價_tb.Leave
  86. If Not String.IsNullOrEmpty(總價_tb.Text) AndAlso IsNumeric(總價_tb.Text) Then
  87. ' 將文本轉換為數字
  88. Dim number As Double = CDbl(總價_tb.Text)
  89. ' 格式化數字為千分位
  90. 總價_tb.Text = number.ToString("#,##0")
  91. End If
  92. End Sub
  93. Private Sub 新增_bt_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click
  94. 新增_bt.Enabled = False : 確認新增_bt.Enabled = True : 修改_bt.Enabled = False
  95. Set_日期格式轉換() : Dim NUM1 As Integer
  96. For i As Integer = 1 To 999
  97. NUM1 = 0 + i
  98. If NUM1 < 10 Then : 單號_tb.Text = "GD-" & DTP1 & "-00" & NUM1
  99. ElseIf NUM1 > 9 And NUM1 < 100 Then : 單號_tb.Text = "GD-" & DTP1 & "-0" & NUM1
  100. ElseIf NUM1 > 99 Then : 單號_tb.Text = "GD-" & DTP1 & "-" & NUM1 : End If
  101. PA = 單號_tb.Text : SQL_估價單_單號查詢()
  102. If dr.Read() Then : Else : i = 999 : conn.Close() : End If : conn.Close()
  103. Next
  104. 客戶_tb.Text = "" : 進廠_tb.Text = "" : 總價_tb.Text = "0" : 業務_tb.Text = ""
  105. 廠牌_tb.Text = "" : 年分_tb.Text = "" : 備註_tb.Text = "" : 付款_tb.Text = ""
  106. SQL_估價單_控制表新增() : boo = True : Set_清單2()
  107. End Sub
  108. Private Sub Set_日期格式轉換()
  109. Dim selectedDate As DateTime = 選擇日期_dtp.Value
  110. DTP4 = Strings.Format(selectedDate, "yyyy/MM/dd") : DTP1 = Strings.Format(selectedDate, "yyyyMMdd")
  111. End Sub
  112. Private Sub 確認新增_bt_Click(sender As Object, e As EventArgs) Handles 確認新增_bt.Click
  113. If 客戶_tb.Text = "" Or 廠牌_tb.Text = "" Then
  114. MsgBox("客戶及廠牌車種未輸入完成!!")
  115. Else
  116. 新增_bt.Enabled = True : 確認新增_bt.Enabled = False : 修改_bt.Enabled = True : boo = False
  117. 選擇日期_dtp.CustomFormat = "yyyy/MM/dd"
  118. 選擇日期_dtp.Format = DateTimePickerFormat.Custom
  119. SQL_估價單_控制表修改() : conn.Close() : MsgBox("儲存成功!!") : Set_清單1()
  120. End If
  121. End Sub
  122. Private Sub 修改_bt_Click(sender As Object, e As EventArgs) Handles 修改_bt.Click
  123. 選擇日期_dtp.CustomFormat = "yyyy/MM/dd"
  124. 選擇日期_dtp.Format = DateTimePickerFormat.Custom
  125. SQL_估價單_控制表修改() : conn.Close() : MsgBox("儲存成功!!") : Set_清單1()
  126. End Sub
  127. Private Sub 刪除_bt_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click
  128. 新增_bt.Enabled = True : 確認新增_bt.Enabled = False : 修改_bt.Enabled = False : boo = False
  129. SQL_估價單_控制表刪除() : SQL_估價單_明細表刪除() : conn.Close() : MsgBox("刪除成功")
  130. 客戶_tb.Text = "" : 進廠_tb.Text = "" : 總價_tb.Text = "" : 業務_tb.Text = ""
  131. 廠牌_tb.Text = "" : 年分_tb.Text = "" : 備註_tb.Text = "" : 付款_tb.Text = ""
  132. 單號_tb.Text = ""
  133. Set_清單1() : Set_清單2() : 項次_tb.Text = ""
  134. End Sub
  135. Private Sub 刪除選中的一筆資料_bt_Click(sender As Object, e As EventArgs) Handles 刪除選中的一筆資料_bt.Click
  136. If 項次_tb.Text = "" Then
  137. MsgBox("未選擇需要刪除的資料。")
  138. Else
  139. For i As Integer = 0 To 明細表_dgv.Rows.Count - 1
  140. PA1 = 明細表_dgv.Rows(i).Cells("項次").Value.ToString : PA2 = 明細表_dgv.Rows(i).Cells("內容").Value.ToString
  141. SQL_估價單_修改明細表() : conn.Close()
  142. Next
  143. SQL_估價單_刪除明細表項次() : SQL_估價單_明細表項次更新() : conn.Close()
  144. Set_清單2() : 項次_tb.Text = "" : MsgBox("刪除成功。")
  145. End If
  146. End Sub
  147. Private Sub 申請_bt_Click(sender As Object, e As EventArgs) Handles 申請_bt.Click
  148. For i As Integer = 0 To 明細表_dgv.Rows.Count - 1
  149. PA1 = 明細表_dgv.Rows(i).Cells("項次").Value.ToString : PA2 = 明細表_dgv.Rows(i).Cells("內容").Value.ToString
  150. SQL_估價單_修改明細表() : conn.Close()
  151. Next : Set_清單2() : MsgBox("儲存成功。")
  152. End Sub
  153. Private Sub 查詢_bt_Click(sender As Object, e As EventArgs) Handles 查詢_bt.Click
  154. CHB("請輸入要查詢的單號資料。") : PA56 = 訊息回應 : Set_清單1() : PA56 = ""
  155. End Sub
  156. Private Sub 收支單中新增一筆空白資料_bt_Click(sender As Object, e As EventArgs) Handles 收支單中新增一筆空白資料_bt.Click
  157. If 單號_tb.Text = "" Then
  158. MsgBox("未選擇單號!!")
  159. Else
  160. If 明細表_dgv.Rows.Count > 0 Then
  161. For i As Integer = 0 To 明細表_dgv.Rows.Count - 1
  162. PA1 = 明細表_dgv.Rows(i).Cells("項次").Value.ToString : PA2 = 明細表_dgv.Rows(i).Cells("內容").Value.ToString
  163. SQL_估價單_修改明細表() : conn.Close()
  164. Next
  165. End If
  166. SQL_估價單_查詢最後一筆單號項次()
  167. If dr.Read() Then
  168. 新項次 = dr("項次")
  169. NUM1 = Double.Parse(新項次) + 1
  170. Else
  171. NUM1 = 1
  172. End If : conn.Close()
  173. PA15 = NUM1.ToString()
  174. SQL_估價單_新增明細表() : conn.Close()
  175. Set_清單2()
  176. MsgBox("明細表新增成功!!")
  177. End If
  178. End Sub
  179. Private Sub 查詢_bt_MouseEnter(sender As Object, e As EventArgs) Handles 查詢_bt.MouseEnter
  180. ToolTip1.SetToolTip(Me.查詢_bt, "查詢單號")
  181. End Sub
  182. Private Sub 新增_bt_MouseEnter(sender As Object, e As EventArgs) Handles 新增_bt.MouseEnter
  183. ToolTip1.SetToolTip(Me.新增_bt, "新增準備")
  184. End Sub
  185. Private Sub 確認新增_bt_MouseEnter(sender As Object, e As EventArgs) Handles 確認新增_bt.MouseEnter
  186. ToolTip1.SetToolTip(Me.確認新增_bt, "確認新增")
  187. End Sub
  188. Private Sub 修改_bt_MouseEnter(sender As Object, e As EventArgs) Handles 修改_bt.MouseEnter
  189. ToolTip1.SetToolTip(Me.修改_bt, "修改存檔")
  190. End Sub
  191. Private Sub 刪除_bt_MouseEnter(sender As Object, e As EventArgs) Handles 刪除_bt.MouseEnter
  192. ToolTip1.SetToolTip(Me.刪除_bt, "刪除")
  193. End Sub
  194. Private Sub 申請_bt_MouseEnter(sender As Object, e As EventArgs) Handles 申請_bt.MouseEnter
  195. ToolTip1.SetToolTip(Me.申請_bt, "資料存檔")
  196. End Sub
  197. Private Sub 匯出EXCEL_bt_MouseEnter(sender As Object, e As EventArgs) Handles 匯出EXCEL_bt.MouseEnter
  198. ToolTip1.SetToolTip(Me.匯出EXCEL_bt, "匯出PDF")
  199. End Sub
  200. Private Sub 收支單中新增一筆空白資料_bt_MouseEnter(sender As Object, e As EventArgs) Handles 收支單中新增一筆空白資料_bt.MouseEnter
  201. ToolTip1.SetToolTip(Me.收支單中新增一筆空白資料_bt, "明細表新增空白的資料")
  202. End Sub
  203. Private Sub 刪除選中的一筆資料_bt_MouseEnter(sender As Object, e As EventArgs) Handles 刪除選中的一筆資料_bt.MouseEnter
  204. ToolTip1.SetToolTip(Me.刪除選中的一筆資料_bt, "刪除選中的一筆資料")
  205. End Sub
  206. Private Sub 匯出EXCEL_bt_Click(sender As Object, e As EventArgs) Handles 匯出EXCEL_bt.Click
  207. xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
  208. xlApp.Visible = True
  209. xlApp.DisplayAlerts = True
  210. xlApp.Application.WindowState = xlMaximized
  211. xlBook = xlApp.Workbooks.Add
  212. xlSheet = NewMethod(xlBook)
  213. xlBook.Activate()
  214. xlSheet.Activate()
  215. xlSheet.Cells(1, 3) = 公司_tb.Text
  216. xlSheet.Cells(2, 3) = "估 價 單"
  217. Dim selectedDate As Date = 選擇日期_dtp.Value
  218. Dim rocYear As Integer = selectedDate.Year - 1911
  219. Dim rocDate As String = rocYear.ToString() & "年" & selectedDate.Month.ToString() & "月" & selectedDate.Day.ToString() & "日"
  220. xlSheet.Cells(3, 2) = "客戶 : " & 客戶_tb.Text : xlSheet.Cells(3, 4) = "報價日期 : " & rocDate
  221. xlSheet.Cells(4, 2) = "廠牌/車種 : " & 廠牌_tb.Text : xlSheet.Cells(4, 4) = "進廠 : " & 進廠_tb.Text
  222. xlSheet.Cells(5, 2) = "車身型式 : " & 年分_tb.Text : xlSheet.Cells(5, 4) = "業務 : " & 業務_tb.Text
  223. xlSheet.Cells(7, 3) = "施工說明 : (以合格證標準規格承製)"
  224. For i As Integer = 0 To 明細表_dgv.Rows.Count - 1
  225. xlSheet.Cells(i + 8, 2) = 明細表_dgv.Rows(i).Cells("項次").Value : xlSheet.Cells(i + 8, 3) = 明細表_dgv.Rows(i).Cells("內容").Value
  226. N2 = 8 + i
  227. Next i
  228. Dim number As Double = CDbl(總價_tb.Text)
  229. xlSheet.Cells(N2 + 1, 3) = "總計 :" & number.ToString("#,##0") & " 元(不含稅)"
  230. xlSheet.Cells(N2 + 2, 3) = "備註 :" & 備註_tb.Text
  231. xlSheet.Cells(N2 + 3, 3) = "付款方式 :" & 付款_tb.Text
  232. BB(xlApp, xlSheet) '未改
  233. xlApp.Sheets(2).Delete : xlSheet.PageSetup.PrintArea = ""
  234. '----轉成PDF-----
  235. Dim pdfFolderPath As String = Path.Combine(System.Windows.Forms.Application.StartupPath, "pdf")
  236. If Not Directory.Exists(pdfFolderPath) Then
  237. Directory.CreateDirectory(pdfFolderPath)
  238. End If
  239. Dim pdfFilePath As String = Path.Combine(pdfFolderPath, 單號_tb.Text & "-估價單.pdf")
  240. xlBook.Sheets(1).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, pdfFilePath, XlFixedFormatQuality.xlQualityStandard, True)
  241. '--------
  242. xlApp.Cells.Select() : xlApp.Application.WindowState = xlMinimized : xlBook.Close(False)
  243. Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
  244. Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
  245. Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
  246. xlApp.Quit() : xlSheet = Nothing : xlBook = Nothing : xlApp = Nothing : GC.Collect()
  247. Try
  248. Dim chromePath As String = "C:\Program Files\Google\Chrome\Application\chrome.exe"
  249. If System.IO.File.Exists(chromePath) Then
  250. Dim process As New Process()
  251. process.StartInfo.FileName = "chrome"
  252. process.StartInfo.Arguments = """" & pdfFilePath & """"
  253. process.Start()
  254. Else : Dim edgePath As String = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
  255. If System.IO.File.Exists(edgePath) Then
  256. Dim process As New Process()
  257. process.StartInfo.FileName = "msedge"
  258. process.StartInfo.Arguments = """" & pdfFilePath & """"
  259. process.Start()
  260. Else
  261. Process.Start(pdfFilePath)
  262. End If
  263. End If
  264. Catch ex As Exception
  265. MsgBox("以存檔至桌面 。" & vbCrLf & "檔案名稱:" & 單號_tb.Text & "-估價單.pdf")
  266. End Try
  267. End Sub
  268. Private Sub BB(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
  269. xlSheet.Cells.Select()
  270. With myExcel.Selection.Font
  271. .Name = "微軟正黑體"
  272. .Size = 14
  273. .Strikethrough = False
  274. .Superscript = False
  275. .Subscript = False
  276. .OutlineFont = False
  277. .Shadow = False
  278. .Underline = xlUnderlineStyleNone
  279. .ThemeColor = xlThemeColorLight1
  280. .TintAndShade = 0
  281. .ThemeFont = xlThemeFontNone
  282. End With
  283. xlSheet.Range("B7:D" & N2 + 3).Select()
  284. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  285. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  286. With myExcel.Selection.Borders(xlEdgeLeft)
  287. .LineStyle = xlContinuous
  288. .ColorIndex = 0
  289. .TintAndShade = 0
  290. .Weight = xlThin
  291. End With
  292. With myExcel.Selection.Borders(xlEdgeTop)
  293. .LineStyle = xlContinuous
  294. .ColorIndex = 0
  295. .TintAndShade = 0
  296. .Weight = xlThin
  297. End With
  298. With myExcel.Selection.Borders(xlEdgeBottom)
  299. .LineStyle = xlContinuous
  300. .ColorIndex = 0
  301. .TintAndShade = 0
  302. .Weight = xlThin
  303. End With
  304. With myExcel.Selection.Borders(xlEdgeRight)
  305. .LineStyle = xlContinuous
  306. .ColorIndex = 0
  307. .TintAndShade = 0
  308. .Weight = xlThin
  309. End With
  310. With myExcel.Selection.Borders(xlInsideVertical)
  311. .LineStyle = xlContinuous
  312. .ColorIndex = 0
  313. .TintAndShade = 0
  314. .Weight = xlThin
  315. End With
  316. With myExcel.Selection.Borders(xlInsideHorizontal)
  317. .LineStyle = xlContinuous
  318. .ColorIndex = 0
  319. .TintAndShade = 0
  320. .Weight = xlThin
  321. End With
  322. xlSheet.Range("C1").Select()
  323. With myExcel.Selection.Font
  324. .Name = "微軟正黑體"
  325. .Size = 20
  326. .Strikethrough = False
  327. .Superscript = False
  328. .Subscript = False
  329. .OutlineFont = False
  330. .Shadow = False
  331. .Underline = xlUnderlineStyleNone
  332. .ThemeColor = xlThemeColorLight1
  333. .TintAndShade = 0
  334. .ThemeFont = xlThemeFontNone
  335. End With
  336. xlSheet.Range("C2").Select()
  337. With myExcel.Selection.Font
  338. .Name = "微軟正黑體"
  339. .Size = 18
  340. .Strikethrough = False
  341. .Superscript = False
  342. .Subscript = False
  343. .OutlineFont = False
  344. .Shadow = False
  345. .Underline = xlUnderlineStyleNone
  346. .ThemeColor = xlThemeColorLight1
  347. .TintAndShade = 0
  348. .ThemeFont = xlThemeFontNone
  349. End With
  350. xlSheet.Rows("1:1").EntireRow.AutoFit
  351. xlSheet.Rows("2:2").EntireRow.AutoFit
  352. xlSheet.Columns("A:A").ColumnWidth = 8
  353. xlSheet.Columns("B:B").ColumnWidth = 5
  354. xlSheet.Columns("C:C").ColumnWidth = 35
  355. xlSheet.Columns("D:D").ColumnWidth = 40
  356. xlSheet.Range("B1:D1").Select()
  357. With myExcel.Selection
  358. .HorizontalAlignment = xlCenter
  359. .VerticalAlignment = xlCenter
  360. .WrapText = False
  361. .Orientation = 0
  362. .AddIndent = False
  363. .IndentLevel = 0
  364. .ShrinkToFit = False
  365. .ReadingOrder = xlContext
  366. .MergeCells = False
  367. End With
  368. myExcel.Selection.Merge
  369. xlSheet.Range("B2:D2").Select()
  370. With myExcel.Selection
  371. .HorizontalAlignment = xlCenter
  372. .VerticalAlignment = xlCenter
  373. .WrapText = False
  374. .Orientation = 0
  375. .AddIndent = False
  376. .IndentLevel = 0
  377. .ShrinkToFit = False
  378. .ReadingOrder = xlContext
  379. .MergeCells = False
  380. End With
  381. myExcel.Selection.Merge
  382. xlSheet.Range("B3:C3").Select()
  383. With myExcel.Selection
  384. .HorizontalAlignment = xlLeft
  385. .VerticalAlignment = xlCenter
  386. .WrapText = False
  387. .Orientation = 0
  388. .AddIndent = False
  389. .IndentLevel = 0
  390. .ShrinkToFit = False
  391. .ReadingOrder = xlContext
  392. .MergeCells = False
  393. End With
  394. myExcel.Selection.Merge
  395. xlSheet.Range("B4:C4").Select()
  396. With myExcel.Selection
  397. .HorizontalAlignment = xlLeft
  398. .VerticalAlignment = xlCenter
  399. .WrapText = False
  400. .Orientation = 0
  401. .AddIndent = False
  402. .IndentLevel = 0
  403. .ShrinkToFit = False
  404. .ReadingOrder = xlContext
  405. .MergeCells = False
  406. End With
  407. myExcel.Selection.Merge
  408. xlSheet.Range("B5:C5").Select()
  409. With myExcel.Selection
  410. .HorizontalAlignment = xlLeft
  411. .VerticalAlignment = xlCenter
  412. .WrapText = False
  413. .Orientation = 0
  414. .AddIndent = False
  415. .IndentLevel = 0
  416. .ShrinkToFit = False
  417. .ReadingOrder = xlContext
  418. .MergeCells = False
  419. End With
  420. myExcel.Selection.Merge
  421. xlSheet.Range("B7:D7").Select()
  422. With myExcel.Selection
  423. .HorizontalAlignment = xlCenter
  424. .VerticalAlignment = xlCenter
  425. .WrapText = False
  426. .Orientation = 0
  427. .AddIndent = False
  428. .IndentLevel = 0
  429. .ShrinkToFit = False
  430. .ReadingOrder = xlContext
  431. .MergeCells = False
  432. End With
  433. myExcel.Selection.Merge
  434. For i As Integer = 8 To N2 + 3
  435. xlSheet.Range("C" & i & ":D" & i).Select()
  436. If i > N2 Then
  437. With myExcel.Selection
  438. .HorizontalAlignment = xlCenter
  439. .VerticalAlignment = xlCenter
  440. .WrapText = False
  441. .Orientation = 0
  442. .AddIndent = False
  443. .IndentLevel = 0
  444. .ShrinkToFit = False
  445. .ReadingOrder = xlContext
  446. .MergeCells = False
  447. End With
  448. Else
  449. With myExcel.Selection
  450. .HorizontalAlignment = xlLeft
  451. .VerticalAlignment = xlCenter
  452. .WrapText = False
  453. .Orientation = 0
  454. .AddIndent = False
  455. .IndentLevel = 0
  456. .ShrinkToFit = False
  457. .ReadingOrder = xlContext
  458. .MergeCells = False
  459. End With
  460. End If
  461. myExcel.Selection.Merge
  462. xlSheet.Range("B" & i).Select()
  463. With myExcel.Selection
  464. .HorizontalAlignment = xlCenter
  465. .VerticalAlignment = xlCenter
  466. .WrapText = False
  467. .Orientation = 0
  468. .AddIndent = False
  469. .IndentLevel = 0
  470. .ShrinkToFit = False
  471. .ReadingOrder = xlContext
  472. .MergeCells = False
  473. End With
  474. Next i
  475. For i = 1 To N2 + 3
  476. xlSheet.Rows(i).RowHeight = xlSheet.Rows(i).RowHeight + 5
  477. Next i
  478. myExcel.Application.PrintCommunication = False
  479. With myExcel.ActiveSheet.PageSetup
  480. .PrintTitleRows = ""
  481. .PrintTitleColumns = ""
  482. End With
  483. myExcel.Application.PrintCommunication = True
  484. myExcel.ActiveSheet.PageSetup.PrintArea = ""
  485. myExcel.Application.PrintCommunication = False
  486. With myExcel.ActiveSheet.PageSetup
  487. .LeftHeader = ""
  488. .CenterHeader = ""
  489. .RightHeader = ""
  490. .LeftFooter = ""
  491. .CenterFooter = ""
  492. .RightFooter = ""
  493. .LeftMargin = myExcel.Application.InchesToPoints(0.25)
  494. .RightMargin = myExcel.Application.InchesToPoints(0.25)
  495. .TopMargin = myExcel.Application.InchesToPoints(0.75)
  496. .BottomMargin = myExcel.Application.InchesToPoints(0.75)
  497. .HeaderMargin = myExcel.Application.InchesToPoints(0.3)
  498. .FooterMargin = myExcel.Application.InchesToPoints(0.3)
  499. .PrintHeadings = False
  500. .PrintGridlines = False
  501. .CenterHorizontally = False
  502. .CenterVertically = False
  503. .Draft = False
  504. .FirstPageNumber = xlAutomatic
  505. .BlackAndWhite = False
  506. .Zoom = False
  507. .FitToPagesWide = 1
  508. .FitToPagesTall = False
  509. .OddAndEvenPagesHeaderFooter = False
  510. .DifferentFirstPageHeaderFooter = False
  511. .ScaleWithDocHeaderFooter = True
  512. .AlignMarginsHeaderFooter = True
  513. .EvenPage.LeftHeader.Text = ""
  514. .EvenPage.CenterHeader.Text = ""
  515. .EvenPage.RightHeader.Text = ""
  516. .EvenPage.LeftFooter.Text = ""
  517. .EvenPage.CenterFooter.Text = ""
  518. .EvenPage.RightFooter.Text = ""
  519. .FirstPage.LeftHeader.Text = ""
  520. .FirstPage.CenterHeader.Text = ""
  521. .FirstPage.RightHeader.Text = ""
  522. .FirstPage.LeftFooter.Text = ""
  523. .FirstPage.CenterFooter.Text = ""
  524. .FirstPage.RightFooter.Text = ""
  525. End With
  526. myExcel.Application.PrintCommunication = True
  527. End Sub
  528. Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet
  529. Return CType(xlBook.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet)
  530. End Function
  531. End Class