Açıklama Yok
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 44KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  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.Drawing.Printing
  12. Imports System.Text
  13. Imports System.IO
  14. Public Class 公函
  15. Dim xlApp As 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. ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet
  21. ReadOnly QRCODE As DotNetBarcode = New DotNetBarcode
  22. Private Sub 公函_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  23. Me.MdiParent = ICS_ASMS_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  24. SQL_讀取公司資料()
  25. If dr.Read() Then
  26. 公司名稱.Text = dr("公司名稱")
  27. 地址.Text = dr("地址")
  28. 電話.Text = dr("電話")
  29. 傳真.Text = dr("傳真")
  30. 簡稱.Text = dr("簡稱")
  31. End If
  32. conn.Close()
  33. 已核准的營運成本收支單_rb.Checked = True
  34. 作廢的營運成本收支單_rb.Checked = False
  35. Set_清單1()
  36. 刪除_bt.Enabled = False : 儲存_bt.Enabled = False : 作廢_bt.Enabled = False : 列印_bt.Enabled = False
  37. End Sub
  38. Private Sub Set_清單1()
  39. 控制表_dgv.DataSource = Nothing : ds1.Clear()
  40. 控制表_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  41. 控制表_dgv.ColumnHeadersHeight = 25
  42. 控制表_dgv.AllowUserToAddRows = False
  43. 控制表_dgv.RowTemplate.Height = 30
  44. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  45. If 作廢的營運成本收支單_rb.Checked = True And 已核准的營運成本收支單_rb.Checked = False Then
  46. SQL_公函_控制表清單1()
  47. ElseIf 作廢的營運成本收支單_rb.Checked = False And 已核准的營運成本收支單_rb.Checked = True Then
  48. SQL_公函_控制表清單()
  49. End If
  50. da.Fill(ds1) : 控制表_dgv.DataSource = ds1.Tables(0) : conn.Close()
  51. 控制表_dgv.Columns(0).FillWeight = 20 : 控制表_dgv.Columns(1).Visible = False : 控制表_dgv.Columns(2).Visible = False
  52. 控制表_dgv.Columns(3).Visible = False : 控制表_dgv.Columns(4).Visible = False : 控制表_dgv.Columns(5).Visible = False
  53. 控制表_dgv.Columns(6).Visible = False : 控制表_dgv.Columns(8).Visible = False : 控制表_dgv.Columns(7).FillWeight = 20
  54. 控制表_dgv.Columns(9).Visible = False : 控制表_dgv.Columns(10).Visible = False : 控制表_dgv.Columns(11).Visible = False
  55. 控制表_dgv.Columns(12).Visible = False : 控制表_dgv.Columns(13).Visible = False : 控制表_dgv.Columns(14).Visible = False
  56. End Sub
  57. Private Sub 縮放_tb_Click(sender As Object, e As EventArgs) Handles 縮放_tb.Click
  58. If 控制表_dgv.Size.Width = 200 Then
  59. 控制表_dgv.Size = New Size(620, 控制表_dgv.Size.Height)
  60. 控制表_dgv.Columns(7).FillWeight = 120
  61. 控制表_dgv.Columns(0).FillWeight = 20
  62. Else
  63. 控制表_dgv.Size = New Size(200, 控制表_dgv.Size.Height)
  64. 控制表_dgv.Columns(7).FillWeight = 20
  65. 控制表_dgv.Columns(0).FillWeight = 20
  66. End If
  67. End Sub
  68. Private Sub 控制表_dgv_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles 控制表_dgv.CellClick
  69. If e.RowIndex = -1 Then : Else
  70. 單號_tb.Text = 控制表_dgv(0, e.RowIndex).Value.ToString
  71. Dim dateString As String = 控制表_dgv(1, e.RowIndex).Value.ToString
  72. Dim dateParts() As String = dateString.Split("/"c)
  73. Dim year As Integer = Integer.Parse(dateParts(0)) + 1911 ' 將民國年轉換為西元年
  74. Dim month As Integer = Integer.Parse(dateParts(1))
  75. Dim day As Integer = Integer.Parse(dateParts(2))
  76. Dim dateTime As New DateTime(year, month, day)
  77. 選擇日期_dtp.Value = dateTime
  78. 選擇日期_dtp.CustomFormat = "yyyy/MM/dd"
  79. 選擇日期_dtp.Format = DateTimePickerFormat.Custom
  80. 承辦人_tb.Text = 控制表_dgv(2, e.RowIndex).Value.ToString
  81. 受文者_tb.Text = 控制表_dgv(3, e.RowIndex).Value.ToString
  82. 速別_tb.Text = 控制表_dgv(4, e.RowIndex).Value.ToString
  83. 密等_tb.Text = 控制表_dgv(5, e.RowIndex).Value.ToString
  84. 附件_tb.Text = 控制表_dgv(6, e.RowIndex).Value.ToString
  85. 主旨_tb.Text = 控制表_dgv(7, e.RowIndex).Value.ToString
  86. 說明_tb.Text = 控制表_dgv(8, e.RowIndex).Value.ToString
  87. 說明_rtb.Text = 控制表_dgv(8, e.RowIndex).Value.ToString
  88. 正本_tb.Text = 控制表_dgv(9, e.RowIndex).Value.ToString
  89. 副本_tb.Text = 控制表_dgv(10, e.RowIndex).Value.ToString
  90. 手機_tb.Text = 控制表_dgv(13, e.RowIndex).Value.ToString
  91. 標題_tb.Text = 控制表_dgv(14, e.RowIndex).Value.ToString
  92. If 登入人級別 <> "00" Then
  93. If 控制表_dgv(12, e.RowIndex).Value = True Then
  94. 刪除_bt.Enabled = False : 儲存_bt.Enabled = False : 作廢_bt.Enabled = False : 列印_bt.Enabled = True : 新增_bt.Enabled = True
  95. ElseIf 控制表_dgv(11, e.RowIndex).Value = True And 控制表_dgv(12, e.RowIndex).Value = False Then
  96. 刪除_bt.Enabled = False : 儲存_bt.Enabled = False : 作廢_bt.Enabled = True : 列印_bt.Enabled = True : 新增_bt.Enabled = True
  97. ElseIf 控制表_dgv(11, e.RowIndex).Value = False And 控制表_dgv(12, e.RowIndex).Value = False Then
  98. 刪除_bt.Enabled = True : 儲存_bt.Enabled = True : 作廢_bt.Enabled = True : 列印_bt.Enabled = True : 新增_bt.Enabled = True
  99. End If
  100. Else
  101. 刪除_bt.Enabled = True : 儲存_bt.Enabled = True : 作廢_bt.Enabled = True : 列印_bt.Enabled = True : 新增_bt.Enabled = True
  102. End If
  103. End If
  104. End Sub
  105. Private Sub 複製_bt_Click(sender As Object, e As EventArgs) Handles 複製_bt.Click
  106. 刪除_bt.Enabled = True : 儲存_bt.Enabled = True : 作廢_bt.Enabled = False : 列印_bt.Enabled = False : 新增_bt.Enabled = False
  107. 受文者_tb.Text = "" : 正本_tb.Text = ""
  108. Dim NUM1 As Integer
  109. Dim selectedDate As DateTime = 選擇日期_dtp.Value
  110. Dim taiwanYear As Integer = selectedDate.Year - 1911
  111. Dim str As String = String.Format("{0}{1:00}{2:00}", taiwanYear, selectedDate.Month, selectedDate.Day)
  112. PA1 = String.Format("{0}/{1:00}/{2:00}", taiwanYear, selectedDate.Month, selectedDate.Day)
  113. For i As Integer = 1 To 999
  114. NUM1 = 0 + i
  115. If NUM1 < 10 Then : 單號_tb.Text = str & "0" & NUM1
  116. ElseIf NUM1 > 9 Then : 單號_tb.Text = str & NUM1
  117. End If
  118. conn.Close()
  119. PA = 單號_tb.Text
  120. SQL_公函_查詢第一筆單號()
  121. If dr.Read() Then : Else : i = 999 : conn.Close() : End If : conn.Close()
  122. Next
  123. PA = 單號_tb.Text
  124. SQL_公函_新增一筆公函控制表() : conn.Close()
  125. End Sub
  126. Private Sub 新增_bt_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click
  127. 單號_tb.Text = "" : 承辦人_tb.Text = gUserName : 手機_tb.Text = "" : 受文者_tb.Text = ""
  128. 速別_tb.Text = "" : 密等_tb.Text = "" : 主旨_tb.Text = "" : 說明_tb.Text = "" : 說明_rtb.Text = ""
  129. 正本_tb.Text = "" : 副本_tb.Text = "" : 附件_tb.Text = "" : 標題_tb.Text = 公司名稱.Text & "管理委員會"
  130. Dim NUM1 As Integer
  131. Dim selectedDate As DateTime = 選擇日期_dtp.Value
  132. Dim taiwanYear As Integer = selectedDate.Year - 1911
  133. Dim str As String = String.Format("{0}{1:00}{2:00}", taiwanYear, selectedDate.Month, selectedDate.Day)
  134. PA1 = String.Format("{0}/{1:00}/{2:00}", taiwanYear, selectedDate.Month, selectedDate.Day)
  135. For i As Integer = 1 To 999
  136. NUM1 = 0 + i
  137. If NUM1 < 10 Then : 單號_tb.Text = str & "0" & NUM1
  138. ElseIf NUM1 > 9 Then : 單號_tb.Text = str & NUM1
  139. End If
  140. conn.Close()
  141. PA = 單號_tb.Text
  142. SQL_公函_查詢第一筆單號()
  143. If dr.Read() Then : Else : i = 999 : conn.Close() : End If : conn.Close()
  144. Next
  145. PA = 單號_tb.Text
  146. SQL_公函_新增一筆公函控制表() : conn.Close()
  147. 刪除_bt.Enabled = True : 儲存_bt.Enabled = True : 作廢_bt.Enabled = False : 列印_bt.Enabled = False : 新增_bt.Enabled = False
  148. End Sub
  149. Private Sub 刪除_bt_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click
  150. SQL_公函_控制表刪除() : conn.Close() : MsgBox("刪除成功!!")
  151. 單號_tb.Text = "" : 承辦人_tb.Text = "" : 手機_tb.Text = "" : 受文者_tb.Text = ""
  152. 速別_tb.Text = "" : 密等_tb.Text = "" : 主旨_tb.Text = "" : 說明_tb.Text = "" : 說明_rtb.Text = ""
  153. 正本_tb.Text = "" : 副本_tb.Text = "" : 附件_tb.Text = "" : Set_清單1()
  154. If 登入人級別 <> "00" Then
  155. 刪除_bt.Enabled = False : 儲存_bt.Enabled = False : 作廢_bt.Enabled = False : 列印_bt.Enabled = False : 新增_bt.Enabled = True
  156. End If
  157. End Sub
  158. Private Sub 儲存_bt_Click(sender As Object, e As EventArgs) Handles 儲存_bt.Click
  159. If 承辦人_tb.Text = gUserName Or 登入人級別 = "00" Then
  160. Dim selectedDate As DateTime = 選擇日期_dtp.Value
  161. Dim taiwanYear As Integer = selectedDate.Year - 1911
  162. PA1 = String.Format("{0}/{1:00}/{2:00}", taiwanYear, selectedDate.Month, selectedDate.Day)
  163. SQL_公函_控制表修改() : conn.Close() : MsgBox("儲存成功!!") : Set_清單1()
  164. If 登入人級別 <> "00" Then
  165. 刪除_bt.Enabled = True : 儲存_bt.Enabled = True : 作廢_bt.Enabled = True : 列印_bt.Enabled = True : 新增_bt.Enabled = True
  166. End If
  167. Else
  168. MsgBox("請確認開單人是否為本人")
  169. End If
  170. End Sub
  171. Private Sub 作廢_bt_Click(sender As Object, e As EventArgs) Handles 作廢_bt.Click
  172. SQL_公函_控制表作廢() : conn.Close() : MsgBox("作廢成功!!") : Set_清單1()
  173. If 登入人級別 <> "00" Then
  174. 刪除_bt.Enabled = False : 儲存_bt.Enabled = False : 作廢_bt.Enabled = False : 列印_bt.Enabled = True : 新增_bt.Enabled = True
  175. End If
  176. End Sub
  177. Private Sub 作廢的營運成本收支單_rb_CheckedChanged(sender As Object, e As EventArgs) Handles 作廢的營運成本收支單_rb.Click
  178. 作廢的營運成本收支單_rb.Checked = True : 已核准的營運成本收支單_rb.Checked = False
  179. Set_清單1()
  180. End Sub
  181. Private Sub 已核准的營運成本收支單_rb_CheckedChanged(sender As Object, e As EventArgs) Handles 已核准的營運成本收支單_rb.Click
  182. 作廢的營運成本收支單_rb.Checked = False : 已核准的營運成本收支單_rb.Checked = True
  183. Set_清單1()
  184. End Sub
  185. Private Sub 字體_NUD_ValueChanged(sender As Object, e As EventArgs) Handles 字體_NUD.ValueChanged
  186. 受文者_tb.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
  187. 速別_tb.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
  188. 密等_tb.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
  189. 主旨_tb.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
  190. 說明_tb.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
  191. 說明_rtb.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
  192. 正本_tb.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
  193. 副本_tb.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
  194. 附件_tb.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
  195. End Sub
  196. Private Sub 查詢_tb_Click(sender As Object, e As EventArgs) Handles 查詢_tb.Click
  197. PA56 = InputBox("請輸入要查詢的單號資料。") : Set_清單1() : PA56 = ""
  198. End Sub
  199. Private Sub 複製_bt_MouseEnter(sender As Object, e As EventArgs) Handles 複製_bt.MouseEnter
  200. ToolTip1.SetToolTip(Me.複製_bt, "複製文件")
  201. End Sub
  202. Private Sub 確縮放_tb_MouseEnter(sender As Object, e As EventArgs) Handles 縮放_tb.MouseEnter
  203. ToolTip1.SetToolTip(Me.縮放_tb, "主旨縮放")
  204. End Sub
  205. Private Sub 查詢_tb_MouseEnter(sender As Object, e As EventArgs) Handles 查詢_tb.MouseEnter
  206. ToolTip1.SetToolTip(Me.查詢_tb, "關鍵字搜尋")
  207. End Sub
  208. Private Sub 新增_bt_MouseEnter(sender As Object, e As EventArgs) Handles 新增_bt.MouseEnter
  209. ToolTip1.SetToolTip(Me.新增_bt, "新增")
  210. End Sub
  211. Private Sub 確認新增_bt_MouseEnter(sender As Object, e As EventArgs) Handles 儲存_bt.MouseEnter
  212. ToolTip1.SetToolTip(Me.儲存_bt, "儲存")
  213. End Sub
  214. Private Sub 修改_bt_MouseEnter(sender As Object, e As EventArgs) Handles 作廢_bt.MouseEnter
  215. ToolTip1.SetToolTip(Me.作廢_bt, "作廢")
  216. End Sub
  217. Private Sub 刪除_bt_MouseEnter(sender As Object, e As EventArgs) Handles 刪除_bt.MouseEnter
  218. ToolTip1.SetToolTip(Me.刪除_bt, "刪除")
  219. End Sub
  220. Private Sub 匯出EXCEL_bt_MouseEnter(sender As Object, e As EventArgs) Handles 列印_bt.MouseEnter
  221. ToolTip1.SetToolTip(Me.列印_bt, "匯出PDF")
  222. End Sub
  223. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  224. QRCode2_pb.Image = Nothing
  225. QRCode2_pb.Image = New Bitmap(QRCode2_pb.Width, QRCode2_pb.Height)
  226. Dim GP2 As Graphics = Graphics.FromImage(QRCode2_pb.Image)
  227. QRCODE.Type = DotNetBarcode.Types.QRCode : QRCODE.QRQuitZone = 0 : QRCODE.QRWriteBar("http://106.1.48.106:8080/ICS-SCADA-SYS/index2.html", 1, 1, 2.5, GP2)
  228. QRCode2_pb.SizeMode = 4
  229. Dim printDocument As New PrintDocument()
  230. AddHandler printDocument.PrintPage, AddressOf PrintPageHandler
  231. Dim printDialog As New PrintDialog()
  232. printDialog.Document = printDocument
  233. If printDialog.ShowDialog() = DialogResult.OK Then
  234. printDocument.Print()
  235. End If
  236. End Sub
  237. Private Sub PrintPageHandler(sender As Object, e As PrintPageEventArgs)
  238. ' 在這個事件處理程序中,你可以使用 e.Graphics 繪製要列印的內容
  239. Dim graphics As Graphics = e.Graphics
  240. Dim newFont As New System.Drawing.Font("標楷體", 18)
  241. Dim brush As New SolidBrush(Color.Black)
  242. 'Dim printText As String = "光明燈"
  243. 'Dim printText1 As String = "伍佰元整"
  244. 'Dim printText2 As String = "王詩文"
  245. Dim printText3 As String = "王詩文"
  246. Dim printText4 As String = "王詩文"
  247. Dim printText5 As String = "112"
  248. Dim printText6 As String = "10"
  249. Dim printText7 As String = "08"
  250. Dim newFont1 As New System.Drawing.Font("標楷體", 14)
  251. 'Dim newFont1 As New System.Drawing.Font("標楷體", 18)
  252. Dim printText As String = "明細如下"
  253. Dim printText1 As String = "玖仟玖佰元整"
  254. Dim printText2 As String = "王詩文(闔家人等)"
  255. Dim printText31 As String = "光明燈*3"
  256. Dim printText41 As String = "太歲燈*3"
  257. Dim printText51 As String = "智慧燈*3"
  258. Dim printText61 As String = "財利燈*3"
  259. Dim printText71 As String = "姻緣燈*3"
  260. Dim printText81 As String = "延壽燈*3"
  261. Dim printText91 As String = "解厄燈*3"
  262. graphics.DrawString(printText, newFont, brush, 370, 75)
  263. graphics.DrawString(printText2, newFont, brush, 0, 230)
  264. graphics.DrawString(printText31, newFont1, brush, 0, 275)
  265. graphics.DrawString(printText41, newFont1, brush, 0, 300)
  266. graphics.DrawString(printText51, newFont1, brush, 0, 325)
  267. graphics.DrawString(printText61, newFont1, brush, 0, 350)
  268. graphics.DrawString(printText71, newFont1, brush, 0, 375)
  269. graphics.DrawString(printText81, newFont1, brush, 0, 400)
  270. graphics.DrawString(printText91, newFont1, brush, 0, 425)
  271. 'graphics.DrawString(printText, newFont, brush, 375, 75)
  272. graphics.DrawString(printText1, newFont, brush, 70, 125)
  273. 'graphics.DrawString(printText2, newFont, brush, 70, 230)
  274. graphics.DrawString(printText3, newFont, brush, 380, 380)
  275. graphics.DrawString(printText4, newFont, brush, 350, 430)
  276. graphics.DrawString(printText5, newFont, brush, 140, 485)
  277. graphics.DrawString(printText6, newFont, brush, 300, 485)
  278. graphics.DrawString(printText7, newFont, brush, 440, 485)
  279. Dim qrCodeImage As Image = QRCode2_pb.Image
  280. ' 將QR Code 圖片繪製到指定位置
  281. graphics.DrawImage(qrCodeImage, 520, 5)
  282. e.HasMorePages = False ' 如果有多頁要列印,設置為 True
  283. End Sub
  284. Private Sub 列印_bt_Click(sender As Object, e As EventArgs) Handles 列印_bt.Click
  285. SQL_公函_控制表鎖定() : conn.Close()
  286. If 登入人級別 <> "00" Then
  287. 刪除_bt.Enabled = False : 儲存_bt.Enabled = False : 作廢_bt.Enabled = True : 列印_bt.Enabled = True : 新增_bt.Enabled = True
  288. End If
  289. Set_清單1()
  290. xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
  291. xlApp.Visible = True
  292. xlApp.DisplayAlerts = True
  293. xlApp.Application.WindowState = xlMaximized
  294. xlBook = xlApp.Workbooks.Add
  295. xlSheet = NewMethod(xlBook)
  296. xlBook.Activate()
  297. xlSheet.Activate()
  298. xlSheet.Cells(1, 1) = 標題_tb.Text & " 函"
  299. xlSheet.Cells(2, 7) = "機關地址:" : xlSheet.Cells(2, 8) = 地址.Text
  300. xlSheet.Cells(3, 7) = "電 話:" : xlSheet.Cells(3, 8) = 電話.Text : xlSheet.Cells(3, 9) = "傳 真:" : xlSheet.Cells(3, 10) = 傳真.Text
  301. xlSheet.Cells(4, 7) = "承 辦 人:" : xlSheet.Cells(4, 8) = 承辦人_tb.Text
  302. If 手機_tb.Text <> "" Then
  303. xlSheet.Cells(4, 9) = "手 機:" : xlSheet.Cells(4, 10) = "'" & 手機_tb.Text
  304. End If
  305. xlSheet.Cells(5, 1) = "受文者:" : xlSheet.Cells(5, 5) = 受文者_tb.Text : xlSheet.Cells(5, 11) = 受文者_tb.Text
  306. Dim selectedDate As DateTime = 選擇日期_dtp.Value
  307. Dim taiwanYear As Integer = selectedDate.Year - 1911
  308. xlSheet.Cells(6, 1) = "發文日期:" : xlSheet.Cells(6, 4) = "中華民國" & taiwanYear & "年" & selectedDate.Month & "月" & selectedDate.Day & "日"
  309. xlSheet.Cells(7, 1) = "發文字號:" : xlSheet.Cells(7, 4) = 簡稱.Text & "字第 " & 單號_tb.Text & " 號"
  310. xlSheet.Cells(8, 1) = "速別:" : xlSheet.Cells(8, 2) = 速別_tb.Text : xlSheet.Cells(8, 11) = 速別_tb.Text
  311. xlSheet.Cells(9, 1) = "密等及解密條件:" : xlSheet.Cells(9, 6) = 密等_tb.Text : xlSheet.Cells(9, 11) = 密等_tb.Text
  312. xlSheet.Cells(10, 1) = "附件:" : xlSheet.Cells(10, 2) = 附件_tb.Text : xlSheet.Cells(10, 11) = 附件_tb.Text
  313. xlSheet.Cells(11, 1) = "主旨:" : xlSheet.Cells(11, 3) = 主旨_tb.Text : xlSheet.Cells(11, 11) = 主旨_tb.Text
  314. If 說明_rtb.Text <> "" Then
  315. Dim lines As New List(Of String)()
  316. Dim text As String = 說明_rtb.Text
  317. lines.Clear()
  318. ' 使用 Graphics.MeasureString 测量文本的宽度
  319. Using g As Graphics = CreateGraphics()
  320. Dim currentLine As String = ""
  321. For Each c As Char In text
  322. If c = ControlChars.Lf Then
  323. ' 如果遇到换行符号,添加一个新的段落
  324. lines.Add(currentLine)
  325. currentLine = ""
  326. Else
  327. currentLine += c
  328. ' 计算当前行的宽度
  329. Dim width As Integer = TextRenderer.MeasureText(currentLine, 說明_rtb.Font).Width
  330. ' 当宽度接近 RichTextBox 的宽度时,添加一个分段符号
  331. If width >= 450 Then
  332. lines.Add(currentLine)
  333. currentLine = ""
  334. End If
  335. End If
  336. Next
  337. ' 如果最后一行没有被添加,添加它
  338. If currentLine <> "" Then
  339. lines.Add(currentLine)
  340. End If
  341. End Using
  342. For i As Integer = 0 To lines.Count - 1
  343. 字串處理(lines(i))
  344. lines(i) = 已處理字串
  345. Next
  346. xlSheet.Cells(12, 1) = "說明:"
  347. 'For i = 0 To lines.Length - 1
  348. ' xlSheet.Cells(12 + i, 3) = lines(i) : xlSheet.Cells(12 + i, 11) = lines(i) & vbLf
  349. ' N2 = i + 12
  350. 'Next
  351. For i = 0 To lines.Count - 1
  352. xlSheet.Cells(12 + i, 3) = lines(i) : xlSheet.Cells(12 + i, 11) = lines(i)
  353. N2 = i + 12
  354. Next
  355. xlSheet.Cells(N2 + 1, 1) = "正本:" : xlSheet.Cells(N2 + 1, 2) = 正本_tb.Text : xlSheet.Cells(N2 + 1, 11) = 正本_tb.Text
  356. xlSheet.Cells(N2 + 2, 1) = "副本:" : xlSheet.Cells(N2 + 2, 2) = 副本_tb.Text : xlSheet.Cells(N2 + 2, 11) = 副本_tb.Text
  357. Else
  358. xlSheet.Cells(12, 1) = "正本:" : xlSheet.Cells(12, 2) = 正本_tb.Text : xlSheet.Cells(12, 11) = 正本_tb.Text
  359. xlSheet.Cells(13, 1) = "副本:" : xlSheet.Cells(13, 2) = 副本_tb.Text : xlSheet.Cells(13, 11) = 副本_tb.Text
  360. End If
  361. BB(xlApp, xlSheet)
  362. xlApp.Sheets(2).Delete : xlSheet.PageSetup.PrintArea = ""
  363. '----轉成PDF-----
  364. Dim pdfFolderPath As String = Path.Combine(System.Windows.Forms.Application.StartupPath, "pdf")
  365. If Not Directory.Exists(pdfFolderPath) Then
  366. Directory.CreateDirectory(pdfFolderPath)
  367. End If
  368. Dim pdfFilePath As String = Path.Combine(pdfFolderPath, 單號_tb.Text & "-公函.pdf")
  369. xlBook.Sheets(1).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, pdfFilePath, XlFixedFormatQuality.xlQualityStandard, True)
  370. xlApp.Cells.Select() : xlApp.Application.WindowState = xlMinimized : xlBook.Close(False)
  371. Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
  372. Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
  373. Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
  374. xlApp.Quit() : xlSheet = Nothing : xlBook = Nothing : xlApp = Nothing : GC.Collect()
  375. Try
  376. Dim chromePath As String = "C:\Program Files\Google\Chrome\Application\chrome.exe"
  377. If System.IO.File.Exists(chromePath) Then
  378. Dim process As New Process()
  379. process.StartInfo.FileName = "chrome"
  380. process.StartInfo.Arguments = """" & pdfFilePath & """"
  381. process.Start()
  382. Else : Dim edgePath As String = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
  383. If System.IO.File.Exists(edgePath) Then
  384. Dim process As New Process()
  385. process.StartInfo.FileName = "msedge"
  386. process.StartInfo.Arguments = """" & pdfFilePath & """"
  387. process.Start()
  388. Else
  389. Process.Start(pdfFilePath)
  390. End If
  391. End If
  392. Catch ex As Exception
  393. MsgBox("以存檔至桌面 。" & vbCrLf & "檔案名稱:" & 單號_tb.Text & "-公函.pdf")
  394. End Try
  395. End Sub
  396. Private Sub BB(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
  397. xlSheet.Rows("1:1").Select
  398. With myExcel.Selection.Font
  399. .Name = "標楷體"
  400. .Size = 18
  401. .Strikethrough = False
  402. .Superscript = False
  403. .Subscript = False
  404. .OutlineFont = False
  405. .Shadow = False
  406. .Underline = xlUnderlineStyleNone
  407. .ThemeColor = xlThemeColorLight1
  408. .TintAndShade = 0
  409. .ThemeFont = xlThemeFontNone
  410. End With
  411. xlSheet.Range("2:4").Select()
  412. With myExcel.Selection.Font
  413. .Name = "標楷體"
  414. .Size = 10
  415. .Strikethrough = False
  416. .Superscript = False
  417. .Subscript = False
  418. .OutlineFont = False
  419. .Shadow = False
  420. .Underline = xlUnderlineStyleNone
  421. .ThemeColor = xlThemeColorLight1
  422. .TintAndShade = 0
  423. .ThemeFont = xlThemeFontNone
  424. End With
  425. If 說明_rtb.Text <> "" Then
  426. xlSheet.Range("6:10," & N2 + 1 & ":" & N2 + 2).Select()
  427. With myExcel.Selection.Font
  428. .Name = "標楷體"
  429. .Size = 12
  430. .Strikethrough = False
  431. .Superscript = False
  432. .Subscript = False
  433. .OutlineFont = False
  434. .Shadow = False
  435. .Underline = xlUnderlineStyleNone
  436. .ThemeColor = xlThemeColorLight1
  437. .TintAndShade = 0
  438. .ThemeFont = xlThemeFontNone
  439. End With
  440. xlSheet.Range("5:5,11:" & N2).Select()
  441. With myExcel.Selection.Font
  442. .Name = "標楷體"
  443. .Size = 16
  444. .Strikethrough = False
  445. .Superscript = False
  446. .Subscript = False
  447. .OutlineFont = False
  448. .Shadow = False
  449. .Underline = xlUnderlineStyleNone
  450. .ThemeColor = xlThemeColorLight1
  451. .TintAndShade = 0
  452. .ThemeFont = xlThemeFontNone
  453. End With
  454. Else
  455. xlSheet.Range("6:10,12:13").Select()
  456. With myExcel.Selection.Font
  457. .Name = "標楷體"
  458. .Size = 12
  459. .Strikethrough = False
  460. .Superscript = False
  461. .Subscript = False
  462. .OutlineFont = False
  463. .Shadow = False
  464. .Underline = xlUnderlineStyleNone
  465. .ThemeColor = xlThemeColorLight1
  466. .TintAndShade = 0
  467. .ThemeFont = xlThemeFontNone
  468. End With
  469. xlSheet.Range("5:5,11:11").Select()
  470. With myExcel.Selection.Font
  471. .Name = "標楷體"
  472. .Size = 16
  473. .Strikethrough = False
  474. .Superscript = False
  475. .Subscript = False
  476. .OutlineFont = False
  477. .Shadow = False
  478. .Underline = xlUnderlineStyleNone
  479. .ThemeColor = xlThemeColorLight1
  480. .TintAndShade = 0
  481. .ThemeFont = xlThemeFontNone
  482. End With
  483. End If
  484. xlSheet.Columns("A:A").ColumnWidth = 5.5
  485. xlSheet.Columns("B:B").ColumnWidth = 1.5
  486. xlSheet.Columns("C:C").ColumnWidth = 2
  487. xlSheet.Columns("D:D").ColumnWidth = 0.38
  488. xlSheet.Columns("E:E").ColumnWidth = 5
  489. xlSheet.Columns("F:F").ColumnWidth = 41.5
  490. xlSheet.Columns("G:G").ColumnWidth = 8
  491. xlSheet.Columns("H:H").ColumnWidth = 10
  492. xlSheet.Columns("I:I").ColumnWidth = 8
  493. xlSheet.Columns("J:J").ColumnWidth = 10
  494. xlSheet.Range("A1:J1").Select()
  495. With myExcel.Selection
  496. .HorizontalAlignment = xlCenter
  497. .VerticalAlignment = xlCenter
  498. .WrapText = False
  499. .Orientation = 0
  500. .AddIndent = False
  501. .IndentLevel = 0
  502. .ShrinkToFit = False
  503. .ReadingOrder = xlContext
  504. .MergeCells = False
  505. End With
  506. myExcel.Selection.Merge
  507. xlSheet.Range("H2:J2").Select()
  508. With myExcel.Selection
  509. .HorizontalAlignment = xlLeft
  510. .VerticalAlignment = xlCenter
  511. .WrapText = False
  512. .Orientation = 0
  513. .AddIndent = False
  514. .IndentLevel = 0
  515. .ShrinkToFit = False
  516. .ReadingOrder = xlContext
  517. .MergeCells = False
  518. End With
  519. myExcel.Selection.Merge
  520. xlSheet.Range("G2,G3:J4").Select()
  521. With myExcel.Selection
  522. .HorizontalAlignment = xlLeft
  523. .VerticalAlignment = xlCenter
  524. .WrapText = False
  525. .Orientation = 0
  526. .AddIndent = False
  527. .IndentLevel = 0
  528. .ShrinkToFit = False
  529. .ReadingOrder = xlContext
  530. .MergeCells = False
  531. End With
  532. xlSheet.Range("A5:D5").Select()
  533. With myExcel.Selection
  534. .HorizontalAlignment = xlLeft
  535. .VerticalAlignment = xlTop
  536. .WrapText = False
  537. .Orientation = 0
  538. .AddIndent = False
  539. .IndentLevel = 0
  540. .ShrinkToFit = False
  541. .ReadingOrder = xlContext
  542. .MergeCells = False
  543. End With
  544. myExcel.Selection.Merge
  545. xlSheet.Range("E5:J5").Select()
  546. With myExcel.Selection
  547. .HorizontalAlignment = xlLeft
  548. .VerticalAlignment = xlTop
  549. .WrapText = True
  550. .Orientation = 0
  551. .AddIndent = False
  552. .IndentLevel = 0
  553. .ShrinkToFit = False
  554. .ReadingOrder = xlContext
  555. .MergeCells = False
  556. End With
  557. myExcel.Selection.Merge
  558. xlSheet.Range("A6:C6").Select()
  559. With myExcel.Selection
  560. .HorizontalAlignment = xlLeft
  561. .VerticalAlignment = xlTop
  562. .WrapText = False
  563. .Orientation = 0
  564. .AddIndent = False
  565. .IndentLevel = 0
  566. .ShrinkToFit = False
  567. .ReadingOrder = xlContext
  568. .MergeCells = False
  569. End With
  570. myExcel.Selection.Merge
  571. xlSheet.Range("D6:J6").Select()
  572. With myExcel.Selection
  573. .HorizontalAlignment = xlLeft
  574. .VerticalAlignment = xlTop
  575. .WrapText = True
  576. .Orientation = 0
  577. .AddIndent = False
  578. .IndentLevel = 0
  579. .ShrinkToFit = False
  580. .ReadingOrder = xlContext
  581. .MergeCells = False
  582. End With
  583. myExcel.Selection.Merge
  584. xlSheet.Range("A7:C7").Select()
  585. With myExcel.Selection
  586. .HorizontalAlignment = xlLeft
  587. .VerticalAlignment = xlTop
  588. .WrapText = False
  589. .Orientation = 0
  590. .AddIndent = False
  591. .IndentLevel = 0
  592. .ShrinkToFit = False
  593. .ReadingOrder = xlContext
  594. .MergeCells = False
  595. End With
  596. myExcel.Selection.Merge
  597. xlSheet.Range("D7:J7").Select()
  598. With myExcel.Selection
  599. .HorizontalAlignment = xlLeft
  600. .VerticalAlignment = xlTop
  601. .WrapText = True
  602. .Orientation = 0
  603. .AddIndent = False
  604. .IndentLevel = 0
  605. .ShrinkToFit = False
  606. .ReadingOrder = xlContext
  607. .MergeCells = False
  608. End With
  609. myExcel.Selection.Merge
  610. xlSheet.Range("A8").Select()
  611. With myExcel.Selection
  612. .HorizontalAlignment = xlLeft
  613. .VerticalAlignment = xlTop
  614. .WrapText = False
  615. .Orientation = 0
  616. .AddIndent = False
  617. .IndentLevel = 0
  618. .ShrinkToFit = False
  619. .ReadingOrder = xlContext
  620. .MergeCells = False
  621. End With
  622. xlSheet.Range("B8:J8").Select()
  623. With myExcel.Selection
  624. .HorizontalAlignment = xlLeft
  625. .VerticalAlignment = xlTop
  626. .WrapText = True
  627. .Orientation = 0
  628. .AddIndent = False
  629. .IndentLevel = 0
  630. .ShrinkToFit = False
  631. .ReadingOrder = xlContext
  632. .MergeCells = False
  633. End With
  634. myExcel.Selection.Merge
  635. xlSheet.Range("A9:E9").Select()
  636. With myExcel.Selection
  637. .HorizontalAlignment = xlLeft
  638. .VerticalAlignment = xlTop
  639. .WrapText = False
  640. .Orientation = 0
  641. .AddIndent = False
  642. .IndentLevel = 0
  643. .ShrinkToFit = False
  644. .ReadingOrder = xlContext
  645. .MergeCells = False
  646. End With
  647. myExcel.Selection.Merge
  648. xlSheet.Range("F9:J9").Select()
  649. With myExcel.Selection
  650. .HorizontalAlignment = xlLeft
  651. .VerticalAlignment = xlTop
  652. .WrapText = True
  653. .Orientation = 0
  654. .AddIndent = False
  655. .IndentLevel = 0
  656. .ShrinkToFit = False
  657. .ReadingOrder = xlContext
  658. .MergeCells = False
  659. End With
  660. myExcel.Selection.Merge
  661. xlSheet.Range("A10").Select()
  662. With myExcel.Selection
  663. .HorizontalAlignment = xlLeft
  664. .VerticalAlignment = xlTop
  665. .WrapText = False
  666. .Orientation = 0
  667. .AddIndent = False
  668. .IndentLevel = 0
  669. .ShrinkToFit = False
  670. .ReadingOrder = xlContext
  671. .MergeCells = False
  672. End With
  673. xlSheet.Range("B10:J10").Select()
  674. With myExcel.Selection
  675. .HorizontalAlignment = xlLeft
  676. .VerticalAlignment = xlTop
  677. .WrapText = True
  678. .Orientation = 0
  679. .AddIndent = False
  680. .IndentLevel = 0
  681. .ShrinkToFit = False
  682. .ReadingOrder = xlContext
  683. .MergeCells = False
  684. End With
  685. myExcel.Selection.Merge
  686. xlSheet.Range("A11:B11").Select()
  687. With myExcel.Selection
  688. .HorizontalAlignment = xlLeft
  689. .VerticalAlignment = xlTop
  690. .WrapText = False
  691. .Orientation = 0
  692. .AddIndent = False
  693. .IndentLevel = 0
  694. .ShrinkToFit = False
  695. .ReadingOrder = xlContext
  696. .MergeCells = False
  697. End With
  698. myExcel.Selection.Merge
  699. xlSheet.Range("C11:J11").Select()
  700. With myExcel.Selection
  701. .HorizontalAlignment = xlLeft
  702. .VerticalAlignment = xlTop
  703. .WrapText = True
  704. .Orientation = 0
  705. .AddIndent = False
  706. .IndentLevel = 0
  707. .ShrinkToFit = False
  708. .ReadingOrder = xlContext
  709. .MergeCells = False
  710. End With
  711. myExcel.Selection.Merge
  712. If 說明_rtb.Text <> "" Then
  713. xlSheet.Range("A12:B12").Select()
  714. With myExcel.Selection
  715. .HorizontalAlignment = xlLeft
  716. .VerticalAlignment = xlTop
  717. .WrapText = False
  718. .Orientation = 0
  719. .AddIndent = False
  720. .IndentLevel = 0
  721. .ShrinkToFit = False
  722. .ReadingOrder = xlContext
  723. .MergeCells = False
  724. End With
  725. myExcel.Selection.Merge
  726. For i = 12 To N2
  727. xlSheet.Range("C" & i & ":J" & i).Select()
  728. With myExcel.Selection
  729. .HorizontalAlignment = xlLeft
  730. .VerticalAlignment = xlTop
  731. .WrapText = True
  732. .Orientation = 0
  733. .AddIndent = False
  734. .IndentLevel = 0
  735. .ShrinkToFit = False
  736. .ReadingOrder = xlContext
  737. .MergeCells = False
  738. End With
  739. myExcel.Selection.Merge
  740. Next
  741. xlSheet.Range("A" & N2 + 1).Select()
  742. With myExcel.Selection
  743. .HorizontalAlignment = xlLeft
  744. .VerticalAlignment = xlTop
  745. .WrapText = False
  746. .Orientation = 0
  747. .AddIndent = False
  748. .IndentLevel = 0
  749. .ShrinkToFit = False
  750. .ReadingOrder = xlContext
  751. .MergeCells = False
  752. End With
  753. myExcel.Selection.Merge
  754. xlSheet.Range("B" & N2 + 1 & ":J" & N2 + 1).Select()
  755. With myExcel.Selection
  756. .HorizontalAlignment = xlLeft
  757. .VerticalAlignment = xlTop
  758. .WrapText = True
  759. .Orientation = 0
  760. .AddIndent = False
  761. .IndentLevel = 0
  762. .ShrinkToFit = False
  763. .ReadingOrder = xlContext
  764. .MergeCells = False
  765. End With
  766. myExcel.Selection.Merge
  767. xlSheet.Range("A" & N2 + 2).Select()
  768. With myExcel.Selection
  769. .HorizontalAlignment = xlLeft
  770. .VerticalAlignment = xlTop
  771. .WrapText = False
  772. .Orientation = 0
  773. .AddIndent = False
  774. .IndentLevel = 0
  775. .ShrinkToFit = False
  776. .ReadingOrder = xlContext
  777. .MergeCells = False
  778. End With
  779. myExcel.Selection.Merge
  780. xlSheet.Range("B" & N2 + 2 & ":J" & N2 + 2).Select()
  781. With myExcel.Selection
  782. .HorizontalAlignment = xlLeft
  783. .VerticalAlignment = xlTop
  784. .WrapText = True
  785. .Orientation = 0
  786. .AddIndent = False
  787. .IndentLevel = 0
  788. .ShrinkToFit = False
  789. .ReadingOrder = xlContext
  790. .MergeCells = False
  791. End With
  792. myExcel.Selection.Merge
  793. Else
  794. xlSheet.Range("A12").Select()
  795. With myExcel.Selection
  796. .HorizontalAlignment = xlLeft
  797. .VerticalAlignment = xlTop
  798. .WrapText = False
  799. .Orientation = 0
  800. .AddIndent = False
  801. .IndentLevel = 0
  802. .ShrinkToFit = False
  803. .ReadingOrder = xlContext
  804. .MergeCells = False
  805. End With
  806. myExcel.Selection.Merge
  807. xlSheet.Range("B12:J12").Select()
  808. With myExcel.Selection
  809. .HorizontalAlignment = xlLeft
  810. .VerticalAlignment = xlTop
  811. .WrapText = True
  812. .Orientation = 0
  813. .AddIndent = False
  814. .IndentLevel = 0
  815. .ShrinkToFit = False
  816. .ReadingOrder = xlContext
  817. .MergeCells = False
  818. End With
  819. myExcel.Selection.Merge
  820. xlSheet.Range("A13").Select()
  821. With myExcel.Selection
  822. .HorizontalAlignment = xlLeft
  823. .VerticalAlignment = xlTop
  824. .WrapText = False
  825. .Orientation = 0
  826. .AddIndent = False
  827. .IndentLevel = 0
  828. .ShrinkToFit = False
  829. .ReadingOrder = xlContext
  830. .MergeCells = False
  831. End With
  832. myExcel.Selection.Merge
  833. xlSheet.Range("B13:J13").Select()
  834. With myExcel.Selection
  835. .HorizontalAlignment = xlLeft
  836. .VerticalAlignment = xlTop
  837. .WrapText = True
  838. .Orientation = 0
  839. .AddIndent = False
  840. .IndentLevel = 0
  841. .ShrinkToFit = False
  842. .ReadingOrder = xlContext
  843. .MergeCells = False
  844. End With
  845. myExcel.Selection.Merge
  846. End If
  847. xlSheet.Columns("K:K").Select
  848. With myExcel.Selection
  849. .HorizontalAlignment = xlLeft
  850. .VerticalAlignment = xlTop
  851. .WrapText = True
  852. .Orientation = 0
  853. .AddIndent = False
  854. .IndentLevel = 0
  855. .ShrinkToFit = False
  856. .ReadingOrder = xlContext
  857. .MergeCells = False
  858. End With
  859. xlSheet.Columns("K:K").ColumnWidth = 75.63
  860. xlSheet.Rows("5:5").Select
  861. xlSheet.Rows("5:5").EntireRow.AutoFit
  862. xlSheet.Columns("K:K").ColumnWidth = 70
  863. xlSheet.Rows("9:9").Select
  864. xlSheet.Rows("9:9").EntireRow.AutoFit
  865. xlSheet.Columns("K:K").ColumnWidth = 81
  866. xlSheet.Rows("8:8").Select
  867. xlSheet.Rows("8:8").EntireRow.AutoFit
  868. xlSheet.Rows("10:10").Select
  869. xlSheet.Rows("10:10").EntireRow.AutoFit
  870. If 說明_rtb.Text <> "" Then
  871. xlSheet.Rows(N2 + 1 & ":" & N2 + 1).Select
  872. xlSheet.Rows(N2 + 1 & ":" & N2 + 1).EntireRow.AutoFit
  873. xlSheet.Rows(N2 + 2 & ":" & N2 + 2).Select
  874. xlSheet.Rows(N2 + 2 & ":" & N2 + 2).EntireRow.AutoFit
  875. 'xlSheet.Columns("K:K").ColumnWidth = 73.8
  876. xlSheet.Columns("K:K").ColumnWidth = 88.8
  877. For i = 11 To N2
  878. xlSheet.Rows(i & ":" & i).Select
  879. xlSheet.Rows(i & ":" & i).EntireRow.AutoFit
  880. Next
  881. Else
  882. xlSheet.Rows("12:12").Select
  883. xlSheet.Rows("12:12").EntireRow.AutoFit
  884. xlSheet.Rows("13:13").Select
  885. xlSheet.Rows("13:13").EntireRow.AutoFit
  886. xlSheet.Columns("K:K").ColumnWidth = 88.8
  887. xlSheet.Rows("11:11").Select
  888. xlSheet.Rows("11:11").EntireRow.AutoFit
  889. End If
  890. xlSheet.Rows("6:6").Select
  891. xlSheet.Rows("6:6").EntireRow.AutoFit
  892. xlSheet.Rows("7:7").Select
  893. xlSheet.Rows("7:7").EntireRow.AutoFit
  894. xlSheet.Columns("K:K").Select
  895. myExcel.Selection.EntireColumn.Hidden = True
  896. For i = 1 To N2 + 2
  897. If xlSheet.Rows(i).RowHeight < 400 Then
  898. If i = 10 Or i = 11 Or i = N2 Then
  899. xlSheet.Rows(i).RowHeight = xlSheet.Rows(i).RowHeight + 8
  900. Else
  901. xlSheet.Rows(i).RowHeight = xlSheet.Rows(i).RowHeight + 5
  902. End If
  903. End If
  904. Next i
  905. myExcel.Application.PrintCommunication = False
  906. With myExcel.ActiveSheet.PageSetup
  907. .PrintTitleRows = ""
  908. .PrintTitleColumns = ""
  909. End With
  910. myExcel.Application.PrintCommunication = True
  911. myExcel.ActiveSheet.PageSetup.PrintArea = ""
  912. myExcel.Application.PrintCommunication = False
  913. With myExcel.ActiveSheet.PageSetup
  914. .LeftHeader = ""
  915. .CenterHeader = ""
  916. .RightHeader = ""
  917. .LeftFooter = ""
  918. .CenterFooter = ""
  919. .RightFooter = ""
  920. .LeftMargin = myExcel.Application.InchesToPoints(0.25)
  921. .RightMargin = myExcel.Application.InchesToPoints(0.25)
  922. .TopMargin = myExcel.Application.InchesToPoints(0.75)
  923. .BottomMargin = myExcel.Application.InchesToPoints(0.75)
  924. .HeaderMargin = myExcel.Application.InchesToPoints(0.3)
  925. .FooterMargin = myExcel.Application.InchesToPoints(0.3)
  926. .PrintHeadings = False
  927. .PrintGridlines = False
  928. .CenterHorizontally = False
  929. .CenterVertically = False
  930. .Draft = False
  931. .FirstPageNumber = xlAutomatic
  932. .BlackAndWhite = False
  933. .Zoom = False
  934. .FitToPagesWide = 1
  935. .FitToPagesTall = 0
  936. .OddAndEvenPagesHeaderFooter = False
  937. .DifferentFirstPageHeaderFooter = False
  938. .ScaleWithDocHeaderFooter = True
  939. .AlignMarginsHeaderFooter = True
  940. .EvenPage.LeftHeader.Text = ""
  941. .EvenPage.CenterHeader.Text = ""
  942. .EvenPage.RightHeader.Text = ""
  943. .EvenPage.LeftFooter.Text = ""
  944. .EvenPage.CenterFooter.Text = ""
  945. .EvenPage.RightFooter.Text = ""
  946. .FirstPage.LeftHeader.Text = ""
  947. .FirstPage.CenterHeader.Text = ""
  948. .FirstPage.RightHeader.Text = ""
  949. .FirstPage.LeftFooter.Text = ""
  950. .FirstPage.CenterFooter.Text = ""
  951. .FirstPage.RightFooter.Text = ""
  952. End With
  953. myExcel.Application.PrintCommunication = True
  954. End Sub
  955. Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet
  956. Return CType(xlBook.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet)
  957. End Function
  958. End Class