설명 없음
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 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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. Imports Telerik.Windows.Documents.Fixed
  13. Imports System.Text.RegularExpressions
  14. Imports Telerik.WinControls.VirtualKeyboard
  15. Public Class 文件
  16. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  17. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  18. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  19. Dim 位置1 As String : Dim 已處理字串 As String
  20. Dim N2 As Integer : Dim N3 As Integer
  21. ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet : ReadOnly ds2 As New DataSet
  22. Private Sub 文件_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  23. 'Me.MdiParent = GRAMS_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  24. conn.Close()
  25. 已核准的營運成本收支單_rb.Checked = True
  26. 作廢的營運成本收支單_rb.Checked = False
  27. Set_清單1() : Set_清單3()
  28. 刪除_bt.Enabled = False : 儲存_bt.Enabled = False : 作廢_bt.Enabled = False : 列印_bt.Enabled = False : 發行_bt.Enabled = False : 指定人員_bt.Enabled = False
  29. End Sub
  30. Private Sub Set_清單3()
  31. Dim ds As New DataSet
  32. 人員1_dgv.DataSource = Nothing : ds.Clear()
  33. 人員1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  34. 人員1_dgv.ColumnHeadersHeight = 25
  35. 人員1_dgv.AllowUserToAddRows = False
  36. SQL_通用_人員清單()
  37. da.Fill(ds) : 人員1_dgv.DataSource = ds.Tables(0) : conn.Close()
  38. Dim chkColumn As New DataGridViewCheckBoxColumn()
  39. End Sub
  40. Private Sub Set_清單1()
  41. 控制表_dgv.DataSource = Nothing : ds1.Clear()
  42. 控制表_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  43. 控制表_dgv.ColumnHeadersHeight = 25
  44. 控制表_dgv.AllowUserToAddRows = False
  45. 控制表_dgv.RowTemplate.Height = 30
  46. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  47. If 作廢的營運成本收支單_rb.Checked = True And 已核准的營運成本收支單_rb.Checked = False And 已發行的營運成本收支單_rb.Checked = False Then
  48. SQL_通用_控制表清單1()
  49. ElseIf 作廢的營運成本收支單_rb.Checked = False And 已核准的營運成本收支單_rb.Checked = True And 已發行的營運成本收支單_rb.Checked = False Then
  50. SQL_通用_控制表清單()
  51. ElseIf 作廢的營運成本收支單_rb.Checked = False And 已核准的營運成本收支單_rb.Checked = False And 已發行的營運成本收支單_rb.Checked = True Then
  52. SQL_通用_控制表清單2()
  53. End If
  54. da.Fill(ds1) : 控制表_dgv.DataSource = ds1.Tables(0) : conn.Close()
  55. 控制表_dgv.Columns(0).FillWeight = 20 : 控制表_dgv.Columns(1).FillWeight = 60 : 控制表_dgv.Columns(2).Visible = False
  56. 控制表_dgv.Columns(3).Visible = False : 控制表_dgv.Columns(4).Visible = False : 控制表_dgv.Columns(5).Visible = False
  57. 控制表_dgv.Columns(6).Visible = False : 控制表_dgv.Columns(7).Visible = False : 控制表_dgv.Columns(8).FillWeight = 20
  58. 控制表_dgv.Columns(9).Visible = False
  59. End Sub
  60. Private Sub Set_清單2()
  61. 人員_dgv.DataSource = Nothing : ds2.Clear()
  62. 人員_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  63. 人員_dgv.ColumnHeadersHeight = 25
  64. 人員_dgv.AllowUserToAddRows = False
  65. 人員_dgv.RowTemplate.Height = 50
  66. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  67. SQL_通用_明細表讀取()
  68. da.Fill(ds2) : 人員_dgv.DataSource = ds2.Tables(0) : conn.Close()
  69. 人員_dgv.Columns(0).Visible = False : 人員_dgv.Columns(1).FillWeight = 20 : 人員_dgv.Columns(2).Visible = False
  70. 人員_dgv.Columns(3).Visible = False : 人員_dgv.Columns(4).FillWeight = 50 : 人員_dgv.Columns(5).FillWeight = 30
  71. Dim imgColumn As DataGridViewImageColumn = TryCast(人員_dgv.Columns("圖片"), DataGridViewImageColumn)
  72. If imgColumn IsNot Nothing Then
  73. imgColumn.ImageLayout = DataGridViewImageCellLayout.Zoom
  74. End If
  75. Dim transparentImage As New Bitmap(50, 50) ' Adjust size as needed
  76. Using g As Graphics = Graphics.FromImage(transparentImage)
  77. g.Clear(Color.Transparent)
  78. End Using
  79. For i As Integer = 0 To 人員_dgv.Rows.Count - 1
  80. If 人員_dgv.Rows(i).Cells("圖片資料庫").Value.ToString <> "" And 人員_dgv.Rows(i).Cells("圖片流水號").Value.ToString <> "" Then
  81. 圖片庫 = 人員_dgv.Rows(i).Cells("圖片資料庫").Value.ToString
  82. SQL_連線字串_圖片資料庫()
  83. PA2 = 人員_dgv.Rows(i).Cells("圖片流水號").Value.ToString
  84. SQL_簽名圖()
  85. While dr.Read() = True
  86. Dim unused As Byte() = New Byte(-1) {} : Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte())
  87. Dim oStream As New MemoryStream(bytes) : 人員_dgv.Rows(i).Cells("圖片").Value = Bitmap.FromStream(oStream)
  88. End While : conn.Close()
  89. Else
  90. ' Set empty value if no image is available
  91. 人員_dgv.Rows(i).Cells("圖片").Value = transparentImage
  92. End If
  93. Next
  94. End Sub
  95. Private Sub 控制表_dgv_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles 控制表_dgv.CellClick
  96. If e.RowIndex = -1 Then : Else
  97. 單號_tb.Text = 控制表_dgv(2, e.RowIndex).Value.ToString
  98. Dim dateString As String = 控制表_dgv(0, e.RowIndex).Value.ToString
  99. Dim dateParts() As String = dateString.Split("/"c)
  100. Dim year As Integer = Integer.Parse(dateParts(0)) + 1911 ' 將民國年轉換為西元年
  101. Dim month As Integer = Integer.Parse(dateParts(1))
  102. Dim day As Integer = Integer.Parse(dateParts(2))
  103. Dim dateTime As New DateTime(year, month, day)
  104. 選擇日期_dtp.Value = dateTime
  105. 選擇日期_dtp.CustomFormat = "yyyy/MM/dd"
  106. 選擇日期_dtp.Format = DateTimePickerFormat.Custom
  107. 檔案名稱_tb.Text = 控制表_dgv(1, e.RowIndex).Value.ToString
  108. 主旨_tb.Text = 控制表_dgv(3, e.RowIndex).Value.ToString
  109. 說明_tb.Text = 控制表_dgv(4, e.RowIndex).Value.ToString
  110. 開單人_tb.Text = 控制表_dgv("開單人", e.RowIndex).Value.ToString
  111. 全選_cb.Checked = 控制表_dgv("全選", e.RowIndex).Value
  112. PA57 = 單號_tb.Text
  113. Set_清單2()
  114. If (全選_cb.Checked = True) Then
  115. For I As Integer = 0 To 人員1_dgv.Rows.Count - 1
  116. Dim skip As Boolean = False ' 用于标记是否跳过当前外层循环
  117. For II As Integer = 0 To 人員_dgv.Rows.Count - 1
  118. If 人員1_dgv.Rows(I).Cells("姓名").Value.ToString() = 人員_dgv.Rows(II).Cells("姓名").Value.ToString() Then
  119. skip = True ' 标记跳过当前外层循环
  120. Exit For ' 跳出内层循环
  121. End If
  122. Next
  123. If skip Then
  124. Continue For ' 跳过当前外层循环的当前迭代
  125. End If
  126. PA58 = 人員1_dgv.Rows(I).Cells("姓名").Value.ToString()
  127. SQL_通用_明細表新增()
  128. Next
  129. Set_清單2()
  130. End If
  131. 刪除_bt.Enabled = True : 儲存_bt.Enabled = True : 作廢_bt.Enabled = True : 列印_bt.Enabled = True : 發行_bt.Enabled = True : 指定人員_bt.Enabled = True
  132. End If
  133. End Sub
  134. Private Sub 查詢_tb_Click(sender As Object, e As EventArgs) Handles 查詢_tb.Click
  135. PA56 = InputBox("請輸入要查詢的單號資料。") : Set_清單1() : PA56 = ""
  136. End Sub
  137. Private Sub 檔案名稱_tb_KeyPress(sender As Object, e As KeyPressEventArgs) Handles 檔案名稱_tb.KeyPress
  138. ' 允许字母、数字和空格,禁止其他字符
  139. If Not Char.IsLetterOrDigit(e.KeyChar) AndAlso Not Char.IsWhiteSpace(e.KeyChar) Then
  140. e.Handled = True
  141. End If
  142. End Sub
  143. Private Sub 新增_bt_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click
  144. 單號_tb.Text = "" : 檔案名稱_tb.Text = "" : 主旨_tb.Text = "" : 說明_tb.Text = "" : 開單人_tb.Text = gUserName
  145. Dim NUM1 As Integer
  146. Dim dat1 As String
  147. Dim selectedDate As DateTime = 選擇日期_dtp.Value
  148. Dim taiwanYear As Integer = selectedDate.Year - 1911
  149. Dim str As String = String.Format("{0}{1:00}{2:00}", taiwanYear, selectedDate.Month, selectedDate.Day)
  150. PA1 = String.Format("{0}/{1:00}/{2:00}", taiwanYear, selectedDate.Month, selectedDate.Day)
  151. SQL_通用_查詢第一筆單號()
  152. If dr.Read() Then : 單號_tb.Text = dr("流水號").ToString : Else : 單號_tb.Text = str & "00" : End If
  153. dat1 = 單號_tb.Text.Substring(0, 7)
  154. If dat1 <> str Then : NUM1 = 1 : Else : NUM1 = Double.Parse(單號_tb.Text.Substring(7, 2)) + 1 : End If
  155. If NUM1 < 10 Then : 單號_tb.Text = str & "0" & NUM1
  156. ElseIf NUM1 > 9 Then : 單號_tb.Text = str & NUM1
  157. End If
  158. PA = 單號_tb.Text
  159. SQL_通用_新增一筆公函控制表() : conn.Close()
  160. PA57 = "" : Set_清單2()
  161. 刪除_bt.Enabled = True : 儲存_bt.Enabled = True : 作廢_bt.Enabled = True : 列印_bt.Enabled = True : 發行_bt.Enabled = True : 指定人員_bt.Enabled = True
  162. 'ComboBox1.SelectedIndex = 2
  163. 'ComboBox2.SelectedIndex = 3
  164. 'ComboBox3.SelectedIndex = 7
  165. 'ComboBox4.SelectedIndex = 8
  166. End Sub
  167. Private Sub 刪除_bt_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click
  168. PA57 = 單號_tb.Text : SQL_通用_明細表刪除()
  169. SQL_通用_控制表刪除(單號_tb.Text) : conn.Close() : MsgBox("刪除成功!!")
  170. 單號_tb.Text = "" : 檔案名稱_tb.Text = "" : 主旨_tb.Text = "" : 說明_tb.Text = "" : 開單人_tb.Text = ""
  171. Set_清單1() : Set_清單2()
  172. 刪除_bt.Enabled = False : 儲存_bt.Enabled = False : 作廢_bt.Enabled = False : 列印_bt.Enabled = False : 發行_bt.Enabled = False : 指定人員_bt.Enabled = False
  173. End Sub
  174. Private Sub 儲存_bt_Click(sender As Object, e As EventArgs) Handles 儲存_bt.Click
  175. PA57 = 單號_tb.Text
  176. If (全選_cb.Checked = True) Then
  177. If 人員1_dgv.Rows.Count < 1 Then
  178. For I As Integer = 0 To 人員1_dgv.Rows.Count - 1
  179. PA58 = 人員1_dgv.Rows(I).Cells("姓名").Value.ToString()
  180. SQL_通用_明細表新增()
  181. Next
  182. Else
  183. For I As Integer = 0 To 人員1_dgv.Rows.Count - 1
  184. Dim skip As Boolean = False ' 用于标记是否跳过当前外层循环
  185. For II As Integer = 0 To 人員_dgv.Rows.Count - 1
  186. If 人員1_dgv.Rows(I).Cells("姓名").Value.ToString() = 人員_dgv.Rows(II).Cells("姓名").Value.ToString() Then
  187. skip = True ' 标记跳过当前外层循环
  188. Exit For ' 跳出内层循环
  189. End If
  190. Next
  191. If skip Then
  192. Continue For ' 跳过当前外层循环的当前迭代
  193. End If
  194. PA58 = 人員1_dgv.Rows(I).Cells("姓名").Value.ToString()
  195. SQL_通用_明細表新增()
  196. Next
  197. End If
  198. End If
  199. SQL_通用_控制表修改(檔案名稱_tb.Text, 主旨_tb.Text, 說明_tb.Text, 單號_tb.Text, 全選_cb.Checked) : conn.Close() : MsgBox("儲存成功!!") : Set_清單1() : Set_清單2()
  200. 'If 開單人_tb.Text = gUserName Or 登入人級別 = "00" Then
  201. ' SQL_通用_控制表修改(檔案名稱_tb.Text, 主旨_tb.Text, 說明_rtb.Text, 單號_tb.Text) : conn.Close() : MsgBox("儲存成功!!") : Set_清單1()
  202. ' If 登入人級別 <> "00" Then
  203. ' 刪除_bt.Enabled = True : 儲存_bt.Enabled = True : 作廢_bt.Enabled = True : 列印_bt.Enabled = True : 新增_bt.Enabled = True
  204. ' End If
  205. 'Else
  206. ' MsgBox("請確認開單人是否為本人")
  207. 'End If
  208. End Sub
  209. Private Sub 發行_bt_Click(sender As Object, e As EventArgs) Handles 發行_bt.Click
  210. SQL_通用_控制表發行(單號_tb.Text) : conn.Close() : MsgBox("發行成功!!") : Set_清單1()
  211. End Sub
  212. Private Sub 作廢_bt_Click(sender As Object, e As EventArgs) Handles 作廢_bt.Click
  213. SQL_通用_控制表作廢(單號_tb.Text) : conn.Close() : MsgBox("作廢成功!!") : Set_清單1()
  214. End Sub
  215. Private Sub 編輯人員_bt_Click(sender As Object, e As EventArgs) Handles 指定人員_bt.Click
  216. 全選_cb.Checked = False
  217. PA57 = 單號_tb.Text : 選擇人員.ShowDialog() : Set_清單2()
  218. End Sub
  219. Private Sub 作廢的營運成本收支單_rb_CheckedChanged(sender As Object, e As EventArgs) Handles 作廢的營運成本收支單_rb.Click
  220. 作廢的營運成本收支單_rb.Checked = True : 已核准的營運成本收支單_rb.Checked = False : 已發行的營運成本收支單_rb.Checked = False
  221. Set_清單1()
  222. End Sub
  223. Private Sub 已核准的營運成本收支單_rb_CheckedChanged(sender As Object, e As EventArgs) Handles 已核准的營運成本收支單_rb.Click
  224. 作廢的營運成本收支單_rb.Checked = False : 已核准的營運成本收支單_rb.Checked = True : 已發行的營運成本收支單_rb.Checked = False
  225. Set_清單1()
  226. End Sub
  227. Private Sub 已發行的營運成本收支單_rb_CheckedChanged(sender As Object, e As EventArgs) Handles 已發行的營運成本收支單_rb.Click
  228. 作廢的營運成本收支單_rb.Checked = False : 已核准的營運成本收支單_rb.Checked = False : 已發行的營運成本收支單_rb.Checked = True
  229. Set_清單1()
  230. End Sub
  231. Private Sub 查詢_tb_MouseEnter(sender As Object, e As EventArgs) Handles 查詢_tb.MouseEnter
  232. ToolTip1.SetToolTip(Me.查詢_tb, "關鍵字搜尋")
  233. End Sub
  234. Private Sub 新增_bt_MouseEnter(sender As Object, e As EventArgs) Handles 新增_bt.MouseEnter
  235. ToolTip1.SetToolTip(Me.新增_bt, "新增")
  236. End Sub
  237. Private Sub 確認新增_bt_MouseEnter(sender As Object, e As EventArgs) Handles 儲存_bt.MouseEnter
  238. ToolTip1.SetToolTip(Me.儲存_bt, "儲存")
  239. End Sub
  240. Private Sub 發行_bt_MouseEnter(sender As Object, e As EventArgs) Handles 發行_bt.MouseEnter
  241. ToolTip1.SetToolTip(Me.發行_bt, "發行")
  242. End Sub
  243. Private Sub 修改_bt_MouseEnter(sender As Object, e As EventArgs) Handles 作廢_bt.MouseEnter
  244. ToolTip1.SetToolTip(Me.作廢_bt, "作廢")
  245. End Sub
  246. Private Sub 刪除_bt_MouseEnter(sender As Object, e As EventArgs) Handles 刪除_bt.MouseEnter
  247. ToolTip1.SetToolTip(Me.刪除_bt, "刪除")
  248. End Sub
  249. Private Sub 匯出EXCEL_bt_MouseEnter(sender As Object, e As EventArgs) Handles 列印_bt.MouseEnter
  250. ToolTip1.SetToolTip(Me.列印_bt, "匯出PDF")
  251. End Sub
  252. Private Sub 字體_NUD_ValueChanged(sender As Object, e As EventArgs) Handles 字體_NUD.ValueChanged
  253. 主旨_tb.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
  254. 說明_tb.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
  255. End Sub
  256. Private Sub 列印_bt_Click(sender As Object, e As EventArgs) Handles 列印_bt.Click
  257. 'If 登入人級別 <> "00" Then
  258. ' 刪除_bt.Enabled = False : 儲存_bt.Enabled = False : 作廢_bt.Enabled = True : 列印_bt.Enabled = True : 新增_bt.Enabled = True
  259. 'End If
  260. Set_清單1()
  261. xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application) : xlApp.Visible = True : xlApp.DisplayAlerts = True
  262. xlApp.Application.WindowState = xlMaximized : xlBook = xlApp.Workbooks.Add : xlSheet = NewMethod(xlBook) : xlBook.Activate() : xlSheet.Activate()
  263. xlSheet.Cells(1, 1) = "黃柏翰皮膚科診所"
  264. xlSheet.Cells(2, 1) = 主旨_tb.Text
  265. Dim largeText As String = 說明_tb.Text
  266. ' 使用正则表达式去除多余的换行符
  267. Dim cleanedText As String = Regex.Replace(largeText, "(\r\n|\r|\n)+", vbCrLf)
  268. ' 现在根据换行符拆分文本
  269. Dim lines() As String = cleanedText.Split(New String() {vbCrLf}, StringSplitOptions.None)
  270. For i As Integer = 0 To lines.Count - 1
  271. 字串處理(lines(i))
  272. lines(i) = 已處理字串
  273. Next
  274. For i = 0 To Lines.Count - 1
  275. xlSheet.Cells(3 + i, 1) = lines(i)
  276. N2 = i + 3
  277. Next
  278. BB(xlApp, xlSheet)
  279. xlApp.Sheets(2).Delete : xlSheet.PageSetup.PrintArea = ""
  280. Dim pdfFolderPath As String = Path.Combine(System.Windows.Forms.Application.StartupPath, "pdf")
  281. If Not Directory.Exists(pdfFolderPath) Then
  282. Directory.CreateDirectory(pdfFolderPath)
  283. End If
  284. Dim pdfFilePath As String = Path.Combine(pdfFolderPath, 檔案名稱_tb.Text & ".pdf")
  285. xlBook.Sheets(1).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, pdfFilePath, XlFixedFormatQuality.xlQualityStandard, True)
  286. xlApp.Cells.Select() : xlApp.Application.WindowState = xlMinimized : xlBook.Close(False)
  287. Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
  288. Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
  289. Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
  290. xlApp.Quit() : xlSheet = Nothing : xlBook = Nothing : xlApp = Nothing : GC.Collect()
  291. Try
  292. Dim chromePath As String = "C:\Program Files\Google\Chrome\Application\chrome.exe"
  293. If System.IO.File.Exists(chromePath) Then
  294. Dim process As New Process()
  295. process.StartInfo.FileName = "chrome"
  296. process.StartInfo.Arguments = """" & pdfFilePath & """"
  297. process.Start()
  298. Else : Dim edgePath As String = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
  299. If System.IO.File.Exists(edgePath) Then
  300. Dim process As New Process()
  301. process.StartInfo.FileName = "msedge"
  302. process.StartInfo.Arguments = """" & pdfFilePath & """"
  303. process.Start()
  304. Else
  305. Process.Start(pdfFilePath)
  306. End If
  307. End If
  308. Catch ex As Exception
  309. MsgBox("以存檔至桌面 。" & vbCrLf & "檔案名稱:" & 檔案名稱_tb.Text & ".pdf")
  310. End Try
  311. End Sub
  312. Public Sub 字串處理(ByVal 說明1 As String)
  313. Dim 前面空白數量 As Integer = 0
  314. While Strings.Right(說明1, 1) = " " : 說明1 = 說明1.Substring(0, 說明1.Length - 1) : End While
  315. While 說明1.StartsWith(" ") : 說明1 = 說明1.Substring(1) : 前面空白數量 += 1 : End While
  316. If 說明1.Contains(" ") Then
  317. Dim 空白數量() As String = 說明1.Split(" ") : Dim 中間空白數量 As Integer = 1
  318. For j As Integer = 0 To 空白數量.Length - 1 : If 空白數量(j) = "" Then : 中間空白數量 += 1 : End If : Next
  319. Dim 要去除的空白數量 As Integer = 中間空白數量 \ 2 : Dim 已去除的數量 As Integer = 0 : Dim 除2字串 As String = ""
  320. For i As Integer = 0 To 空白數量.Length - 1
  321. If 空白數量(i) = "" Then : If 已去除的數量 < 要去除的空白數量 Then : 已去除的數量 += 1 : Else : 除2字串 &= " " : End If : Else : 除2字串 &= 空白數量(i) : End If
  322. Next : 說明1 = 除2字串
  323. End If
  324. If 前面空白數量 > 0 Then : Dim 要增加的空白數量 As Integer = 前面空白數量 \ 2 : For i As Integer = 0 To 要增加的空白數量 - 1 : 說明1 = " " & 說明1 : Next : End If
  325. 已處理字串 = 說明1
  326. End Sub
  327. Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet
  328. Return CType(xlBook.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet)
  329. End Function
  330. Private Sub BB(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
  331. xlSheet.Activate() ' 激活工作表
  332. myExcel.ActiveWindow.View = XlWindowView.xlPageLayoutView
  333. myExcel.Application.PrintCommunication = False
  334. With myExcel.ActiveSheet.PageSetup
  335. .PrintTitleRows = ""
  336. .PrintTitleColumns = ""
  337. End With
  338. myExcel.Application.PrintCommunication = True
  339. myExcel.ActiveSheet.PageSetup.PrintArea = ""
  340. myExcel.Application.PrintCommunication = False
  341. With myExcel.ActiveSheet.PageSetup
  342. .LeftHeader = ""
  343. .CenterHeader = ""
  344. .RightHeader = ""
  345. .LeftFooter = ""
  346. .CenterFooter = ""
  347. .RightFooter = ""
  348. .LeftMargin = myExcel.Application.InchesToPoints(0.7)
  349. .RightMargin = myExcel.Application.InchesToPoints(0.7)
  350. .TopMargin = myExcel.Application.InchesToPoints(0.3)
  351. .BottomMargin = myExcel.Application.InchesToPoints(0.3)
  352. .HeaderMargin = myExcel.Application.InchesToPoints(0.3)
  353. .FooterMargin = myExcel.Application.InchesToPoints(0.3)
  354. .PrintHeadings = False
  355. .PrintGridlines = False
  356. .CenterHorizontally = True
  357. .CenterVertically = False
  358. .Draft = False
  359. .FirstPageNumber = xlAutomatic
  360. .BlackAndWhite = False
  361. .Zoom = False
  362. .FitToPagesWide = 0
  363. .FitToPagesTall = 0
  364. .OddAndEvenPagesHeaderFooter = False
  365. .DifferentFirstPageHeaderFooter = False
  366. .ScaleWithDocHeaderFooter = True
  367. .AlignMarginsHeaderFooter = True
  368. .EvenPage.LeftHeader.Text = ""
  369. .EvenPage.CenterHeader.Text = ""
  370. .EvenPage.RightHeader.Text = ""
  371. .EvenPage.LeftFooter.Text = ""
  372. .EvenPage.CenterFooter.Text = ""
  373. .EvenPage.RightFooter.Text = ""
  374. .FirstPage.LeftHeader.Text = ""
  375. .FirstPage.CenterHeader.Text = ""
  376. .FirstPage.RightHeader.Text = ""
  377. .FirstPage.LeftFooter.Text = ""
  378. .FirstPage.CenterFooter.Text = ""
  379. .FirstPage.RightFooter.Text = ""
  380. End With
  381. myExcel.Application.PrintCommunication = True
  382. xlSheet.Cells.Select()
  383. With myExcel.Selection.Font
  384. .Name = "微軟正黑體"
  385. .Size = 14
  386. .Strikethrough = False
  387. .Superscript = False
  388. .Subscript = False
  389. .OutlineFont = False
  390. .Shadow = False
  391. .Underline = xlUnderlineStyleNone
  392. .ThemeColor = xlThemeColorLight1
  393. .TintAndShade = 0
  394. .ThemeFont = xlThemeFontNone
  395. End With
  396. xlSheet.Columns("A:A").ColumnWidth = 80
  397. xlSheet.Columns("A:A").Select
  398. With myExcel.Selection
  399. .HorizontalAlignment = xlGeneral
  400. .VerticalAlignment = xlCenter
  401. .WrapText = True
  402. .Orientation = 0
  403. .AddIndent = False
  404. .IndentLevel = 0
  405. .ShrinkToFit = False
  406. .ReadingOrder = xlContext
  407. .MergeCells = False
  408. End With
  409. xlSheet.Range("A1").Select()
  410. With myExcel.Selection
  411. .HorizontalAlignment = xlCenter
  412. .VerticalAlignment = xlCenter
  413. .WrapText = True
  414. .Orientation = 0
  415. .AddIndent = False
  416. .IndentLevel = 0
  417. .ShrinkToFit = False
  418. .ReadingOrder = xlContext
  419. .MergeCells = False
  420. End With
  421. With myExcel.Selection.Font
  422. .Name = "微軟正黑體"
  423. .Size = 20
  424. .Strikethrough = False
  425. .Superscript = False
  426. .Subscript = False
  427. .OutlineFont = False
  428. .Shadow = False
  429. .Underline = xlUnderlineStyleNone
  430. .ThemeColor = xlThemeColorLight1
  431. .TintAndShade = 0
  432. .ThemeFont = xlThemeFontNone
  433. .Bold = True
  434. End With
  435. xlSheet.Range("A2").Select()
  436. With myExcel.Selection
  437. .HorizontalAlignment = xlCenter
  438. .VerticalAlignment = xlCenter
  439. .WrapText = True
  440. .Orientation = 0
  441. .AddIndent = False
  442. .IndentLevel = 0
  443. .ShrinkToFit = False
  444. .ReadingOrder = xlContext
  445. .MergeCells = False
  446. End With
  447. With myExcel.Selection.Font
  448. .Name = "微軟正黑體"
  449. .Size = 18
  450. .Strikethrough = False
  451. .Superscript = False
  452. .Subscript = False
  453. .OutlineFont = False
  454. .Shadow = False
  455. .Underline = xlUnderlineStyleNone
  456. .ThemeColor = xlThemeColorLight1
  457. .TintAndShade = 0
  458. .ThemeFont = xlThemeFontNone
  459. .Bold = True
  460. End With
  461. xlSheet.Rows("1:1").EntireRow.AutoFit
  462. xlSheet.Rows(1).RowHeight = xlSheet.Rows(1).RowHeight + 5
  463. xlSheet.Rows("2:2").EntireRow.AutoFit
  464. xlSheet.Rows(2).RowHeight = xlSheet.Rows(1).RowHeight + 5
  465. For i = 3 To N2
  466. xlSheet.Rows(i & ":" & i).Select
  467. xlSheet.Rows(i & ":" & i).EntireRow.AutoFit
  468. If xlSheet.Rows(i).RowHeight + 5 > 409 Then
  469. xlSheet.Rows(i).RowHeight = 409
  470. Else
  471. xlSheet.Rows(i).RowHeight = xlSheet.Rows(i).RowHeight + 5
  472. End If
  473. Next
  474. End Sub
  475. End Class