Option Strict Off Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle Imports Microsoft.Office.Interop.Excel.Constants Imports Microsoft.Office.Interop.Excel.XlBordersIndex Imports Microsoft.Office.Interop.Excel.XlLineStyle Imports Microsoft.Office.Interop.Excel.XlBorderWeight Imports Microsoft.Office.Interop.Excel.XlThemeFont Imports Microsoft.Office.Interop.Excel.XlThemeColor Imports Microsoft.Office.Interop.Excel.XlWindowState Imports Microsoft.Office.Interop.Excel Imports System.IO Imports System.Data.SqlClient Public Class 財務_收支單一覽表 ReadOnly ds, ds1, ds2, ds3, ds4, ds5, ds6 As New DataSet Dim DTP, 單據日期, 原日期字串 As String : Dim N1 As Integer : Dim N2 As Integer Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet Dim boo, boo1 As Boolean Private Sub Set_清單() 日期彙總_dgv.DataSource = Nothing : ds3.Clear() 日期彙總_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 日期彙總_dgv.ColumnHeadersHeight = 25 : 日期彙總_dgv.AllowUserToAddRows = False : 日期彙總_dgv.RowTemplate.Height = 25 If 公司編號_cb.Text = "全部" Or 公司編號_cb.Text = "" Then : PA51 = "" : Else : PA51 = " AND (公司編號 LIKE N'" & 公司編號_cb.Text & "')" : End If SQL_營運成本收支單一覽表_查詢清單純日期() : da.Fill(ds3) : 日期彙總_dgv.DataSource = ds3.Tables(0) : conn.Close() 日期彙總_dgv.Columns(0).FillWeight = 100 : 日期彙總_dgv.Columns(0).ReadOnly = True End Sub Private Sub Set_清單1() 單據彙總_dgv.DataSource = Nothing : ds1.Clear() 單據彙總_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 單據彙總_dgv.ColumnHeadersHeight = 25 單據彙總_dgv.AllowUserToAddRows = False If 公司編號_cb.Text = "全部" Or 公司編號_cb.Text = "" Then : PA51 = "" : Else : PA51 = " AND (公司編號 LIKE N'" & 公司編號_cb.Text & "')" : End If SQL_營運成本收支單一覽表_查詢清單() : da.Fill(ds1) : 單據彙總_dgv.DataSource = ds1.Tables(0) : conn.Close() 單據彙總_dgv.RowTemplate.Height = 25 單據彙總_dgv.Columns(0).FillWeight = 160 : 單據彙總_dgv.Columns(1).Visible = False : 單據彙總_dgv.Columns(2).FillWeight = 100 : 單據彙總_dgv.Columns(3).Visible = False 單據彙總_dgv.Columns(4).FillWeight = 100 : 單據彙總_dgv.Columns(5).Visible = False : 單據彙總_dgv.Columns(6).Visible = False End Sub Private Sub Set_清單2() 財務彙總_dgv.DataSource = Nothing : ds2.Clear() 財務彙總_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 財務彙總_dgv.ColumnHeadersHeight = 25 財務彙總_dgv.AllowUserToAddRows = False 財務彙總_dgv.RowTemplate.Height = 30 If 全部_ch.Checked = True And 含稅_ch.Checked = False And 非稅_ch.Checked = False Then SQL2 = "" ElseIf 全部_ch.Checked = False And 含稅_ch.Checked = True And 非稅_ch.Checked = False Then SQL2 = " AND (公帳流水帳.含稅 = 1)" ElseIf 全部_ch.Checked = False And 含稅_ch.Checked = False And 非稅_ch.Checked = True Then SQL2 = " AND (公帳流水帳.含稅 = 0 OR 公帳流水帳.含稅 IS NULL)" End If If 公司編號_cb.Text = "全部" Or 公司編號_cb.Text = "" Then : PA51 = "" : Else : PA51 = " AND (公帳控制表.公司編號 LIKE N'" & 公司編號_cb.Text & "')" : End If SQL_營運成本收支單一覽表_查詢清單2() : da.Fill(ds2) : 財務彙總_dgv.DataSource = ds2.Tables(0) : conn.Close() 財務彙總_dgv.Columns(0).Visible = False : 財務彙總_dgv.Columns(1).FillWeight = 140 : 財務彙總_dgv.Columns(2).FillWeight = 140 : 財務彙總_dgv.Columns(3).FillWeight = 140 財務彙總_dgv.Columns(4).FillWeight = 100 : 財務彙總_dgv.Columns(5).FillWeight = 100 : 財務彙總_dgv.Columns(6).FillWeight = 100 : 財務彙總_dgv.Columns(7).FillWeight = 100 財務彙總_dgv.Columns(8).FillWeight = 100 : 財務彙總_dgv.Columns(9).FillWeight = 100 財務彙總_dgv.Columns(4).Visible = False : 財務彙總_dgv.Columns(5).Visible = False If 彙總匯率_ch.Checked = False Then 財務彙總_dgv.Columns(8).Visible = False : 財務彙總_dgv.Columns(9).Visible = False Else 財務彙總_dgv.Columns(8).Visible = False : 財務彙總_dgv.Columns(9).Visible = False End If 財務彙總_dgv.Columns(6).DefaultCellStyle.Format = "#,##0" : 財務彙總_dgv.Columns(7).DefaultCellStyle.Format = "#,##0" : 財務彙總_dgv.Columns(4).DefaultCellStyle.Format = "#,##0" 財務彙總_dgv.Columns(5).DefaultCellStyle.Format = "#,##0" 財務彙總_dgv.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 財務彙總_dgv.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight 財務彙總_dgv.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 財務彙總_dgv.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight 財務彙總_dgv.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 財務彙總_dgv.Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight 財務彙總_dgv.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 財務彙總_dgv.Columns(5).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight 財務彙總_dgv.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter 財務彙總_dgv.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter 財務彙總_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter 財務彙總_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter For i As Integer = 0 To 財務彙總_dgv.Columns.Count - 1 : 財務彙總_dgv.Columns(i).ReadOnly = True : Next End Sub Private Sub Set_清單3() 財務彙總_天_dgv.DataSource = Nothing : ds4.Clear() 財務彙總_天_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 財務彙總_天_dgv.ColumnHeadersHeight = 25 財務彙總_天_dgv.AllowUserToAddRows = False 財務彙總_天_dgv.RowTemplate.Height = 30 If 全部_ch.Checked = True And 含稅_ch.Checked = False And 非稅_ch.Checked = False Then SQL2 = "" ElseIf 全部_ch.Checked = False And 含稅_ch.Checked = True And 非稅_ch.Checked = False Then SQL2 = " AND (公帳流水帳.含稅 = 1)" ElseIf 全部_ch.Checked = False And 含稅_ch.Checked = False And 非稅_ch.Checked = True Then SQL2 = " AND (公帳流水帳.含稅 = 0 OR 公帳流水帳.含稅 IS NULL)" End If If 公司編號_cb.Text = "全部" Or 公司編號_cb.Text = "" Then : PA51 = "" : Else : PA51 = " AND (公帳控制表.公司編號 LIKE N'" & 公司編號_cb.Text & "')" : End If SQL_營運成本收支單一覽表_查詢清單3() : da.Fill(ds4) : 財務彙總_天_dgv.DataSource = ds4.Tables(0) : conn.Close() 財務彙總_天_dgv.Columns(0).Visible = False : 財務彙總_天_dgv.Columns(1).FillWeight = 140 : 財務彙總_天_dgv.Columns(2).FillWeight = 140 : 財務彙總_天_dgv.Columns(3).FillWeight = 140 財務彙總_天_dgv.Columns(4).FillWeight = 100 : 財務彙總_天_dgv.Columns(5).FillWeight = 100 : 財務彙總_天_dgv.Columns(6).FillWeight = 100 : 財務彙總_天_dgv.Columns(7).FillWeight = 100 財務彙總_天_dgv.Columns(8).FillWeight = 100 : 財務彙總_天_dgv.Columns(9).FillWeight = 100 財務彙總_天_dgv.Columns(4).Visible = False : 財務彙總_天_dgv.Columns(5).Visible = False If 彙總匯率_ch.Checked = False Then 財務彙總_天_dgv.Columns(8).Visible = False : 財務彙總_天_dgv.Columns(9).Visible = False Else 財務彙總_天_dgv.Columns(8).Visible = False : 財務彙總_天_dgv.Columns(9).Visible = False End If 財務彙總_天_dgv.Columns(6).DefaultCellStyle.Format = "#,##0" : 財務彙總_天_dgv.Columns(7).DefaultCellStyle.Format = "#,##0" : 財務彙總_天_dgv.Columns(4).DefaultCellStyle.Format = "#,##0" 財務彙總_天_dgv.Columns(5).DefaultCellStyle.Format = "#,##0" 財務彙總_天_dgv.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 財務彙總_天_dgv.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight 財務彙總_天_dgv.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 財務彙總_天_dgv.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight 財務彙總_天_dgv.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 財務彙總_天_dgv.Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight 財務彙總_天_dgv.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 財務彙總_天_dgv.Columns(5).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight 財務彙總_天_dgv.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter 財務彙總_天_dgv.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter 財務彙總_天_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter 財務彙總_天_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter For i As Integer = 0 To 財務彙總_天_dgv.Columns.Count - 1 : 財務彙總_天_dgv.Columns(i).ReadOnly = True : Next End Sub ' 宣告全局變量 Dim dt As New System.Data.DataTable() Private Sub 初始化DataGridView() 明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 明細_dgv.ColumnHeadersHeight = 40 : 明細_dgv.AllowUserToAddRows = False : 明細_dgv.RowTemplate.Height = 35 dt.Clear() : 加載數據到DataTable() 明細_dgv.DataSource = dt End Sub Private Sub 加載數據到DataTable() If 全部_ch.Checked = True And 含稅_ch.Checked = False And 非稅_ch.Checked = False Then : SQL2 = "" ElseIf 全部_ch.Checked = False And 含稅_ch.Checked = True And 非稅_ch.Checked = False Then : SQL2 = " AND (公帳流水帳.含稅 = 1)" ElseIf 全部_ch.Checked = False And 含稅_ch.Checked = False And 非稅_ch.Checked = True Then : SQL2 = " AND (公帳流水帳.含稅 = 0 OR 公帳流水帳.含稅 IS NULL)" : End If If 公司編號_cb.Text = "全部" Or 公司編號_cb.Text = "" Then : PA51 = "" : Else : PA51 = " AND (公帳控制表.公司編號 LIKE N'" & 公司編號_cb.Text & "')" : End If If boo = True Then : PA55 = 申請日期_dtp.Text : Else : PA55 = "" : End If dt.Clear() Using conn As New SqlConnection(ConString) : conn.Open() Using cmd As New SqlCommand() : cmd.Connection = conn If boo1 = True Then : cmd.CommandText = SQL_營運成本收支單一覽表_查詢費用清單() Else : cmd.CommandText = SQL_營運成本收支單一覽表_查詢清單4() : End If Using adapter As New SqlDataAdapter(cmd) adapter.Fill(dt) End Using End Using End Using End Sub Public Sub 添加昨日結餘行() 原日期字串 = 單據日期 Dim 日期 As DateTime = DateTime.ParseExact(原日期字串, "yyyy/MM/dd", Globalization.CultureInfo.InvariantCulture) Dim 減一天 As DateTime = 日期.AddDays(-1) : Dim 減一天字串 As String = 減一天.ToString("yyyy/MM/dd") 單據日期 = 減一天字串 : Dim 結餘 As Integer For I As Integer = 0 To 正壘算_dgv.Rows.Count - 1 If 單據日期 = 正壘算_dgv.Rows(I).Cells("日期").Value.ToString Then 結餘 = 正壘算_dgv.Rows(I).Cells("每日結餘").Value.ToString : Exit For End If Next Dim newRow As DataRow = dt.NewRow() newRow("項次") = 0 : newRow("支付單號") = "OE-" & Strings.Left(原日期字串, 4) & Strings.Mid(原日期字串, 6, 2) & Strings.Right(原日期字串, 2) & "-999" newRow("會計科目") = "昨日結餘" : newRow("用途") = "" : newRow("零用金") = 0 newRow("支票") = 0 : newRow("收入") = 結餘 : newRow("支出") = 0 : newRow("票期") = "" : newRow("匯率") = 1 newRow("幣別") = "NTD" : newRow("類別") = "" : newRow("流水號") = "" dt.Rows.InsertAt(newRow, 0) : 明細_dgv.Refresh() End Sub Public Sub 添加今日結餘行() Dim newRow As DataRow = dt.NewRow() Dim 零用金合計 As Decimal = 0 : Dim 收入合計 As Decimal = 0 : Dim 支出合計 As Decimal = 0 : Dim 結算 As Decimal = 0 For Each row As DataRow In dt.Rows ' 計算所有行的合計 If Not Convert.IsDBNull(row("零用金")) Then : 零用金合計 += Convert.ToDecimal(row("零用金")) : End If If Not Convert.IsDBNull(row("收入")) Then : 收入合計 += Convert.ToDecimal(row("收入")) : End If If Not Convert.IsDBNull(row("支出")) Then : 支出合計 -= Convert.ToDecimal(row("支出")) : End If Next 結算 = 零用金合計 + 收入合計 + 支出合計 newRow("項次") = dt.Rows.Count + 1 : newRow("支付單號") = "**自動計算**" : newRow("會計科目") = "今日結餘" : newRow("用途") = "" : newRow("零用金") = 零用金合計 : newRow("支票") = 0 If 結算 >= 0 Then : newRow("收入") = 結算 : newRow("支出") = 0 : Else : newRow("收入") = 0 : newRow("支出") = 結算 * -1 : End If newRow("票期") = "" : newRow("匯率") = 1 : newRow("幣別") = "NTD" : newRow("類別") = "" : newRow("流水號") = "" dt.Rows.Add(newRow) : 明細_dgv.Refresh() End Sub Public Sub 更新數據源() 加載數據到DataTable() : 明細_dgv.Refresh() End Sub Private Sub Set_費用清單() 初始化DataGridView() 明細_dgv.Columns(0).FillWeight = 50 : 明細_dgv.Columns(1).FillWeight = 250 : 明細_dgv.Columns(2).FillWeight = 250 : 明細_dgv.Columns(3).FillWeight = 380 明細_dgv.Columns(6).FillWeight = 140 : 明細_dgv.Columns(7).FillWeight = 140 明細_dgv.Columns(9).Visible = False : 明細_dgv.Columns(10).Visible = False : 明細_dgv.Columns(11).Visible = False 明細_dgv.Columns(12).Visible = False : 明細_dgv.Columns(4).Visible = False : 明細_dgv.Columns(5).Visible = False : 明細_dgv.Columns(8).Visible = False If 彙總匯率_ch.Checked = False Then 明細_dgv.Columns(9).Visible = False : 明細_dgv.Columns(10).Visible = False Else 明細_dgv.Columns(9).Visible = False : 明細_dgv.Columns(10).Visible = False End If For i As Integer = 0 To 明細_dgv.Columns.Count - 1 : 明細_dgv.Columns(i).ReadOnly = True : Next 明細_dgv.Columns(4).DefaultCellStyle.Format = "#,##0" : 明細_dgv.Columns(5).DefaultCellStyle.Format = "#,##0" : 明細_dgv.Columns(6).DefaultCellStyle.Format = "#,##0" 明細_dgv.Columns(7).DefaultCellStyle.Format = "#,##0" 明細_dgv.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 明細_dgv.Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight 明細_dgv.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 明細_dgv.Columns(5).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight 明細_dgv.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 明細_dgv.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight 明細_dgv.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 明細_dgv.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight 明細_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : 明細_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter 明細_dgv.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : 明細_dgv.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter 明細_dgv.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : 明細_dgv.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter 添加昨日結餘行() : 添加今日結餘行() 台幣現金_tb.Text = "0" : 台幣支出_tb.Text = "0" : 台幣現金餘額_tb.Text = "0" : 台幣零用金_tb.Text = "0" : 台幣支票_tb.Text = "0" 人民幣零用金_tb.Text = "0" : 人民幣支票_tb.Text = "0" : 人民幣現金_tb.Text = "0" : 人民幣支出_tb.Text = "0" : 人民幣現金餘額_tb.Text = "0" For i As Integer = 0 To 明細_dgv.Rows.Count - 1 明細_dgv.Rows(i).Cells("項次").Value = i + 1 If 明細_dgv.Rows(i).Cells("幣別").Value = "台幣現金" Then 台幣現金_tb.Text = Val(台幣現金_tb.Text) + 明細_dgv.Rows(i).Cells("收入").Value 台幣支出_tb.Text = Val(台幣支出_tb.Text) + 明細_dgv.Rows(i).Cells("支出").Value 台幣零用金_tb.Text = Val(台幣零用金_tb.Text) + 明細_dgv.Rows(i).Cells("零用金").Value 台幣支票_tb.Text = Val(台幣支票_tb.Text) + 明細_dgv.Rows(i).Cells("支票").Value End If If 明細_dgv.Rows(i).Cells("幣別").Value = "人民幣現金" Then 人民幣現金_tb.Text = Val(人民幣現金_tb.Text) + 明細_dgv.Rows(i).Cells("收入").Value 人民幣支出_tb.Text = Val(人民幣支出_tb.Text) + 明細_dgv.Rows(i).Cells("支出").Value 人民幣零用金_tb.Text = Val(人民幣零用金_tb.Text) + 明細_dgv.Rows(i).Cells("零用金").Value 人民幣支票_tb.Text = Val(人民幣支票_tb.Text) + 明細_dgv.Rows(i).Cells("支票").Value End If Next i 台幣現金餘額_tb.Text = Val(台幣零用金_tb.Text) + Val(台幣現金_tb.Text) - Val(台幣支出_tb.Text) 人民幣現金餘額_tb.Text = Val(人民幣零用金_tb.Text) + Val(人民幣現金_tb.Text) - Val(人民幣支出_tb.Text) 台幣現金_tb.Text = Strings.Format(Val(台幣現金_tb.Text), "#,##0") : 台幣支出_tb.Text = Strings.Format(Val(台幣支出_tb.Text), "#,##0") 台幣現金餘額_tb.Text = Strings.Format(Val(台幣現金餘額_tb.Text), "#,##0") 台幣零用金_tb.Text = Strings.Format(Val(台幣零用金_tb.Text), "#,##0") : 台幣支票_tb.Text = Strings.Format(Val(台幣支票_tb.Text), "#,##0") 人民幣零用金_tb.Text = Strings.Format(Val(人民幣零用金_tb.Text), "#,##0") : 人民幣支票_tb.Text = Strings.Format(Val(人民幣支票_tb.Text), "#,##0") 人民幣現金_tb.Text = Strings.Format(Val(人民幣現金_tb.Text), "#,##0") 人民幣支出_tb.Text = Strings.Format(Val(人民幣支出_tb.Text), "#,##0") : 人民幣現金餘額_tb.Text = Strings.Format(Val(人民幣現金餘額_tb.Text), "#,##0") End Sub Private Sub Set_日結() 壘算_dgv.DataSource = Nothing : ds6.Clear() 壘算_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 壘算_dgv.ColumnHeadersHeight = 25 : 壘算_dgv.AllowUserToAddRows = False : 壘算_dgv.RowTemplate.Height = 25 SQL_日帳結算() : da.Fill(ds6) : 壘算_dgv.DataSource = ds6.Tables(0) : conn.Close() 正壘算_dgv.Rows.Clear() : 正壘算_dgv.AllowUserToAddRows = False Dim 今天 As Date = Date.Today Dim 當前日期 As Date = 壘算_dgv.Rows(0).Cells("日期").Value.ToString Do While 當前日期 <= 今天 正壘算_dgv.Rows.Add(當前日期.ToString("yyyy/MM/dd"), 0D, 0D) 當前日期 = 當前日期.AddDays(1) Loop For i As Integer = 0 To 正壘算_dgv.Rows.Count - 1 For J As Integer = 0 To 壘算_dgv.Rows.Count - 1 If 正壘算_dgv.Rows(i).Cells("日期").Value.ToString = 壘算_dgv.Rows(J).Cells("日期").Value.ToString Then 正壘算_dgv.Rows(i).Cells("日結").Value = 壘算_dgv.Rows(J).Cells("日結").Value : Exit For End If Next If i = 0 Then 正壘算_dgv.Rows(i).Cells("每日結餘").Value = 正壘算_dgv.Rows(i).Cells("日結").Value Else 正壘算_dgv.Rows(i).Cells("每日結餘").Value = 正壘算_dgv.Rows(i).Cells("日結").Value + 正壘算_dgv.Rows(i - 1).Cells("每日結餘").Value End If Next End Sub Private Sub 日期格式() If 會計月_ch.Checked = True Then '-------------日期一---------------------------------------------------------------------------------------- DTP = Strings.Left(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 8) & "01" : 開始日期_dtp.Value = DTP 開始日期_dtp.Value = 結束日期_dtp.Value.AddMonths(-1) DTP = Strings.Left(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 8) & "26" : 開始日期_dtp.Value = DTP '-------------日期二---------------------------------------------------------------------------------------- DTP = Strings.Left(Strings.Format(結束日期_dtp.Value, "yyyy/MM/dd"), 8) & "25" : 結束日期_dtp.Value = DTP Else 開始日期_dtp.Value = 結束日期_dtp.Value '-------------日期一---------------------------------------------------------------------------------------- DTP = Strings.Left(Strings.Format(開始日期_dtp.Value, "yyyy/MM/dd"), 8) & "01" : 開始日期_dtp.Value = DTP '-------------日期二---------------------------------------------------------------------------------------- DTP = Strings.Left(Strings.Format(結束日期_dtp.Value, "yyyy/MM/dd"), 8) & "01" : 結束日期_dtp.Value = DTP 結束日期_dtp.Value = 結束日期_dtp.Value.AddMonths(1) : 結束日期_dtp.Value = 結束日期_dtp.Value.AddDays(-1) End If End Sub Private Sub 載入公司編號cb() SQL_公司編號_下拉清單() : 公司編號_cb.Items.Clear() : 公司編號_cb.Items.Add("全部") While (dr.Read()) : 公司編號_cb.Items.Add(dr("公司編號")) : End While : conn.Close() End Sub Private Sub 營運成本收支單一覽表_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.MdiParent = ICS_ASMS_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True 正壘算_dgv.Columns.Clear() 正壘算_dgv.Columns.Add("日期", "日期") 正壘算_dgv.Columns.Add("日結", "日結") 正壘算_dgv.Columns.Add("每日結餘", "每日結餘") End Sub Private Sub 營運成本收支單一覽表_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown Set_日結() : System.Windows.Forms.Application.DoEvents() 載入公司編號cb() : System.Windows.Forms.Application.DoEvents() DTP = Strings.Left(Strings.Format(Today(), "yyyy/MM/dd"), 8) & "01" 開始日期_dtp.Value = DTP : 結束日期_dtp.Value = Today() : 支付單列印成EXCEL.Enabled = False 日期格式() : 明細_rb.Checked = True : 財務彙總_天_dgv.Visible = False If 公司 = True Then : Else : 公司編號_lb.Visible = False : 公司編號_cb.Visible = False : End If SQL_讀取公司名稱() : If dr.Read() Then : 公司名稱.Text = dr("公司名稱") : End If : conn.Close() End Sub Dim 已超出 As Boolean Private Sub 財務彙總_dgv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 財務彙總_dgv.MouseUp 'If 財務彙總_dgv.SelectedCells.Count = 1 Then : MsgBox(財務彙總_dgv.SelectedCells(0).ColumnIndex & " " & 財務彙總_dgv.SelectedCells(0).RowIndex) : End If If 財務彙總_dgv.SelectedCells.Count = 1 Then : 已超出 = False : End If If 財務彙總_dgv.SelectedCells.Count > 0 Then If 財務彙總_dgv.SelectedCells(0).ColumnIndex >= 4 And 財務彙總_dgv.SelectedCells(0).ColumnIndex <= 7 Then If 已超出 = False Then Dim x As Double = 0 For i As Integer = 0 To 財務彙總_dgv.SelectedCells.Count - 1 x += Val(財務彙總_dgv.Rows(財務彙總_dgv.SelectedCells.Item(i).RowIndex).Cells(財務彙總_dgv.SelectedCells.Item(i).ColumnIndex).Value) Next i : ICS_ASMS_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(x, "#,##0") Else : ICS_ASMS_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0") : End If Else : 已超出 = True : ICS_ASMS_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0") End If End If End Sub Private Sub 明細_dgv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 明細_dgv.MouseUp 'If 明細_dgv.SelectedCells.Count = 1 Then : MsgBox(明細_dgv.SelectedCells(0).ColumnIndex & " " & 明細_dgv.SelectedCells(0).RowIndex) : End If If 明細_dgv.SelectedCells.Count = 1 Then : 已超出 = False : End If If 明細_dgv.SelectedCells.Count > 0 Then If 明細_dgv.SelectedCells(0).ColumnIndex >= 4 And 明細_dgv.SelectedCells(0).ColumnIndex <= 7 Then If 已超出 = False Then Dim x As Double = 0 For i As Integer = 0 To 明細_dgv.SelectedCells.Count - 1 x += Val(明細_dgv.Rows(明細_dgv.SelectedCells.Item(i).RowIndex).Cells(明細_dgv.SelectedCells.Item(i).ColumnIndex).Value) Next i : ICS_ASMS_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(x, "#,##0") Else : ICS_ASMS_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0") : End If Else : 已超出 = True : ICS_ASMS_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0") End If End If End Sub Private Sub 財務彙總_dgv_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles 財務彙總_dgv.CellClick If e.RowIndex = -1 Then : Else PA56 = 財務彙總_dgv(3, e.RowIndex).Value.ToString boo1 = False 支付單列印成EXCEL.Enabled = True Set_費用清單() End If End Sub Private Sub 單據彙總_dgv_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles 單據彙總_dgv.CellClick If e.RowIndex = -1 Then : Else 收支單號_tb.Text = 單據彙總_dgv(0, e.RowIndex).Value.ToString : 驗證碼_tb.Text = 單據彙總_dgv(6, e.RowIndex).Value.ToString 申請人_tb.Text = 單據彙總_dgv(1, e.RowIndex).Value.ToString : 申請日期_dtp.Value = 單據彙總_dgv(2, e.RowIndex).Value.ToString 審核人_tb.Text = 單據彙總_dgv(3, e.RowIndex).Value.ToString : 圖片編碼_tb.Text = 單據彙總_dgv(5, e.RowIndex).Value.ToString If 單據彙總_dgv(4, e.RowIndex).Value.ToString = "" Then 審核日期_dtp.Value = 單據彙總_dgv(2, e.RowIndex).Value.ToString Else 審核日期_dtp.Value = 單據彙總_dgv(4, e.RowIndex).Value.ToString End If Set_費用清單() End If End Sub Private Sub 日期彙總_dgv_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles 日期彙總_dgv.CellClick If e.RowIndex = -1 Then : Else boo1 = True boo = True : 支付單列印成EXCEL.Enabled = True If 日期浮動_cb.Checked = True Then 結束日期_dtp.Value = 日期彙總_dgv(0, e.RowIndex).Value.ToString End If 申請日期_dtp.Value = 日期彙總_dgv(0, e.RowIndex).Value.ToString : 單據日期 = 日期彙總_dgv(0, e.RowIndex).Value.ToString Set_費用清單() : Set_清單3() : Set_清單2() If 單據彙總_dgv.Rows.Count > 0 Then 圖片編碼_tb.Text = 單據彙總_dgv(5, 0).Value.ToString End If 憑證張數_tb.Text = "" End If End Sub Private Sub 單據彙總_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 單據彙總_dgv.RowPostPaint Dim linePen As New Pen(Color.Blue, 2) : Dim linePen1 As New Pen(Color.Red, 2) : Dim linePen2 As New Pen(Color.Green, 2) If e.RowIndex = 單據彙總_dgv.Rows.Count - 1 Then Exit Sub Else If 單據彙總_dgv(2, e.RowIndex).Value.ToString <> 單據彙總_dgv(2, e.RowIndex + 1).Value.ToString Then Dim startX As Integer = IIf(單據彙總_dgv.RowHeadersVisible, 單據彙總_dgv.RowHeadersWidth, 0) Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1 Dim endX As Integer = startX + 單據彙總_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 單據彙總_dgv.HorizontalScrollingOffset e.Graphics.DrawLine(linePen, startX, startY, endX, startY) Exit Sub End If End If End Sub Private Sub 財務彙總_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 財務彙總_dgv.RowPostPaint Dim linePen As New Pen(Color.Blue, 2) : Dim linePen1 As New Pen(Color.Red, 2) : Dim linePen2 As New Pen(Color.Green, 2) If e.RowIndex = 財務彙總_dgv.Rows.Count - 1 Then Exit Sub Else If 財務彙總_dgv(0, e.RowIndex).Value.ToString <> 財務彙總_dgv(0, e.RowIndex + 1).Value.ToString Then Dim startX As Integer = IIf(財務彙總_dgv.RowHeadersVisible, 財務彙總_dgv.RowHeadersWidth, 0) Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1 Dim endX As Integer = startX + 財務彙總_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 財務彙總_dgv.HorizontalScrollingOffset e.Graphics.DrawLine(linePen, startX, startY, endX, startY) Exit Sub End If If 財務彙總_dgv(8, e.RowIndex).Value.ToString <> 財務彙總_dgv(8, e.RowIndex + 1).Value.ToString Then Dim startX As Integer = IIf(財務彙總_dgv.RowHeadersVisible, 財務彙總_dgv.RowHeadersWidth, 0) Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1 Dim endX As Integer = startX + 財務彙總_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 財務彙總_dgv.HorizontalScrollingOffset e.Graphics.DrawLine(linePen2, startX, startY, endX, startY) Exit Sub End If If 財務彙總_dgv(1, e.RowIndex).Value.ToString <> 財務彙總_dgv(1, e.RowIndex + 1).Value.ToString Then Dim startX As Integer = IIf(財務彙總_dgv.RowHeadersVisible, 財務彙總_dgv.RowHeadersWidth, 0) Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1 Dim endX As Integer = startX + 財務彙總_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 財務彙總_dgv.HorizontalScrollingOffset e.Graphics.DrawLine(linePen1, startX, startY, endX, startY) Exit Sub End If End If End Sub Private Sub 日期浮動_cb_CheckedChanged(sender As Object, e As EventArgs) Handles 日期浮動_cb.Click If 日期浮動_cb.Checked = False Then 日期浮動_cb.Checked = False : 當月_bt.PerformClick() End If End Sub Private Sub 全部_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 全部_ch.Click 全部_ch.Checked = True : 含稅_ch.Checked = False : 非稅_ch.Checked = False : Set_費用清單() : Set_清單() : Set_清單2() : 彙總計算() End Sub Private Sub 含稅_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 含稅_ch.Click 全部_ch.Checked = False : 含稅_ch.Checked = True : 非稅_ch.Checked = False : Set_費用清單() : Set_清單() : Set_清單2() : 彙總計算() End Sub Private Sub 非稅_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 非稅_ch.Click 全部_ch.Checked = False : 含稅_ch.Checked = False : 非稅_ch.Checked = True : Set_費用清單() : Set_清單() : Set_清單2() : 彙總計算() End Sub Private Sub 當日_bt_Click(sender As Object, e As EventArgs) Handles 當日_bt.Click 中間日期_dtp.Value = Today 日期浮動_cb.Checked = False : DTP = Strings.Format(Today(), "yyyy/MM/dd") 開始日期_dtp.Value = DTP : 結束日期_dtp.Value = DTP boo = False Set_費用清單() : Set_清單() : Set_清單2() : 彙總計算() End Sub Private Sub 當月_bt_Click(sender As Object, e As EventArgs) Handles 當月_bt.Click 中間日期_dtp.Value = Today 日期浮動_cb.Checked = False : DTP = Strings.Left(Strings.Format(Today(), "yyyy/MM/dd"), 8) & "01" 開始日期_dtp.Value = DTP : 結束日期_dtp.Value = Today() boo = False Set_費用清單() : Set_清單() : Set_清單2() : 彙總計算() End Sub Private Sub 彙總計算() If 明細_rb.Checked = False And 彙總_rb.Checked = True Then 支付單列印成EXCEL.Enabled = False 台幣現金_tb.Text = "0" : 台幣支出_tb.Text = "0" : 台幣現金餘額_tb.Text = "0" : 台幣零用金_tb.Text = "0" : 台幣支票_tb.Text = "0" 人民幣零用金_tb.Text = "0" : 人民幣支票_tb.Text = "0" : 人民幣現金_tb.Text = "0" : 人民幣支出_tb.Text = "0" : 人民幣現金餘額_tb.Text = "0" For i As Integer = 0 To 財務彙總_dgv.Rows.Count - 1 If 財務彙總_dgv.Rows(i).Cells("幣別").Value = "台幣現金" Then 台幣現金_tb.Text = Val(台幣現金_tb.Text) + 財務彙總_dgv.Rows(i).Cells("收入").Value 台幣支出_tb.Text = Val(台幣支出_tb.Text) + 財務彙總_dgv.Rows(i).Cells("支出").Value 台幣零用金_tb.Text = Val(台幣零用金_tb.Text) + 財務彙總_dgv.Rows(i).Cells("零用金").Value 台幣支票_tb.Text = Val(台幣支票_tb.Text) + 財務彙總_dgv.Rows(i).Cells("支票").Value End If If 財務彙總_dgv.Rows(i).Cells("幣別").Value = "人民幣現金" Then If 財務彙總_dgv.Rows(i).Cells("主項").Value <> "上月結存" Then 人民幣現金_tb.Text = Val(人民幣現金_tb.Text) + 財務彙總_dgv.Rows(i).Cells("收入").Value 人民幣支出_tb.Text = Val(人民幣支出_tb.Text) + 財務彙總_dgv.Rows(i).Cells("支出").Value 人民幣零用金_tb.Text = Val(人民幣零用金_tb.Text) + 財務彙總_dgv.Rows(i).Cells("零用金").Value 人民幣支票_tb.Text = Val(人民幣支票_tb.Text) + 財務彙總_dgv.Rows(i).Cells("支票").Value End If End If Next i 台幣現金餘額_tb.Text = Val(台幣零用金_tb.Text) + Val(台幣現金_tb.Text) - Val(台幣支出_tb.Text) 人民幣現金餘額_tb.Text = Val(人民幣零用金_tb.Text) + Val(人民幣現金_tb.Text) - Val(人民幣支出_tb.Text) 台幣現金_tb.Text = Strings.Format(Val(台幣現金_tb.Text), "#,##0") : 台幣支出_tb.Text = Strings.Format(Val(台幣支出_tb.Text), "#,##0") 台幣現金餘額_tb.Text = Strings.Format(Val(台幣現金餘額_tb.Text), "#,##0") 台幣零用金_tb.Text = Strings.Format(Val(台幣零用金_tb.Text), "#,##0") : 台幣支票_tb.Text = Strings.Format(Val(台幣支票_tb.Text), "#,##0") 人民幣零用金_tb.Text = Strings.Format(Val(人民幣零用金_tb.Text), "#,##0") : 人民幣支票_tb.Text = Strings.Format(Val(人民幣支票_tb.Text), "#,##0") 人民幣現金_tb.Text = Strings.Format(Val(人民幣現金_tb.Text), "#,##0") 人民幣支出_tb.Text = Strings.Format(Val(人民幣支出_tb.Text), "#,##0") : 人民幣現金餘額_tb.Text = Strings.Format(Val(人民幣現金餘額_tb.Text), "#,##0") End If End Sub Private Sub 上個月_bt_Click(sender As Object, e As EventArgs) Handles 上個月_bt.Click 日期浮動_cb.Checked = False If 會計月_ch.Checked = True Then 中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(-1) 開始日期_dtp.Value = 中間日期_dtp.Value 結束日期_dtp.Value = 中間日期_dtp.Value Else 中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(-1) 開始日期_dtp.Value = 中間日期_dtp.Value 結束日期_dtp.Value = 中間日期_dtp.Value End If boo = False 日期格式() : Set_費用清單() : Set_清單() : Set_清單2() : 彙總計算() End Sub Private Sub 下個月_bt_Click(sender As Object, e As EventArgs) Handles 下個月_bt.Click 日期浮動_cb.Checked = False If 會計月_ch.Checked = True Then 中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(1) 開始日期_dtp.Value = 中間日期_dtp.Value 結束日期_dtp.Value = 中間日期_dtp.Value Else 中間日期_dtp.Value = 中間日期_dtp.Value.AddMonths(1) 開始日期_dtp.Value = 中間日期_dtp.Value 結束日期_dtp.Value = 中間日期_dtp.Value End If : boo = False : 日期格式() : Set_費用清單() : Set_清單() : Set_清單2() : 彙總計算() End Sub Private Sub 開始日期_dtp_ValueChanged(sender As Object, e As EventArgs) Handles 開始日期_dtp.ValueChanged If 日期浮動_cb.Checked = True Then Set_清單1() : Set_清單2() : 彙總計算() Else Set_清單1() : Set_清單() : Set_清單2() : 彙總計算() End If End Sub Private Sub 結束日期_dtp_ValueChanged(sender As Object, e As EventArgs) Handles 結束日期_dtp.ValueChanged If 日期浮動_cb.Checked = True Then Set_清單1() : Set_清單2() : 彙總計算() Else Set_清單1() : Set_清單() : Set_清單2() : 彙總計算() End If End Sub Private Sub 會計月_CheckedChanged(sender As Object, e As EventArgs) Handles 會計月_ch.Click 會計月_ch.Checked = True : 一般月_ch.Checked = False : 日期格式() : Set_費用清單() : Set_清單() : Set_清單2() : 彙總計算() End Sub Private Sub 一般月_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 一般月_ch.Click 會計月_ch.Checked = False : 一般月_ch.Checked = True : 日期格式() : Set_費用清單() : Set_清單() : Set_清單2() : 彙總計算() End Sub Private Sub 明細_rb_CheckedChanged(sender As Object, e As EventArgs) Handles 明細_rb.Click 明細_dgv.Visible = True : 財務彙總_天_dgv.Visible = False 明細_rb.Checked = True : 彙總_rb.Checked = False 台幣現金_tb.Text = "0" : 台幣支出_tb.Text = "0" : 台幣現金餘額_tb.Text = "0" : 台幣零用金_tb.Text = "0" : 台幣支票_tb.Text = "0" ': 單據彙總_dgv.Enabled = True End Sub Private Sub 彙總_rb_CheckedChanged(sender As Object, e As EventArgs) Handles 彙總_rb.Click 明細_dgv.Visible = False : 財務彙總_天_dgv.Visible = True 明細_rb.Checked = False : 彙總_rb.Checked = True 收支單號_tb.Text = "" : 申請人_tb.Text = "" : 審核人_tb.Text = "" : 明細_dgv.DataSource = Nothing : ds.Clear() ': 單據彙總_dgv.Enabled = False 彙總計算() End Sub Private Sub 圖片編碼_tb_TextChanged(sender As Object, e As EventArgs) Handles 圖片編碼_tb.TextChanged SQL_營運成本收支單一覽表_查詢簽名檔圖片() While dr.Read() = True Dim unused As Byte() = New Byte(-1) {} Dim bytes As Byte() = DirectCast(dr.Item("簽名檔圖片"), Byte()) Dim oStream As New MemoryStream(bytes) 簽名圖_pb.Image = Bitmap.FromStream(oStream) End While conn.Close() 簽名圖_pb.SizeMode = 4 End Sub Private Sub 彙總匯率_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 彙總匯率_ch.Click Set_清單() : Set_清單2() End Sub Private Sub 支付單列印成EXCEL_Click(sender As Object, e As EventArgs) Handles 支付單列印成EXCEL.Click If 明細_rb.Checked = False And 彙總_rb.Checked = True Then MsgBox("請點選明細才能列印") ElseIf 明細_rb.Checked = True And 彙總_rb.Checked = False Then 列印.ShowDialog() : 列印.BringToFront() xlApp = CType(CreateObject("Excel.Application"), Application) xlBook = xlApp.Workbooks.Add : xlApp.DisplayAlerts = True : xlBook.Activate() : xlSheet = NewMethod(xlBook) xlSheet.Activate() : xlApp.Visible = True : xlApp.Application.WindowState = xlMaximized If BL1 Then Dim dat As String = 明細_dgv.Rows(0).Cells("支付單號").Value.ToString Dim startIndex As Integer = dat.IndexOf("-") + 1 Dim datePart As String Dim dateValue As DateTime Dim dat1 As String If boo1 = True Then datePart = dat.Substring(startIndex, 8) If DateTime.TryParseExact(datePart, "yyyyMMdd", Nothing, System.Globalization.DateTimeStyles.None, dateValue) Then Dim formattedDate As String = dateValue.ToString("yyyy/MM/dd") dat1 = formattedDate Else dat1 = "無效日期" End If Else datePart = DateTime.Now.ToString("yyyyMM") dat1 = DateTime.Now.ToString("yyyy/MM") End If Dim firstCellValue As Object = 明細_dgv.Rows(0).Cells("會計科目").Value Dim allSame As Boolean = True For i As Integer = 1 To 明細_dgv.Rows.Count - 1 If Not Object.Equals(明細_dgv.Rows(i).Cells("會計科目").Value, firstCellValue) Then allSame = False Exit For End If Next If allSame Then xlSheet.Cells(2, 3) = 明細_dgv.Rows(0).Cells("會計科目").Value & "-用途說明" Else xlSheet.Cells(2, 3) = "用途說明" End If xlSheet.Cells(1, 1) = 公司名稱.Text & "收支粘貼憑證用紙-" & dat1 xlSheet.Cells(2, 1) = "憑證編號" : xlSheet.Cells(2, 2) = "編號" : xlSheet.Cells(2, 9) = "金額" xlSheet.Cells(2, 10) = "附件" : xlSheet.Cells(3, 10) = "憑證" : xlSheet.Cells(2, 8) = "收" & vbLf & "支" xlSheet.Cells(4, 10) = 憑證張數_tb.Text & vbCrLf & "張" If 顯示單據_cb.Checked = True Then xlSheet.Cells(2, 7) = "單據" & vbLf & "編號" End If For i As Integer = 0 To 明細_dgv.Rows.Count - 2 If i <> 0 Then xlSheet.Cells(i + 4, 2) = i End If If allSame Then xlSheet.Cells(i + 4, 3) = 明細_dgv.Rows(i).Cells("用途").Value If 顯示單據_cb.Checked = True Then xlSheet.Cells(i + 4, 7) = "'" + 明細_dgv.Rows(i).Cells("票期").Value End If Else xlSheet.Cells(i + 4, 3) = 明細_dgv.Rows(i).Cells("會計科目").Value xlSheet.Cells(i + 4, 4) = 明細_dgv.Rows(i).Cells("用途").Value If 顯示單據_cb.Checked = True Then xlSheet.Cells(i + 4, 7) = "'" + 明細_dgv.Rows(i).Cells("票期").Value End If End If xlSheet.Cells(i + 4, 11) = 明細_dgv.Rows(i).Cells("用途").Value If 明細_dgv.Rows(i).Cells("收入").Value = 0 And 明細_dgv.Rows(i).Cells("支出").Value <> 0 Then If i <> 0 Then xlSheet.Cells(i + 4, 8) = "支" End If Dim value1 As Double = Convert.ToDouble(明細_dgv.Rows(i).Cells("支出").Value) Dim formattedValue1 As String = value1.ToString("#,##0") xlSheet.Cells(i + 4, 9) = formattedValue1 'Dim str As String = 大寫轉換(明細_dgv.Rows(i).Cells("支出").Value) 'xlSheet.Cells(i + 4, 9) = str & " 元整" ElseIf 明細_dgv.Rows(i).Cells("收入").Value <> 0 And 明細_dgv.Rows(i).Cells("支出").Value = 0 Then If i <> 0 Then xlSheet.Cells(i + 4, 8) = "收" End If Dim value2 As Double = Convert.ToDouble(明細_dgv.Rows(i).Cells("收入").Value) Dim formattedValue2 As String = value2.ToString("#,##0") xlSheet.Cells(i + 4, 9) = formattedValue2 'Dim str As String = 大寫轉換(明細_dgv.Rows(i).Cells("收入").Value) 'xlSheet.Cells(i + 4, 9) = str & " 元整" End If N2 = i + 4 Next i Dim 台幣現金餘額 As Double Dim index As Integer = 明細_dgv.Rows.Count - 1 xlSheet.Cells(N2 + 1, 2) = "今日結餘 : " If 明細_dgv.Rows(index).Cells("收入").Value = 0 And 明細_dgv.Rows(index).Cells("支出").Value <> 0 Then 台幣現金餘額 = Convert.ToDouble(明細_dgv.Rows(index).Cells("支出").Value) * -1 ElseIf 明細_dgv.Rows(index).Cells("收入").Value <> 0 And 明細_dgv.Rows(index).Cells("支出").Value = 0 Then 台幣現金餘額 = Convert.ToDouble(明細_dgv.Rows(index).Cells("收入").Value) Else 台幣現金餘額 = 0 End If xlSheet.Cells(N2 + 1, 9) = 台幣現金餘額.ToString("#,##0") SQL_公司稱謂() If dr.Read() Then xlSheet.Cells(N2 + 2, 7) = If(Not IsDBNull(dr("編號一")), dr("編號一").ToString(), "") xlSheet.Cells(N2 + 2, 6) = If(Not IsDBNull(dr("編號二")), dr("編號二").ToString(), "") xlSheet.Cells(N2 + 2, 5) = If(Not IsDBNull(dr("編號三")), dr("編號三").ToString(), "") xlSheet.Cells(N2 + 2, 4) = If(Not IsDBNull(dr("編號四")), dr("編號四").ToString(), "") xlSheet.Cells(N2 + 2, 3) = If(Not IsDBNull(dr("編號五")), dr("編號五").ToString(), "") xlSheet.Cells(N2 + 2, 1) = If(Not IsDBNull(dr("編號六")), dr("編號六").ToString(), "") xlSheet.Cells(N2 + 2, 9) = If(Not IsDBNull(dr("編號七")), dr("編號七").ToString(), "") End If AA(xlApp, xlSheet, allSame) xlApp.Sheets(2).Delete : xlSheet.PageSetup.PrintArea = "" '----轉成PDF----- Dim pdfFolderPath As String = Path.Combine(System.Windows.Forms.Application.StartupPath, "pdf") If Not Directory.Exists(pdfFolderPath) Then Directory.CreateDirectory(pdfFolderPath) End If Dim pdfFilePath As String = Path.Combine(pdfFolderPath, datePart & "-傳票.pdf") xlBook.Sheets(1).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, pdfFilePath, XlFixedFormatQuality.xlQualityStandard, True) '-------- xlApp.Cells.Select() : xlApp.Application.WindowState = xlMinimized : xlBook.Close(False) Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) Runtime.InteropServices.Marshal.ReleaseComObject(xlBook) Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) xlApp.Quit() : xlSheet = Nothing : xlBook = Nothing : xlApp = Nothing : GC.Collect() Try Dim chromePath As String = "C:\Program Files\Google\Chrome\Application\chrome.exe" If System.IO.File.Exists(chromePath) Then Dim process As New Process() process.StartInfo.FileName = "chrome" process.StartInfo.Arguments = """" & pdfFilePath & """" process.Start() Else : Dim edgePath As String = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" If System.IO.File.Exists(edgePath) Then Dim process As New Process() process.StartInfo.FileName = "msedge" process.StartInfo.Arguments = """" & pdfFilePath & """" process.Start() Else Process.Start(pdfFilePath) End If End If Catch ex As Exception MsgBox("以存檔至桌面 。" & vbCrLf & "檔案名稱:" & datePart & "-傳票.pdf") End Try Else xlSheet.Cells(1, 1) = 公司名稱.Text & "收支一覽表-" & 開始日期_dtp.Value.ToString("yyyy/MM/dd") & "~" & 結束日期_dtp.Value.ToString("yyyy/MM/dd") xlSheet.Cells(2, 1) = "主項" : xlSheet.Cells(2, 2) = "子項" : xlSheet.Cells(2, 3) = "子細項" xlSheet.Cells(2, 4) = "收入" : xlSheet.Cells(2, 5) = "支出" Dim 支出合計 As Double = 0 : Dim 收入合計 As Double = 0 For i As Integer = 0 To 財務彙總_dgv.Rows.Count - 1 Dim 支出 As Double = Convert.ToDouble(財務彙總_dgv.Rows(i).Cells("支出").Value) Dim 收入 As Double = Convert.ToDouble(財務彙總_dgv.Rows(i).Cells("收入").Value) 支出合計 += 支出 收入合計 += 收入 xlSheet.Cells(i + 3, 1) = 財務彙總_dgv.Rows(i).Cells("主項").Value xlSheet.Cells(i + 3, 2) = 財務彙總_dgv.Rows(i).Cells("子項").Value xlSheet.Cells(i + 3, 3) = 財務彙總_dgv.Rows(i).Cells("子細項").Value xlSheet.Cells(i + 3, 4) = 收入.ToString("#,##0") xlSheet.Cells(i + 3, 5) = 支出.ToString("#,##0") N2 = i + 4 Next i xlSheet.Cells(N2, 3) = "合計" : xlSheet.Cells(N2, 4) = 收入合計.ToString("#,##0") : xlSheet.Cells(N2, 5) = 支出合計.ToString("#,##0") xlSheet.Cells(N2 + 1, 3) = "總計" : xlSheet.Cells(N2 + 1, 4) = (收入合計 - 支出合計).ToString("#,##0") BB(xlApp, xlSheet) xlApp.Sheets(2).Delete : xlSheet.PageSetup.PrintArea = "" '----轉成PDF----- Dim pdfFolderPath As String = Path.Combine(System.Windows.Forms.Application.StartupPath, "pdf") If Not Directory.Exists(pdfFolderPath) Then Directory.CreateDirectory(pdfFolderPath) End If Dim pdfFilePath As String = Path.Combine(pdfFolderPath, "收支一覽表.pdf") xlBook.Sheets(1).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, pdfFilePath, XlFixedFormatQuality.xlQualityStandard, True) '-------- xlApp.Cells.Select() : xlApp.Application.WindowState = xlMinimized : xlBook.Close(False) Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) Runtime.InteropServices.Marshal.ReleaseComObject(xlBook) Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) xlApp.Quit() : xlSheet = Nothing : xlBook = Nothing : xlApp = Nothing : GC.Collect() Try Dim chromePath As String = "C:\Program Files\Google\Chrome\Application\chrome.exe" If System.IO.File.Exists(chromePath) Then Dim process As New Process() process.StartInfo.FileName = "chrome" process.StartInfo.Arguments = """" & pdfFilePath & """" process.Start() Else : Dim edgePath As String = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" If System.IO.File.Exists(edgePath) Then Dim process As New Process() process.StartInfo.FileName = "msedge" process.StartInfo.Arguments = """" & pdfFilePath & """" process.Start() Else Process.Start(pdfFilePath) End If End If Catch ex As Exception MsgBox("以存檔至桌面 。" & vbCrLf & "檔案名稱:收支一覽表.pdf") End Try End If End If End Sub Private Shared Function NewMethod(xlBook As Workbook) As Worksheet Return CType(xlBook.Worksheets.Add, Worksheet) End Function Private Sub BB(ByVal myExcel As Application, ByVal xlSheet As Worksheet) xlSheet.Activate() : xlSheet.Parent.Windows(1).View = XlWindowView.xlPageLayoutView : xlSheet.Cells.Select() With myExcel.Selection.Font : .Name = "標楷體" : .Size = 12 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone End With xlSheet.Range("A2:E" & N2 + 1).Select() myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With myExcel.Application.PrintCommunication = False With myExcel.ActiveSheet.PageSetup : .PrintTitleRows = "" : .PrintTitleColumns = "" : End With myExcel.Application.PrintCommunication = True : myExcel.ActiveSheet.PageSetup.PrintArea = "" : myExcel.Application.PrintCommunication = False With myExcel.ActiveSheet.PageSetup : .LeftHeader = "" : .CenterHeader = "" : .RightHeader = "" : .LeftFooter = "" : .CenterFooter = "" : .RightFooter = "" .LeftMargin = myExcel.Application.InchesToPoints(0.25) : .RightMargin = myExcel.Application.InchesToPoints(0.25) : .TopMargin = myExcel.Application.InchesToPoints(0.75) .BottomMargin = myExcel.Application.InchesToPoints(0.75) : .HeaderMargin = myExcel.Application.InchesToPoints(0.3) : .FooterMargin = myExcel.Application.InchesToPoints(0.3) .PrintHeadings = False : .PrintGridlines = False : .CenterHorizontally = True : .CenterVertically = False : .Draft = False : .FirstPageNumber = xlAutomatic .BlackAndWhite = False : .Zoom = False : .FitToPagesWide = 1 : .FitToPagesTall = 0 : .OddAndEvenPagesHeaderFooter = False : .DifferentFirstPageHeaderFooter = False .ScaleWithDocHeaderFooter = True : .AlignMarginsHeaderFooter = True .EvenPage.LeftHeader.Text = "" : .EvenPage.CenterHeader.Text = "" : .EvenPage.RightHeader.Text = "" : .EvenPage.LeftFooter.Text = "" .EvenPage.CenterFooter.Text = "" : .EvenPage.RightFooter.Text = "" : .FirstPage.LeftHeader.Text = "" : .FirstPage.CenterHeader.Text = "" .FirstPage.RightHeader.Text = "" : .FirstPage.LeftFooter.Text = "" : .FirstPage.CenterFooter.Text = "" : .FirstPage.RightFooter.Text = "" End With : myExcel.Application.PrintCommunication = True xlSheet.Columns("A:A").ColumnWidth = 15 : xlSheet.Columns("B:B").ColumnWidth = 15 : xlSheet.Columns("C:C").ColumnWidth = 21 xlSheet.Columns("D:D").ColumnWidth = 15 : xlSheet.Columns("E:E").ColumnWidth = 15 xlSheet.Range("A1:E1").Select() With myExcel.Selection.Font : .Name = "標楷體" : .Size = 14 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone End With xlSheet.Range("A1:E1").Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("D2,E2").Select() With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With xlSheet.Range("A" & N2 & ":C" & N2).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("A" & N2 + 1 & ":C" & N2 + 1).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("D" & N2 + 1 & ":E" & N2 + 1).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge For i As Integer = 1 To N2 + 1 xlSheet.Rows(i).AutoFit : xlSheet.Rows(i).RowHeight = xlSheet.Rows(i).RowHeight + 4 Next End Sub Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet, ByVal allSame As Boolean) xlSheet.Activate() : xlSheet.Parent.Windows(1).View = XlWindowView.xlPageLayoutView : xlSheet.Cells.Select() With myExcel.Selection.Font : .Name = "標楷體" : .Size = 12 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone End With xlSheet.Range("A2:J" & N2 + 3).Select() myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With myExcel.Application.PrintCommunication = False With myExcel.ActiveSheet.PageSetup : .PrintTitleRows = "" : .PrintTitleColumns = "" : End With myExcel.Application.PrintCommunication = True : myExcel.ActiveSheet.PageSetup.PrintArea = "" : myExcel.Application.PrintCommunication = False With myExcel.ActiveSheet.PageSetup : .LeftHeader = "" : .CenterHeader = "" : .RightHeader = "" : .LeftFooter = "" : .CenterFooter = "" : .RightFooter = "" .LeftMargin = myExcel.Application.InchesToPoints(0.25) : .RightMargin = myExcel.Application.InchesToPoints(0.25) : .TopMargin = myExcel.Application.InchesToPoints(0.75) .BottomMargin = myExcel.Application.InchesToPoints(0.75) : .HeaderMargin = myExcel.Application.InchesToPoints(0.3) : .FooterMargin = myExcel.Application.InchesToPoints(0.3) .PrintHeadings = False : .PrintGridlines = False : .CenterHorizontally = False : .CenterVertically = False : .Draft = False : .FirstPageNumber = xlAutomatic .BlackAndWhite = False : .Zoom = False : .FitToPagesWide = 1 : .FitToPagesTall = 0 : .OddAndEvenPagesHeaderFooter = False : .DifferentFirstPageHeaderFooter = False .ScaleWithDocHeaderFooter = True : .AlignMarginsHeaderFooter = True .EvenPage.LeftHeader.Text = "" : .EvenPage.CenterHeader.Text = "" : .EvenPage.RightHeader.Text = "" : .EvenPage.LeftFooter.Text = "" : .EvenPage.CenterFooter.Text = "" .EvenPage.RightFooter.Text = "" : .FirstPage.LeftHeader.Text = "" : .FirstPage.CenterHeader.Text = "" : .FirstPage.RightHeader.Text = "" : .FirstPage.LeftFooter.Text = "" .FirstPage.CenterFooter.Text = "" : .FirstPage.RightFooter.Text = "" End With : myExcel.Application.PrintCommunication = True xlSheet.Columns("A:A").ColumnWidth = 5 : xlSheet.Columns("B:B").ColumnWidth = 3 : xlSheet.Columns("C:C").ColumnWidth = 16 : xlSheet.Columns("D:D").ColumnWidth = 13 xlSheet.Columns("E:E").ColumnWidth = 13 : xlSheet.Columns("F:F").ColumnWidth = 13 : xlSheet.Columns("G:G").ColumnWidth = 9 : xlSheet.Columns("H:H").ColumnWidth = 4 xlSheet.Columns("I:I").ColumnWidth = 11 : xlSheet.Columns("J:J").ColumnWidth = 5 : xlSheet.Columns("K:K").WrapText = True If allSame Then If 顯示單據_cb.Checked = True Then : xlSheet.Columns("K:K").ColumnWidth = 56.88 : Else : xlSheet.Columns("K:K").ColumnWidth = 66.5 : End If Else If 顯示單據_cb.Checked = True Then : xlSheet.Columns("K:K").ColumnWidth = 40.25 : Else : xlSheet.Columns("K:K").ColumnWidth = 49.88 : End If End If xlSheet.Rows(N2 + 3 & ":" & N2 + 3).RowHeight = 100 xlSheet.Range("A1:J1").Select() With myExcel.Selection.Font : .Name = "標楷體" : .Size = 16 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone End With xlSheet.Range("A1:J1").Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("A2:A3").Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("B2:B3").Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge If 顯示單據_cb.Checked = True Then xlSheet.Range("C2:F3").Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("G2:G3").Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge Else xlSheet.Range("C2:G3").Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge End If xlSheet.Range("H2:H3").Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("I2:I3").Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("J4:J" & N2 + 1).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("A4:A" & N2 + 1).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Rows(2).AutoFit : xlSheet.Rows(2).RowHeight = xlSheet.Rows(2).RowHeight + 1 xlSheet.Rows(3).AutoFit : xlSheet.Rows(3).RowHeight = xlSheet.Rows(3).RowHeight + 1 For i As Integer = 4 To N2 xlSheet.Range("B" & i).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With xlSheet.Range("H" & i).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With If allSame Then If 顯示單據_cb.Checked = True Then xlSheet.Range("C" & i & ":F" & i).Select() With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("G" & i).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With Else xlSheet.Range("C" & i & ":G" & i).Select() With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge End If Else xlSheet.Range("C" & i).Select() With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge If 顯示單據_cb.Checked = True Then xlSheet.Range("D" & i & ":F" & i).Select() With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("G" & i).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With Else xlSheet.Range("D" & i & ":G" & i).Select() With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge End If End If xlSheet.Range("I" & i).Select() With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Rows(i).AutoFit : xlSheet.Rows(i).RowHeight = xlSheet.Rows(i).RowHeight + 5 : xlSheet.Range("K" & i).Value = "" Next i xlSheet.Range("B" & N2 + 1 & ":H" & N2 + 1).Select() With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("I" & N2 + 1).Select() With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With xlSheet.Rows(N2 + 1).AutoFit : xlSheet.Rows(N2 + 1).RowHeight = xlSheet.Rows(N2 + 1).RowHeight + 3 xlSheet.Range("A" & N2 + 2 & ":B" & N2 + 2).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("G" & N2 + 2 & ":H" & N2 + 2).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("I" & N2 + 2 & ":J" & N2 + 2).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("A" & N2 + 3 & ":B" & N2 + 3).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("G" & N2 + 3 & ":H" & N2 + 3).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("I" & N2 + 3 & ":J" & N2 + 3).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With : myExcel.Selection.Merge xlSheet.Range("J2:J3").Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With xlSheet.Range("C" & N2 + 2 & ":F" & N2 + 2).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False End With End Sub Private Sub 公司編號_cb_Click(sender As Object, e As EventArgs) Handles 公司編號_cb.Click CB選擇清單(公司編號_cb, 公司編號_cb.Text) End Sub Private Sub 公司編號_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 公司編號_cb.SelectedIndexChanged Set_清單1() : Set_清單() : Set_清單2() : 彙總計算() : Set_費用清單() End Sub '----------------------滑鼠右鍵-------------------------------------------------------------------------------------------------------------------------------------------------------------------- Private Sub 重新讀取ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 重新讀取ToolStripMenuItem.Click Set_清單1() : Set_清單() : Set_清單2() : 彙總計算() End Sub Private Sub 字體_NUD_ValueChanged(sender As Object, e As EventArgs) Handles 字體_NUD.ValueChanged 單據彙總_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value) 財務彙總_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value) 明細_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value) End Sub Private Sub 支付單列印成EXCEL_MouseEnter(sender As Object, e As EventArgs) Handles 支付單列印成EXCEL.MouseEnter ToolTip1.SetToolTip(Me.支付單列印成EXCEL, "支付單列印成EXCEL") End Sub Private Function 大寫轉換(輸入文本 As String) As String Dim 個位(20), 十位(9), 百位(1), 千位(1), 百萬, 十億, 零, 拾, 百, 仟, 萬, 億, 兆, 答案 As String : Dim 數長 As Integer 答案 = "" : 零 = "" : 拾 = "" : 百 = "" : 仟 = "" : 萬 = "" : 百萬 = "" : 億 = "" : 十億 = "" : 兆 = "" 個位(0) = "零" : 個位(1) = "壹" : 個位(2) = "貳" : 個位(3) = "參" : 個位(4) = "肆" : 個位(5) = "伍" : 個位(6) = "陸" : 個位(7) = "柒" : 個位(8) = "捌" : 個位(9) = "玖" 零 = "零" : 拾 = "拾" : 百 = "百" : 仟 = "仟" : 萬 = "萬" : 億 = "億" : 兆 = "兆" '--------------轉大寫----------------------------------------------------------- Dim 位數(13), 末位數 As String Dim NB As Long = 輸入文本 : Dim NBS As String = NB.ToString() : 數長 = NBS.Length 位數(1) = Strings.Left(NBS, 1) : 末位數 = Strings.Right(NBS, 1) If 數長 >= 2 Then : 位數(2) = Strings.Mid(NBS, 2, 1) : End If : If 數長 >= 3 Then : 位數(3) = Strings.Mid(NBS, 3, 1) : End If If 數長 >= 4 Then : 位數(4) = Strings.Mid(NBS, 4, 1) : End If : If 數長 >= 5 Then : 位數(5) = Strings.Mid(NBS, 5, 1) : End If If 數長 >= 6 Then : 位數(6) = Strings.Mid(NBS, 6, 1) : End If : If 數長 >= 7 Then : 位數(7) = Strings.Mid(NBS, 7, 1) : End If If 數長 >= 8 Then : 位數(8) = Strings.Mid(NBS, 8, 1) : End If : If 數長 >= 9 Then : 位數(9) = Strings.Mid(NBS, 9, 1) : End If If 數長 >= 10 Then : 位數(10) = Strings.Mid(NBS, 10, 1) : End If : If 數長 >= 11 Then : 位數(11) = Strings.Mid(NBS, 11, 1) : End If If 數長 >= 12 Then : 位數(12) = Strings.Mid(NBS, 12, 1) : End If : If 數長 >= 13 Then : 位數(13) = Strings.Mid(NBS, 13, 1) : End If If 數長 = 1 Then : 答案 = 個位(輸入文本) ElseIf 數長 = 2 Then If 末位數 = "0" Then : 答案 = 個位(位數(1)) & 拾 : Else : 答案 = 個位(位數(1)) & 拾 & 個位(末位數) : End If ElseIf 數長 = 3 Then : 答案 = 個位(位數(1)) & 百 If 位數(2) = "0" And 末位數 = "0" Then ElseIf 位數(2) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(末位數) ElseIf 位數(2) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(2)) & 拾 ElseIf 位數(2) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(2)) & 拾 & 個位(末位數) End If ElseIf 數長 = 4 Then : 答案 = 個位(位數(1)) & 仟 If 位數(2) = "0" And 位數(3) = "0" And 末位數 = "0" Then ElseIf 位數(2) = "0" And 位數(3) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(末位數) ElseIf 位數(2) = "0" And 位數(3) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(3)) & 拾 & 個位(末位數) ElseIf 位數(2) = "0" And 位數(3) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(3)) & 拾 ElseIf 位數(2) <> "0" And 位數(3) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(2)) & 百 ElseIf 位數(2) <> "0" And 位數(3) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(2)) & 百 & 零 & 個位(末位數) ElseIf 位數(2) <> "0" And 位數(3) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(2)) & 百 & 個位(位數(3)) & 拾 ElseIf 位數(2) <> "0" And 末位數 <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(2)) & 百 & 個位(位數(3)) & 拾 & 個位(末位數) End If ElseIf 數長 = 5 Then : 答案 = 個位(位數(1)) & 萬 If 位數(2) = "0" And 位數(3) = "0" And 位數(4) = "0" And 末位數 = "0" Then ElseIf 位數(2) = "0" And 位數(3) = "0" And 位數(4) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(末位數) ElseIf 位數(2) = "0" And 位數(3) = "0" And 位數(4) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(4)) & 拾 ElseIf 位數(2) = "0" And 位數(3) = "0" And 位數(4) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(4)) & 拾 & 個位(末位數) ElseIf 位數(2) = "0" And 位數(3) <> "0" And 位數(4) = "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(3)) & 百 ElseIf 位數(2) = "0" And 位數(3) <> "0" And 位數(4) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(3)) & 百 & 零 & 個位(末位數) ElseIf 位數(2) = "0" And 位數(3) <> "0" And 位數(4) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(3)) & 百 & 個位(位數(4)) & 拾 ElseIf 位數(2) = "0" And 位數(3) <> "0" And 位數(4) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(3)) & 百 & 個位(位數(4)) & 拾 & 個位(末位數) ElseIf 位數(2) <> "0" And 位數(3) = "0" And 位數(4) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(2)) & 仟 ElseIf 位數(2) <> "0" And 位數(3) = "0" And 位數(4) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(2)) & 仟 & 零 & 個位(末位數) ElseIf 位數(2) <> "0" And 位數(3) = "0" And 位數(4) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(2)) & 仟 & 零 & 個位(位數(4)) & 拾 ElseIf 位數(2) <> "0" And 位數(3) = "0" And 位數(4) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(2)) & 仟 & 零 & 個位(位數(4)) & 拾 & 個位(末位數) ElseIf 位數(2) <> "0" And 位數(3) <> "0" And 位數(4) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(2)) & 仟 & 個位(位數(3)) & 百 ElseIf 位數(2) <> "0" And 位數(3) <> "0" And 位數(4) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(2)) & 仟 & 個位(位數(3)) & 百 & 零 & 個位(末位數) ElseIf 位數(2) <> "0" And 位數(3) <> "0" And 位數(4) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(2)) & 仟 & 個位(位數(3)) & 百 & 個位(位數(4)) & 拾 ElseIf 位數(2) <> "0" And 位數(3) <> "0" And 位數(4) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(2)) & 仟 & 個位(位數(3)) & 百 & 個位(位數(4)) & 拾 & 個位(末位數) End If ElseIf 數長 = 6 Then If 位數(2) = "0" Then : 答案 = 個位(位數(1)) & 拾 & 萬 : Else : 答案 = 個位(位數(1)) & 拾 & 個位(位數(2)) & 萬 : End If If 位數(3) = "0" And 位數(4) = "0" And 位數(5) = "0" And 末位數 = "0" Then ElseIf 位數(3) = "0" And 位數(4) = "0" And 位數(5) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(末位數) ElseIf 位數(3) = "0" And 位數(4) = "0" And 位數(5) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(5)) & 拾 ElseIf 位數(3) = "0" And 位數(4) = "0" And 位數(5) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(5)) & 拾 & 個位(末位數) ElseIf 位數(3) = "0" And 位數(4) <> "0" And 位數(5) = "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(4)) & 百 ElseIf 位數(3) = "0" And 位數(4) <> "0" And 位數(5) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(4)) & 百 & 零 & 個位(末位數) ElseIf 位數(3) = "0" And 位數(4) <> "0" And 位數(5) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(4)) & 百 & 個位(位數(5)) & 拾 ElseIf 位數(3) = "0" And 位數(4) <> "0" And 位數(5) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(4)) & 百 & 個位(位數(5)) & 拾 & 個位(末位數) ElseIf 位數(3) <> "0" And 位數(4) = "0" And 位數(5) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(3)) & 仟 ElseIf 位數(3) <> "0" And 位數(4) = "0" And 位數(5) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(3)) & 仟 & 零 & 個位(末位數) ElseIf 位數(3) <> "0" And 位數(4) = "0" And 位數(5) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(3)) & 仟 & 零 & 個位(位數(5)) & 拾 ElseIf 位數(3) <> "0" And 位數(4) = "0" And 位數(5) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(3)) & 仟 & 零 & 個位(位數(5)) & 拾 & 個位(末位數) ElseIf 位數(3) <> "0" And 位數(4) <> "0" And 位數(5) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(3)) & 仟 & 個位(位數(4)) & 百 ElseIf 位數(3) <> "0" And 位數(4) <> "0" And 位數(5) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(3)) & 仟 & 個位(位數(4)) & 百 & 零 & 個位(末位數) ElseIf 位數(3) <> "0" And 位數(4) <> "0" And 位數(5) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(3)) & 仟 & 個位(位數(4)) & 百 & 個位(位數(5)) & 拾 ElseIf 位數(3) <> "0" And 位數(4) <> "0" And 位數(5) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(3)) & 仟 & 個位(位數(4)) & 百 & 個位(位數(5)) & 拾 & 個位(末位數) End If ElseIf 數長 = 7 Then : 答案 = 個位(位數(1)) & 百 If 位數(2) = "0" And 位數(3) = "0" Then : 答案 &= 萬 ElseIf 位數(2) = "0" And 位數(3) <> "0" Then : 答案 &= 零 & 個位(位數(3)) & 萬 ElseIf 位數(2) <> "0" And 位數(3) = "0" Then : 答案 &= 個位(位數(2)) & 拾 & 萬 ElseIf 位數(2) <> "0" And 位數(3) <> "0" Then : 答案 &= 個位(位數(2)) & 拾 & 個位(位數(3)) & 萬 End If If 位數(4) = "0" And 位數(5) = "0" And 位數(6) = "0" And 末位數 = "0" Then ElseIf 位數(4) = "0" And 位數(5) = "0" And 位數(6) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(末位數) ElseIf 位數(4) = "0" And 位數(5) = "0" And 位數(6) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(6)) & 拾 ElseIf 位數(4) = "0" And 位數(5) = "0" And 位數(6) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(6)) & 拾 & 個位(末位數) ElseIf 位數(4) = "0" And 位數(5) <> "0" And 位數(6) = "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(5)) & 百 ElseIf 位數(4) = "0" And 位數(5) <> "0" And 位數(6) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(5)) & 百 & 零 & 個位(末位數) ElseIf 位數(4) = "0" And 位數(5) <> "0" And 位數(6) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(5)) & 百 & 個位(位數(6)) & 拾 ElseIf 位數(4) = "0" And 位數(5) <> "0" And 位數(6) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(5)) & 百 & 個位(位數(6)) & 拾 & 個位(末位數) ElseIf 位數(4) <> "0" And 位數(5) = "0" And 位數(6) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(4)) & 仟 ElseIf 位數(4) <> "0" And 位數(5) = "0" And 位數(6) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(4)) & 仟 & 零 & 個位(末位數) ElseIf 位數(4) <> "0" And 位數(5) = "0" And 位數(6) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(4)) & 仟 & 零 & 個位(位數(6)) & 拾 ElseIf 位數(4) <> "0" And 位數(5) = "0" And 位數(6) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(4)) & 仟 & 零 & 個位(位數(6)) & 拾 & 個位(末位數) ElseIf 位數(4) <> "0" And 位數(5) <> "0" And 位數(6) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(4)) & 仟 & 個位(位數(5)) & 百 ElseIf 位數(4) <> "0" And 位數(5) <> "0" And 位數(6) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(4)) & 仟 & 個位(位數(5)) & 百 & 零 & 個位(末位數) ElseIf 位數(4) <> "0" And 位數(5) <> "0" And 位數(6) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(4)) & 仟 & 個位(位數(5)) & 百 & 個位(位數(6)) & 拾 ElseIf 位數(4) <> "0" And 位數(5) <> "0" And 位數(6) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(4)) & 仟 & 個位(位數(5)) & 百 & 個位(位數(6)) & 拾 & 個位(末位數) End If ElseIf 數長 = 8 Then : 答案 = 個位(位數(1)) & 仟 If 位數(2) = "0" And 位數(3) = "0" And 位數(4) = "0" Then : 答案 &= 萬 ElseIf 位數(2) = "0" And 位數(3) = "0" And 位數(4) <> "0" Then : 答案 &= 零 & 個位(位數(4)) & 萬 ElseIf 位數(2) = "0" And 位數(3) <> "0" And 位數(4) <> "0" Then : 答案 &= 零 & 個位(位數(3)) & 拾 & 個位(位數(4)) & 萬 ElseIf 位數(2) = "0" And 位數(3) <> "0" And 位數(4) = "0" Then : 答案 &= 零 & 個位(位數(3)) & 拾 & 萬 ElseIf 位數(2) <> "0" And 位數(3) = "0" And 位數(4) = "0" Then : 答案 &= 個位(位數(2)) & 百 & 萬 ElseIf 位數(2) <> "0" And 位數(3) = "0" And 位數(4) <> "0" Then : 答案 &= 個位(位數(2)) & 百 & 零 & 個位(位數(4)) & 萬 ElseIf 位數(2) <> "0" And 位數(3) <> "0" And 位數(4) = "0" Then : 答案 &= 個位(位數(2)) & 百 & 個位(位數(3)) & 拾 & 萬 ElseIf 位數(2) <> "0" And 位數(4) <> "0" And 位數(4) <> "0" Then : 答案 &= 個位(位數(2)) & 百 & 個位(位數(3)) & 拾 & 個位(位數(4)) & 萬 End If If 位數(5) = "0" And 位數(6) = "0" And 位數(7) = "0" And 末位數 = "0" Then ElseIf 位數(5) = "0" And 位數(6) = "0" And 位數(7) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(末位數) ElseIf 位數(5) = "0" And 位數(6) = "0" And 位數(7) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(7)) & 拾 ElseIf 位數(5) = "0" And 位數(6) = "0" And 位數(7) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(7)) & 拾 & 個位(末位數) ElseIf 位數(5) = "0" And 位數(6) <> "0" And 位數(7) = "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(6)) & 百 ElseIf 位數(5) = "0" And 位數(6) <> "0" And 位數(7) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(6)) & 百 & 零 & 個位(末位數) ElseIf 位數(5) = "0" And 位數(6) <> "0" And 位數(7) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(6)) & 百 & 個位(位數(7)) & 拾 ElseIf 位數(5) = "0" And 位數(6) <> "0" And 位數(7) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(6)) & 百 & 個位(位數(7)) & 拾 & 個位(末位數) ElseIf 位數(5) <> "0" And 位數(6) = "0" And 位數(7) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(5)) & 仟 ElseIf 位數(5) <> "0" And 位數(6) = "0" And 位數(7) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(5)) & 仟 & 零 & 個位(末位數) ElseIf 位數(5) <> "0" And 位數(6) = "0" And 位數(7) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(5)) & 仟 & 零 & 個位(位數(7)) & 拾 ElseIf 位數(5) <> "0" And 位數(6) = "0" And 位數(7) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(5)) & 仟 & 零 & 個位(位數(7)) & 拾 & 個位(末位數) ElseIf 位數(5) <> "0" And 位數(6) <> "0" And 位數(7) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(5)) & 仟 & 個位(位數(6)) & 百 ElseIf 位數(5) <> "0" And 位數(6) <> "0" And 位數(7) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(5)) & 仟 & 個位(位數(6)) & 百 & 零 & 個位(末位數) ElseIf 位數(5) <> "0" And 位數(6) <> "0" And 位數(7) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(5)) & 仟 & 個位(位數(6)) & 百 & 個位(位數(7)) & 拾 ElseIf 位數(5) <> "0" And 位數(6) <> "0" And 位數(7) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(5)) & 仟 & 個位(位數(6)) & 百 & 個位(位數(7)) & 拾 & 個位(末位數) End If ElseIf 數長 = 9 Then : 答案 = 個位(位數(1)) & 億 If 位數(2) = "0" And 位數(3) = "0" And 位數(4) = "0" And 位數(5) = "0" Then ElseIf 位數(2) = "0" And 位數(3) = "0" And 位數(4) = "0" And 位數(5) <> "0" Then : 答案 &= 零 & 個位(位數(5)) & 萬 ElseIf 位數(2) = "0" And 位數(3) = "0" And 位數(4) <> "0" And 位數(5) = "0" Then : 答案 &= 零 & 個位(位數(4)) & 拾 & 萬 ElseIf 位數(2) = "0" And 位數(3) = "0" And 位數(4) <> "0" And 位數(5) <> "0" Then : 答案 &= 零 & 個位(位數(4)) & 拾 & 個位(位數(5)) & 萬 ElseIf 位數(2) = "0" And 位數(3) <> "0" And 位數(4) = "0" And 位數(5) = "0" Then : 答案 &= 零 & 個位(位數(3)) & 百 & 萬 ElseIf 位數(2) = "0" And 位數(3) <> "0" And 位數(4) = "0" And 位數(5) <> "0" Then : 答案 &= 零 & 個位(位數(3)) & 百 & 零 & 個位(位數(5)) & 萬 ElseIf 位數(2) = "0" And 位數(3) <> "0" And 位數(4) <> "0" And 位數(5) = "0" Then : 答案 &= 零 & 個位(位數(3)) & 百 & 個位(位數(4)) & 拾 & 萬 ElseIf 位數(2) = "0" And 位數(3) <> "0" And 位數(4) <> "0" And 位數(5) <> "0" Then : 答案 &= 零 & 個位(位數(3)) & 百 & 個位(位數(4)) & 拾 & 個位(位數(5)) & 萬 ElseIf 位數(2) <> "0" And 位數(3) = "0" And 位數(4) = "0" And 位數(5) = "0" Then : 答案 &= 個位(位數(2)) & 仟 & 萬 ElseIf 位數(2) <> "0" And 位數(3) = "0" And 位數(4) = "0" And 位數(5) <> "0" Then : 答案 &= 個位(位數(2)) & 仟 & 零 & 個位(位數(5)) & 萬 ElseIf 位數(2) <> "0" And 位數(3) = "0" And 位數(4) <> "0" And 位數(5) = "0" Then : 答案 &= 個位(位數(2)) & 仟 & 零 & 個位(位數(4)) & 拾 & 萬 ElseIf 位數(2) <> "0" And 位數(3) = "0" And 位數(4) <> "0" And 位數(5) <> "0" Then : 答案 &= 個位(位數(2)) & 仟 & 零 & 個位(位數(4)) & 拾 & 個位(位數(5)) & 萬 ElseIf 位數(2) <> "0" And 位數(3) <> "0" And 位數(4) = "0" And 位數(5) = "0" Then : 答案 &= 個位(位數(2)) & 仟 & 個位(位數(3)) & 百 & 萬 ElseIf 位數(2) <> "0" And 位數(3) <> "0" And 位數(4) = "0" And 位數(5) <> "0" Then : 答案 &= 個位(位數(2)) & 仟 & 個位(位數(3)) & 百 & 零 & 個位(位數(5)) & 萬 ElseIf 位數(2) <> "0" And 位數(3) <> "0" And 位數(4) <> "0" And 位數(5) = "0" Then : 答案 &= 個位(位數(2)) & 仟 & 個位(位數(3)) & 百 & 個位(位數(4)) & 拾 & 萬 ElseIf 位數(2) <> "0" And 位數(3) <> "0" And 位數(4) <> "0" And 位數(5) <> "0" Then : 答案 &= 個位(位數(2)) & 仟 & 個位(位數(3)) & 百 & 個位(位數(4)) & 拾 & 個位(位數(5)) & 萬 End If If 位數(6) = "0" And 位數(7) = "0" And 位數(8) = "0" And 末位數 = "0" Then ElseIf 位數(6) = "0" And 位數(7) = "0" And 位數(8) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(末位數) ElseIf 位數(6) = "0" And 位數(7) = "0" And 位數(8) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(8)) & 拾 ElseIf 位數(6) = "0" And 位數(7) = "0" And 位數(8) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(8)) & 拾 & 個位(末位數) ElseIf 位數(6) = "0" And 位數(7) <> "0" And 位數(8) = "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(7)) & 百 ElseIf 位數(6) = "0" And 位數(7) <> "0" And 位數(8) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(7)) & 百 & 零 & 個位(末位數) ElseIf 位數(6) = "0" And 位數(7) <> "0" And 位數(8) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(7)) & 百 & 個位(位數(8)) & 拾 ElseIf 位數(6) = "0" And 位數(7) <> "0" And 位數(8) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(7)) & 百 & 個位(位數(8)) & 拾 & 個位(末位數) ElseIf 位數(6) <> "0" And 位數(7) = "0" And 位數(8) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(6)) & 仟 ElseIf 位數(6) <> "0" And 位數(7) = "0" And 位數(8) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(6)) & 仟 & 零 & 個位(末位數) ElseIf 位數(6) <> "0" And 位數(7) = "0" And 位數(8) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(6)) & 仟 & 零 & 個位(位數(8)) & 拾 ElseIf 位數(6) <> "0" And 位數(7) = "0" And 位數(8) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(6)) & 仟 & 零 & 個位(位數(8)) & 拾 & 個位(末位數) ElseIf 位數(6) <> "0" And 位數(7) <> "0" And 位數(8) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(6)) & 仟 & 個位(位數(7)) & 百 ElseIf 位數(6) <> "0" And 位數(7) <> "0" And 位數(8) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(6)) & 仟 & 個位(位數(7)) & 百 & 零 & 個位(末位數) ElseIf 位數(6) <> "0" And 位數(7) <> "0" And 位數(8) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(6)) & 仟 & 個位(位數(7)) & 百 & 個位(位數(8)) & 拾 ElseIf 位數(6) <> "0" And 位數(7) <> "0" And 位數(8) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(6)) & 仟 & 個位(位數(7)) & 百 & 個位(位數(8)) & 拾 & 個位(末位數) End If ElseIf 數長 = 10 Then If 位數(2) = "0" Then : 答案 = 個位(位數(1)) & 拾 & 億 : Else : 答案 = 個位(位數(1)) & 拾 & 個位(位數(2)) & 億 : End If If 位數(3) = "0" And 位數(4) = "0" And 位數(5) = "0" And 位數(6) = "0" Then ElseIf 位數(3) = "0" And 位數(4) = "0" And 位數(5) = "0" And 位數(6) <> "0" Then : 答案 &= 零 & 個位(位數(6)) & 萬 ElseIf 位數(3) = "0" And 位數(4) = "0" And 位數(5) <> "0" And 位數(6) = "0" Then : 答案 &= 零 & 個位(位數(5)) & 拾 & 萬 ElseIf 位數(3) = "0" And 位數(4) = "0" And 位數(5) <> "0" And 位數(6) <> "0" Then : 答案 &= 零 & 個位(位數(5)) & 拾 & 個位(位數(6)) & 萬 ElseIf 位數(3) = "0" And 位數(4) <> "0" And 位數(5) = "0" And 位數(6) = "0" Then : 答案 &= 零 & 個位(位數(4)) & 百 & 萬 ElseIf 位數(3) = "0" And 位數(4) <> "0" And 位數(5) = "0" And 位數(6) <> "0" Then : 答案 &= 零 & 個位(位數(4)) & 百 & 零 & 個位(位數(6)) & 萬 ElseIf 位數(3) = "0" And 位數(4) <> "0" And 位數(5) <> "0" And 位數(6) = "0" Then : 答案 &= 零 & 個位(位數(4)) & 百 & 個位(位數(5)) & 拾 & 萬 ElseIf 位數(3) = "0" And 位數(4) <> "0" And 位數(5) <> "0" And 位數(6) <> "0" Then : 答案 &= 零 & 個位(位數(4)) & 百 & 個位(位數(5)) & 拾 & 個位(位數(6)) & 萬 ElseIf 位數(3) <> "0" And 位數(4) = "0" And 位數(5) = "0" And 位數(6) = "0" Then : 答案 &= 個位(位數(3)) & 仟 & 萬 ElseIf 位數(3) <> "0" And 位數(4) = "0" And 位數(5) = "0" And 位數(6) <> "0" Then : 答案 &= 個位(位數(3)) & 仟 & 零 & 個位(位數(6)) & 萬 ElseIf 位數(3) <> "0" And 位數(4) = "0" And 位數(5) <> "0" And 位數(6) = "0" Then : 答案 &= 個位(位數(3)) & 仟 & 零 & 個位(位數(5)) & 拾 & 萬 ElseIf 位數(3) <> "0" And 位數(4) = "0" And 位數(5) <> "0" And 位數(6) <> "0" Then : 答案 &= 個位(位數(3)) & 仟 & 零 & 個位(位數(5)) & 拾 & 個位(位數(6)) & 萬 ElseIf 位數(3) <> "0" And 位數(4) <> "0" And 位數(5) = "0" And 位數(6) = "0" Then : 答案 &= 個位(位數(3)) & 仟 & 個位(位數(4)) & 百 & 萬 ElseIf 位數(3) <> "0" And 位數(4) <> "0" And 位數(5) = "0" And 位數(6) <> "0" Then : 答案 &= 個位(位數(3)) & 仟 & 個位(位數(4)) & 百 & 零 & 個位(位數(6)) & 萬 ElseIf 位數(3) <> "0" And 位數(4) <> "0" And 位數(5) <> "0" And 位數(6) = "0" Then : 答案 &= 個位(位數(3)) & 仟 & 個位(位數(4)) & 百 & 個位(位數(5)) & 拾 & 萬 ElseIf 位數(3) <> "0" And 位數(4) <> "0" And 位數(5) <> "0" And 位數(6) <> "0" Then : 答案 &= 個位(位數(3)) & 仟 & 個位(位數(4)) & 百 & 個位(位數(5)) & 拾 & 個位(位數(6)) & 萬 End If If 位數(7) = "0" And 位數(8) = "0" And 位數(9) = "0" And 末位數 = "0" Then ElseIf 位數(7) = "0" And 位數(8) = "0" And 位數(9) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(末位數) ElseIf 位數(7) = "0" And 位數(8) = "0" And 位數(9) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(9)) & 拾 ElseIf 位數(7) = "0" And 位數(8) = "0" And 位數(9) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(9)) & 拾 & 個位(末位數) ElseIf 位數(7) = "0" And 位數(8) <> "0" And 位數(9) = "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(8)) & 百 ElseIf 位數(7) = "0" And 位數(8) <> "0" And 位數(9) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(8)) & 百 & 零 & 個位(末位數) ElseIf 位數(7) = "0" And 位數(8) <> "0" And 位數(9) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(8)) & 百 & 個位(位數(9)) & 拾 ElseIf 位數(7) = "0" And 位數(8) <> "0" And 位數(9) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(8)) & 百 & 個位(位數(9)) & 拾 & 個位(末位數) ElseIf 位數(7) <> "0" And 位數(8) = "0" And 位數(9) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(7)) & 仟 ElseIf 位數(7) <> "0" And 位數(8) = "0" And 位數(9) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(7)) & 仟 & 零 & 個位(末位數) ElseIf 位數(7) <> "0" And 位數(8) = "0" And 位數(9) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(7)) & 仟 & 零 & 個位(位數(9)) & 拾 ElseIf 位數(7) <> "0" And 位數(8) = "0" And 位數(9) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(7)) & 仟 & 零 & 個位(位數(9)) & 拾 & 個位(末位數) ElseIf 位數(7) <> "0" And 位數(8) <> "0" And 位數(9) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(7)) & 仟 & 個位(位數(8)) & 百 ElseIf 位數(7) <> "0" And 位數(8) <> "0" And 位數(9) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(7)) & 仟 & 個位(位數(8)) & 百 & 零 & 個位(末位數) ElseIf 位數(7) <> "0" And 位數(8) <> "0" And 位數(9) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(7)) & 仟 & 個位(位數(8)) & 百 & 個位(位數(9)) & 拾 ElseIf 位數(7) <> "0" And 位數(8) <> "0" And 位數(9) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(7)) & 仟 & 個位(位數(8)) & 百 & 個位(位數(9)) & 拾 & 個位(末位數) End If ElseIf 數長 = 11 Then : 答案 = 個位(位數(1)) & 百 If 位數(2) = "0" And 位數(3) = "0" Then : 答案 &= 億 ElseIf 位數(2) = "0" And 位數(3) <> "0" Then : 答案 &= 零 & 個位(位數(3)) & 億 ElseIf 位數(2) <> "0" And 位數(3) = "0" Then : 答案 &= 個位(位數(2)) & 拾 & 億 ElseIf 位數(2) <> "0" And 位數(3) <> "0" Then : 答案 &= 個位(位數(2)) & 拾 & 個位(位數(3)) & 億 End If If 位數(4) = "0" And 位數(5) = "0" And 位數(6) = "0" And 位數(7) = "0" Then ElseIf 位數(4) = "0" And 位數(5) = "0" And 位數(6) = "0" And 位數(7) <> "0" Then : 答案 &= 零 & 個位(位數(7)) & 萬 ElseIf 位數(4) = "0" And 位數(5) = "0" And 位數(6) <> "0" And 位數(7) = "0" Then : 答案 &= 零 & 個位(位數(6)) & 拾 & 萬 ElseIf 位數(4) = "0" And 位數(5) = "0" And 位數(6) <> "0" And 位數(7) <> "0" Then : 答案 &= 零 & 個位(位數(6)) & 拾 & 個位(位數(7)) & 萬 ElseIf 位數(4) = "0" And 位數(5) <> "0" And 位數(6) = "0" And 位數(7) = "0" Then : 答案 &= 零 & 個位(位數(5)) & 百 & 萬 ElseIf 位數(4) = "0" And 位數(5) <> "0" And 位數(6) = "0" And 位數(7) <> "0" Then : 答案 &= 零 & 個位(位數(5)) & 百 & 零 & 個位(位數(7)) & 萬 ElseIf 位數(4) = "0" And 位數(5) <> "0" And 位數(6) <> "0" And 位數(7) = "0" Then : 答案 &= 零 & 個位(位數(5)) & 百 & 個位(位數(6)) & 拾 & 萬 ElseIf 位數(4) = "0" And 位數(5) <> "0" And 位數(6) <> "0" And 位數(7) <> "0" Then : 答案 &= 零 & 個位(位數(5)) & 百 & 個位(位數(6)) & 拾 & 個位(位數(7)) & 萬 ElseIf 位數(4) <> "0" And 位數(5) = "0" And 位數(6) = "0" And 位數(7) = "0" Then : 答案 &= 個位(位數(4)) & 仟 & 萬 ElseIf 位數(4) <> "0" And 位數(5) = "0" And 位數(6) = "0" And 位數(7) <> "0" Then : 答案 &= 個位(位數(4)) & 仟 & 零 & 個位(位數(7)) & 萬 ElseIf 位數(4) <> "0" And 位數(5) = "0" And 位數(6) <> "0" And 位數(7) = "0" Then : 答案 &= 個位(位數(4)) & 仟 & 零 & 個位(位數(6)) & 拾 & 萬 ElseIf 位數(4) <> "0" And 位數(5) = "0" And 位數(6) <> "0" And 位數(7) <> "0" Then : 答案 &= 個位(位數(4)) & 仟 & 零 & 個位(位數(6)) & 拾 & 個位(位數(7)) & 萬 ElseIf 位數(4) <> "0" And 位數(5) <> "0" And 位數(6) = "0" And 位數(7) = "0" Then : 答案 &= 個位(位數(4)) & 仟 & 個位(位數(5)) & 百 & 萬 ElseIf 位數(4) <> "0" And 位數(5) <> "0" And 位數(6) = "0" And 位數(7) <> "0" Then : 答案 &= 個位(位數(4)) & 仟 & 個位(位數(5)) & 百 & 零 & 個位(位數(7)) & 萬 ElseIf 位數(4) <> "0" And 位數(5) <> "0" And 位數(6) <> "0" And 位數(7) = "0" Then : 答案 &= 個位(位數(4)) & 仟 & 個位(位數(5)) & 百 & 個位(位數(6)) & 拾 & 萬 ElseIf 位數(4) <> "0" And 位數(5) <> "0" And 位數(6) <> "0" And 位數(7) <> "0" Then : 答案 &= 個位(位數(4)) & 仟 & 個位(位數(5)) & 百 & 個位(位數(6)) & 拾 & 個位(位數(7)) & 萬 End If If 位數(8) = "0" And 位數(9) = "0" And 位數(10) = "0" And 末位數 = "0" Then ElseIf 位數(8) = "0" And 位數(9) = "0" And 位數(10) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(末位數) ElseIf 位數(8) = "0" And 位數(9) = "0" And 位數(10) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(10)) & 拾 ElseIf 位數(8) = "0" And 位數(9) = "0" And 位數(10) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(10)) & 拾 & 個位(末位數) ElseIf 位數(8) = "0" And 位數(9) <> "0" And 位數(10) = "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(9)) & 百 ElseIf 位數(8) = "0" And 位數(9) <> "0" And 位數(10) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(9)) & 百 & 零 & 個位(末位數) ElseIf 位數(8) = "0" And 位數(9) <> "0" And 位數(10) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(9)) & 百 & 個位(位數(10)) & 拾 ElseIf 位數(8) = "0" And 位數(9) <> "0" And 位數(10) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(9)) & 百 & 個位(位數(10)) & 拾 & 個位(末位數) ElseIf 位數(8) <> "0" And 位數(9) = "0" And 位數(10) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(8)) & 仟 ElseIf 位數(8) <> "0" And 位數(9) = "0" And 位數(10) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(8)) & 仟 & 零 & 個位(末位數) ElseIf 位數(8) <> "0" And 位數(9) = "0" And 位數(10) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(8)) & 仟 & 零 & 個位(位數(10)) & 拾 ElseIf 位數(8) <> "0" And 位數(9) = "0" And 位數(10) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(8)) & 仟 & 零 & 個位(位數(10)) & 拾 & 個位(末位數) ElseIf 位數(8) <> "0" And 位數(9) <> "0" And 位數(10) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(8)) & 仟 & 個位(位數(9)) & 百 ElseIf 位數(8) <> "0" And 位數(9) <> "0" And 位數(10) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(8)) & 仟 & 個位(位數(9)) & 百 & 零 & 個位(末位數) ElseIf 位數(8) <> "0" And 位數(9) <> "0" And 位數(10) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(8)) & 仟 & 個位(位數(9)) & 百 & 個位(位數(10)) & 拾 ElseIf 位數(8) <> "0" And 位數(9) <> "0" And 位數(10) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(8)) & 仟 & 個位(位數(9)) & 百 & 個位(位數(10)) & 拾 & 個位(末位數) End If ElseIf 數長 = 12 Then : 答案 = 個位(位數(1)) & 仟 If 位數(2) = "0" And 位數(3) = "0" And 位數(4) = "0" Then : 答案 &= 億 ElseIf 位數(2) = "0" And 位數(3) = "0" And 位數(4) <> "0" Then : 答案 &= 零 & 個位(位數(4)) & 億 ElseIf 位數(2) = "0" And 位數(3) <> "0" And 位數(4) <> "0" Then : 答案 &= 零 & 個位(位數(3)) & 拾 & 個位(位數(4)) & 億 ElseIf 位數(2) = "0" And 位數(3) <> "0" And 位數(4) = "0" Then : 答案 &= 零 & 個位(位數(3)) & 拾 & 億 ElseIf 位數(2) <> "0" And 位數(3) = "0" And 位數(4) = "0" Then : 答案 &= 個位(位數(2)) & 百 & 億 ElseIf 位數(2) <> "0" And 位數(3) = "0" And 位數(4) <> "0" Then : 答案 &= 個位(位數(2)) & 百 & 零 & 個位(位數(4)) & 億 ElseIf 位數(2) <> "0" And 位數(3) <> "0" And 位數(4) = "0" Then : 答案 &= 個位(位數(2)) & 百 & 個位(位數(3)) & 拾 & 億 ElseIf 位數(2) <> "0" And 位數(4) <> "0" And 位數(4) <> "0" Then : 答案 &= 個位(位數(2)) & 百 & 個位(位數(3)) & 拾 & 個位(位數(4)) & 億 End If If 位數(5) = "0" And 位數(6) = "0" And 位數(7) = "0" And 位數(8) = "0" Then ElseIf 位數(5) = "0" And 位數(6) = "0" And 位數(7) = "0" And 位數(8) <> "0" Then : 答案 &= 零 & 個位(位數(8)) & 萬 ElseIf 位數(5) = "0" And 位數(6) = "0" And 位數(7) <> "0" And 位數(8) = "0" Then : 答案 &= 零 & 個位(位數(7)) & 拾 & 萬 ElseIf 位數(5) = "0" And 位數(6) = "0" And 位數(7) <> "0" And 位數(8) <> "0" Then : 答案 &= 零 & 個位(位數(7)) & 拾 & 個位(位數(8)) & 萬 ElseIf 位數(5) = "0" And 位數(6) <> "0" And 位數(7) = "0" And 位數(8) = "0" Then : 答案 &= 零 & 個位(位數(6)) & 百 & 萬 ElseIf 位數(5) = "0" And 位數(6) <> "0" And 位數(7) = "0" And 位數(8) <> "0" Then : 答案 &= 零 & 個位(位數(6)) & 百 & 零 & 個位(位數(8)) & 萬 ElseIf 位數(5) = "0" And 位數(6) <> "0" And 位數(7) <> "0" And 位數(8) = "0" Then : 答案 &= 零 & 個位(位數(6)) & 百 & 個位(位數(7)) & 拾 & 萬 ElseIf 位數(5) = "0" And 位數(6) <> "0" And 位數(7) <> "0" And 位數(8) <> "0" Then : 答案 &= 零 & 個位(位數(6)) & 百 & 個位(位數(7)) & 拾 & 個位(位數(8)) & 萬 ElseIf 位數(5) <> "0" And 位數(6) = "0" And 位數(7) = "0" And 位數(8) = "0" Then : 答案 &= 個位(位數(5)) & 仟 & 萬 ElseIf 位數(5) <> "0" And 位數(6) = "0" And 位數(7) = "0" And 位數(8) <> "0" Then : 答案 &= 個位(位數(5)) & 仟 & 零 & 個位(位數(8)) & 萬 ElseIf 位數(5) <> "0" And 位數(6) = "0" And 位數(7) <> "0" And 位數(8) = "0" Then : 答案 &= 個位(位數(5)) & 仟 & 零 & 個位(位數(7)) & 拾 & 萬 ElseIf 位數(5) <> "0" And 位數(6) = "0" And 位數(7) <> "0" And 位數(8) <> "0" Then : 答案 &= 個位(位數(5)) & 仟 & 零 & 個位(位數(7)) & 拾 & 個位(位數(8)) & 萬 ElseIf 位數(5) <> "0" And 位數(6) <> "0" And 位數(7) = "0" And 位數(8) = "0" Then : 答案 &= 個位(位數(5)) & 仟 & 個位(位數(6)) & 百 & 萬 ElseIf 位數(5) <> "0" And 位數(6) <> "0" And 位數(7) = "0" And 位數(8) <> "0" Then : 答案 &= 個位(位數(5)) & 仟 & 個位(位數(6)) & 百 & 零 & 個位(位數(8)) & 萬 ElseIf 位數(5) <> "0" And 位數(6) <> "0" And 位數(7) <> "0" And 位數(8) = "0" Then : 答案 &= 個位(位數(5)) & 仟 & 個位(位數(6)) & 百 & 個位(位數(7)) & 拾 & 萬 ElseIf 位數(5) <> "0" And 位數(6) <> "0" And 位數(7) <> "0" And 位數(8) <> "0" Then : 答案 &= 個位(位數(5)) & 仟 & 個位(位數(6)) & 百 & 個位(位數(7)) & 拾 & 個位(位數(8)) & 萬 End If If 位數(9) = "0" And 位數(10) = "0" And 位數(11) = "0" And 末位數 = "0" Then ElseIf 位數(9) = "0" And 位數(10) = "0" And 位數(11) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(末位數) ElseIf 位數(9) = "0" And 位數(10) = "0" And 位數(11) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(11)) & 拾 ElseIf 位數(9) = "0" And 位數(10) = "0" And 位數(11) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(11)) & 拾 & 個位(末位數) ElseIf 位數(9) = "0" And 位數(10) <> "0" And 位數(11) = "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(10)) & 百 ElseIf 位數(9) = "0" And 位數(10) <> "0" And 位數(11) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(10)) & 百 & 零 & 個位(末位數) ElseIf 位數(9) = "0" And 位數(10) <> "0" And 位數(11) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(10)) & 百 & 個位(位數(11)) & 拾 ElseIf 位數(9) = "0" And 位數(10) <> "0" And 位數(11) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(10)) & 百 & 個位(位數(11)) & 拾 & 個位(末位數) ElseIf 位數(9) <> "0" And 位數(10) = "0" And 位數(11) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(9)) & 仟 ElseIf 位數(9) <> "0" And 位數(10) = "0" And 位數(11) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(9)) & 仟 & 零 & 個位(末位數) ElseIf 位數(9) <> "0" And 位數(10) = "0" And 位數(11) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(9)) & 仟 & 零 & 個位(位數(11)) & 拾 ElseIf 位數(9) <> "0" And 位數(10) = "0" And 位數(11) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(9)) & 仟 & 零 & 個位(位數(11)) & 拾 & 個位(末位數) ElseIf 位數(9) <> "0" And 位數(10) <> "0" And 位數(11) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(9)) & 仟 & 個位(位數(10)) & 百 ElseIf 位數(9) <> "0" And 位數(10) <> "0" And 位數(11) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(9)) & 仟 & 個位(位數(10)) & 百 & 零 & 個位(末位數) ElseIf 位數(9) <> "0" And 位數(10) <> "0" And 位數(11) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(9)) & 仟 & 個位(位數(10)) & 百 & 個位(位數(11)) & 拾 ElseIf 位數(9) <> "0" And 位數(10) <> "0" And 位數(11) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(9)) & 仟 & 個位(位數(10)) & 百 & 個位(位數(11)) & 拾 & 個位(末位數) End If ElseIf 數長 = 13 Then : 答案 = 個位(位數(1)) & 兆 : 答案 &= 個位(位數(2)) & 仟 If 位數(3) = "0" And 位數(4) = "0" And 位數(5) = "0" Then : 答案 &= 億 ElseIf 位數(3) = "0" And 位數(4) = "0" And 位數(5) <> "0" Then : 答案 &= 零 & 個位(位數(5)) & 億 ElseIf 位數(3) = "0" And 位數(4) <> "0" And 位數(5) <> "0" Then : 答案 &= 零 & 個位(位數(4)) & 拾 & 個位(位數(5)) & 億 ElseIf 位數(3) = "0" And 位數(4) <> "0" And 位數(5) = "0" Then : 答案 &= 零 & 個位(位數(4)) & 拾 & 億 ElseIf 位數(3) <> "0" And 位數(4) = "0" And 位數(5) = "0" Then : 答案 &= 個位(位數(3)) & 百 & 億 ElseIf 位數(3) <> "0" And 位數(4) = "0" And 位數(5) <> "0" Then : 答案 &= 個位(位數(3)) & 百 & 零 & 個位(位數(5)) & 億 ElseIf 位數(3) <> "0" And 位數(4) <> "0" And 位數(5) = "0" Then : 答案 &= 個位(位數(3)) & 百 & 個位(位數(4)) & 拾 & 億 ElseIf 位數(3) <> "0" And 位數(5) <> "0" And 位數(5) <> "0" Then : 答案 &= 個位(位數(3)) & 百 & 個位(位數(4)) & 拾 & 個位(位數(5)) & 億 End If If 位數(6) = "0" And 位數(7) = "0" And 位數(8) = "0" And 位數(9) = "0" Then ElseIf 位數(6) = "0" And 位數(7) = "0" And 位數(8) = "0" And 位數(9) <> "0" Then : 答案 &= 零 & 個位(位數(9)) & 萬 ElseIf 位數(6) = "0" And 位數(7) = "0" And 位數(8) <> "0" And 位數(9) = "0" Then : 答案 &= 零 & 個位(位數(8)) & 拾 & 萬 ElseIf 位數(6) = "0" And 位數(7) = "0" And 位數(8) <> "0" And 位數(9) <> "0" Then : 答案 &= 零 & 個位(位數(8)) & 拾 & 個位(位數(9)) & 萬 ElseIf 位數(6) = "0" And 位數(7) <> "0" And 位數(8) = "0" And 位數(9) = "0" Then : 答案 &= 零 & 個位(位數(7)) & 百 & 萬 ElseIf 位數(6) = "0" And 位數(7) <> "0" And 位數(8) = "0" And 位數(9) <> "0" Then : 答案 &= 零 & 個位(位數(7)) & 百 & 零 & 個位(位數(9)) & 萬 ElseIf 位數(6) = "0" And 位數(7) <> "0" And 位數(8) <> "0" And 位數(9) = "0" Then : 答案 &= 零 & 個位(位數(7)) & 百 & 個位(位數(8)) & 拾 & 萬 ElseIf 位數(6) = "0" And 位數(7) <> "0" And 位數(8) <> "0" And 位數(9) <> "0" Then : 答案 &= 零 & 個位(位數(7)) & 百 & 個位(位數(8)) & 拾 & 個位(位數(9)) & 萬 ElseIf 位數(6) <> "0" And 位數(7) = "0" And 位數(8) = "0" And 位數(9) = "0" Then : 答案 &= 個位(位數(6)) & 仟 & 萬 ElseIf 位數(6) <> "0" And 位數(7) = "0" And 位數(8) = "0" And 位數(9) <> "0" Then : 答案 &= 個位(位數(6)) & 仟 & 零 & 個位(位數(9)) & 萬 ElseIf 位數(6) <> "0" And 位數(7) = "0" And 位數(8) <> "0" And 位數(9) = "0" Then : 答案 &= 個位(位數(6)) & 仟 & 零 & 個位(位數(8)) & 拾 & 萬 ElseIf 位數(6) <> "0" And 位數(7) = "0" And 位數(8) <> "0" And 位數(9) <> "0" Then : 答案 &= 個位(位數(6)) & 仟 & 零 & 個位(位數(8)) & 拾 & 個位(位數(9)) & 萬 ElseIf 位數(6) <> "0" And 位數(7) <> "0" And 位數(8) = "0" And 位數(9) = "0" Then : 答案 &= 個位(位數(6)) & 仟 & 個位(位數(7)) & 百 & 萬 ElseIf 位數(6) <> "0" And 位數(7) <> "0" And 位數(8) = "0" And 位數(9) <> "0" Then : 答案 &= 個位(位數(6)) & 仟 & 個位(位數(7)) & 百 & 零 & 個位(位數(9)) & 萬 ElseIf 位數(6) <> "0" And 位數(7) <> "0" And 位數(8) <> "0" And 位數(9) = "0" Then : 答案 &= 個位(位數(6)) & 仟 & 個位(位數(7)) & 百 & 個位(位數(8)) & 拾 & 萬 ElseIf 位數(6) <> "0" And 位數(7) <> "0" And 位數(8) <> "0" And 位數(9) <> "0" Then : 答案 &= 個位(位數(6)) & 仟 & 個位(位數(7)) & 百 & 個位(位數(8)) & 拾 & 個位(位數(9)) & 萬 End If If 位數(10) = "0" And 位數(11) = "0" And 位數(12) = "0" And 末位數 = "0" Then ElseIf 位數(10) = "0" And 位數(11) = "0" And 位數(12) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(末位數) ElseIf 位數(10) = "0" And 位數(11) = "0" And 位數(12) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(12)) & 拾 ElseIf 位數(10) = "0" And 位數(11) = "0" And 位數(12) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(12)) & 拾 & 個位(末位數) ElseIf 位數(10) = "0" And 位數(11) <> "0" And 位數(12) = "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(11)) & 百 ElseIf 位數(10) = "0" And 位數(11) <> "0" And 位數(12) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(11)) & 百 & 零 & 個位(末位數) ElseIf 位數(10) = "0" And 位數(11) <> "0" And 位數(12) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(11)) & 百 & 個位(位數(12)) & 拾 ElseIf 位數(10) = "0" And 位數(11) <> "0" And 位數(12) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(11)) & 百 & 個位(位數(12)) & 拾 & 個位(末位數) ElseIf 位數(10) <> "0" And 位數(11) = "0" And 位數(12) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(10)) & 仟 ElseIf 位數(10) <> "0" And 位數(11) = "0" And 位數(12) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(10)) & 仟 & 零 & 個位(末位數) ElseIf 位數(10) <> "0" And 位數(11) = "0" And 位數(12) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(10)) & 仟 & 零 & 個位(位數(12)) & 拾 ElseIf 位數(10) <> "0" And 位數(11) = "0" And 位數(12) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(10)) & 仟 & 零 & 個位(位數(12)) & 拾 & 個位(末位數) ElseIf 位數(10) <> "0" And 位數(11) <> "0" And 位數(12) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(10)) & 仟 & 個位(位數(11)) & 百 ElseIf 位數(10) <> "0" And 位數(11) <> "0" And 位數(12) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(10)) & 仟 & 個位(位數(11)) & 百 & 零 & 個位(末位數) ElseIf 位數(10) <> "0" And 位數(11) <> "0" And 位數(12) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(10)) & 仟 & 個位(位數(11)) & 百 & 個位(位數(12)) & 拾 ElseIf 位數(10) <> "0" And 位數(11) <> "0" And 位數(12) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(10)) & 仟 & 個位(位數(11)) & 百 & 個位(位數(12)) & 拾 & 個位(末位數) End If ElseIf 數長 = 14 Then If 位數(2) = "0" Then : 答案 = 個位(位數(1)) & 拾 & 兆 : Else : 答案 = 個位(位數(1)) & 拾 & 個位(位數(2)) & 兆 : End If : 答案 &= 個位(位數(3)) & 仟 If 位數(4) = "0" And 位數(5) = "0" And 位數(6) = "0" Then : 答案 &= 億 ElseIf 位數(4) = "0" And 位數(5) = "0" And 位數(6) <> "0" Then : 答案 &= 零 & 個位(位數(6)) & 億 ElseIf 位數(4) = "0" And 位數(5) <> "0" And 位數(6) <> "0" Then : 答案 &= 零 & 個位(位數(5)) & 拾 & 個位(位數(6)) & 億 ElseIf 位數(4) = "0" And 位數(5) <> "0" And 位數(6) = "0" Then : 答案 &= 零 & 個位(位數(5)) & 拾 & 億 ElseIf 位數(4) <> "0" And 位數(5) = "0" And 位數(6) = "0" Then : 答案 &= 個位(位數(4)) & 百 & 億 ElseIf 位數(4) <> "0" And 位數(5) = "0" And 位數(6) <> "0" Then : 答案 &= 個位(位數(4)) & 百 & 零 & 個位(位數(6)) & 億 ElseIf 位數(4) <> "0" And 位數(5) <> "0" And 位數(6) = "0" Then : 答案 &= 個位(位數(4)) & 百 & 個位(位數(5)) & 拾 & 億 ElseIf 位數(4) <> "0" And 位數(6) <> "0" And 位數(6) <> "0" Then : 答案 &= 個位(位數(4)) & 百 & 個位(位數(5)) & 拾 & 個位(位數(6)) & 億 End If If 位數(7) = "0" And 位數(8) = "0" And 位數(9) = "0" And 位數(10) = "0" Then ElseIf 位數(7) = "0" And 位數(8) = "0" And 位數(9) = "0" And 位數(10) <> "0" Then : 答案 &= 零 & 個位(位數(10)) & 萬 ElseIf 位數(7) = "0" And 位數(8) = "0" And 位數(9) <> "0" And 位數(10) = "0" Then : 答案 &= 零 & 個位(位數(9)) & 拾 & 萬 ElseIf 位數(7) = "0" And 位數(8) = "0" And 位數(9) <> "0" And 位數(10) <> "0" Then : 答案 &= 零 & 個位(位數(9)) & 拾 & 個位(位數(10)) & 萬 ElseIf 位數(7) = "0" And 位數(8) <> "0" And 位數(9) = "0" And 位數(10) = "0" Then : 答案 &= 零 & 個位(位數(8)) & 百 & 萬 ElseIf 位數(7) = "0" And 位數(8) <> "0" And 位數(9) = "0" And 位數(10) <> "0" Then : 答案 &= 零 & 個位(位數(8)) & 百 & 零 & 個位(位數(10)) & 萬 ElseIf 位數(7) = "0" And 位數(8) <> "0" And 位數(9) <> "0" And 位數(10) = "0" Then : 答案 &= 零 & 個位(位數(8)) & 百 & 個位(位數(9)) & 拾 & 萬 ElseIf 位數(7) = "0" And 位數(8) <> "0" And 位數(9) <> "0" And 位數(10) <> "0" Then : 答案 &= 零 & 個位(位數(8)) & 百 & 個位(位數(9)) & 拾 & 個位(位數(10)) & 萬 ElseIf 位數(7) <> "0" And 位數(8) = "0" And 位數(9) = "0" And 位數(10) = "0" Then : 答案 &= 個位(位數(7)) & 仟 & 萬 ElseIf 位數(7) <> "0" And 位數(8) = "0" And 位數(9) = "0" And 位數(10) <> "0" Then : 答案 &= 個位(位數(7)) & 仟 & 零 & 個位(位數(10)) & 萬 ElseIf 位數(7) <> "0" And 位數(8) = "0" And 位數(9) <> "0" And 位數(10) = "0" Then : 答案 &= 個位(位數(7)) & 仟 & 零 & 個位(位數(9)) & 拾 & 萬 ElseIf 位數(7) <> "0" And 位數(8) = "0" And 位數(9) <> "0" And 位數(10) <> "0" Then : 答案 &= 個位(位數(7)) & 仟 & 零 & 個位(位數(9)) & 拾 & 個位(位數(10)) & 萬 ElseIf 位數(7) <> "0" And 位數(8) <> "0" And 位數(9) = "0" And 位數(10) = "0" Then : 答案 &= 個位(位數(7)) & 仟 & 個位(位數(8)) & 百 & 萬 ElseIf 位數(7) <> "0" And 位數(8) <> "0" And 位數(9) = "0" And 位數(10) <> "0" Then : 答案 &= 個位(位數(7)) & 仟 & 個位(位數(8)) & 百 & 零 & 個位(位數(10)) & 萬 ElseIf 位數(7) <> "0" And 位數(8) <> "0" And 位數(9) <> "0" And 位數(10) = "0" Then : 答案 &= 個位(位數(7)) & 仟 & 個位(位數(8)) & 百 & 個位(位數(9)) & 拾 & 萬 ElseIf 位數(7) <> "0" And 位數(8) <> "0" And 位數(9) <> "0" And 位數(10) <> "0" Then : 答案 &= 個位(位數(7)) & 仟 & 個位(位數(8)) & 百 & 個位(位數(9)) & 拾 & 個位(位數(10)) & 萬 End If If 位數(11) = "0" And 位數(12) = "0" And 位數(13) = "0" And 末位數 = "0" Then ElseIf 位數(11) = "0" And 位數(12) = "0" And 位數(13) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(末位數) ElseIf 位數(11) = "0" And 位數(12) = "0" And 位數(13) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(13)) & 拾 ElseIf 位數(11) = "0" And 位數(12) = "0" And 位數(13) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(13)) & 拾 & 個位(末位數) ElseIf 位數(11) = "0" And 位數(12) <> "0" And 位數(13) = "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(12)) & 百 ElseIf 位數(11) = "0" And 位數(12) <> "0" And 位數(13) = "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(12)) & 百 & 零 & 個位(末位數) ElseIf 位數(11) = "0" And 位數(12) <> "0" And 位數(13) <> "0" And 末位數 = "0" Then : 答案 &= 零 & 個位(位數(12)) & 百 & 個位(位數(13)) & 拾 ElseIf 位數(11) = "0" And 位數(12) <> "0" And 位數(13) <> "0" And 末位數 <> "0" Then : 答案 &= 零 & 個位(位數(12)) & 百 & 個位(位數(13)) & 拾 & 個位(末位數) ElseIf 位數(11) <> "0" And 位數(12) = "0" And 位數(13) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(11)) & 仟 ElseIf 位數(11) <> "0" And 位數(12) = "0" And 位數(13) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(11)) & 仟 & 零 & 個位(末位數) ElseIf 位數(11) <> "0" And 位數(12) = "0" And 位數(13) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(11)) & 仟 & 零 & 個位(位數(13)) & 拾 ElseIf 位數(11) <> "0" And 位數(12) = "0" And 位數(13) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(11)) & 仟 & 零 & 個位(位數(13)) & 拾 & 個位(末位數) ElseIf 位數(11) <> "0" And 位數(12) <> "0" And 位數(13) = "0" And 末位數 = "0" Then : 答案 &= 個位(位數(11)) & 仟 & 個位(位數(12)) & 百 ElseIf 位數(11) <> "0" And 位數(12) <> "0" And 位數(13) = "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(11)) & 仟 & 個位(位數(12)) & 百 & 零 & 個位(末位數) ElseIf 位數(11) <> "0" And 位數(12) <> "0" And 位數(13) <> "0" And 末位數 = "0" Then : 答案 &= 個位(位數(11)) & 仟 & 個位(位數(12)) & 百 & 個位(位數(13)) & 拾 ElseIf 位數(11) <> "0" And 位數(12) <> "0" And 位數(13) <> "0" And 末位數 <> "0" Then : 答案 &= 個位(位數(11)) & 仟 & 個位(位數(12)) & 百 & 個位(位數(13)) & 拾 & 個位(末位數) End If End If Return 答案 End Function End Class