|
@@ -492,6 +492,7 @@ Public Class 財務_收支單一覽表
|
492
|
492
|
If 明細_rb.Checked = False And 彙總_rb.Checked = True Then
|
493
|
493
|
MsgBox("請點選明細才能列印")
|
494
|
494
|
ElseIf 明細_rb.Checked = True And 彙總_rb.Checked = False Then
|
|
495
|
+ 列印.ShowDialog() : 列印.BringToFront()
|
495
|
496
|
xlApp = CType(CreateObject("Excel.Application"), Application)
|
496
|
497
|
xlBook = xlApp.Workbooks.Add
|
497
|
498
|
xlApp.DisplayAlerts = True
|
|
@@ -500,147 +501,413 @@ Public Class 財務_收支單一覽表
|
500
|
501
|
xlSheet.Activate()
|
501
|
502
|
xlApp.Visible = True
|
502
|
503
|
xlApp.Application.WindowState = xlMaximized
|
503
|
|
- Dim dat As String = 明細_dgv.Rows(0).Cells("支付單號").Value.ToString
|
504
|
|
- Dim startIndex As Integer = dat.IndexOf("-") + 1
|
505
|
|
- Dim datePart As String
|
506
|
|
- Dim dateValue As DateTime
|
507
|
|
- Dim dat1 As String
|
508
|
|
- If boo1 = True Then
|
509
|
|
- datePart = dat.Substring(startIndex, 8)
|
510
|
|
- If DateTime.TryParseExact(datePart, "yyyyMMdd", Nothing, System.Globalization.DateTimeStyles.None, dateValue) Then
|
511
|
|
- Dim formattedDate As String = dateValue.ToString("yyyy/MM/dd")
|
512
|
|
- dat1 = formattedDate
|
|
504
|
+ If BL1 Then
|
|
505
|
+ Dim dat As String = 明細_dgv.Rows(0).Cells("支付單號").Value.ToString
|
|
506
|
+ Dim startIndex As Integer = dat.IndexOf("-") + 1
|
|
507
|
+ Dim datePart As String
|
|
508
|
+ Dim dateValue As DateTime
|
|
509
|
+ Dim dat1 As String
|
|
510
|
+ If boo1 = True Then
|
|
511
|
+ datePart = dat.Substring(startIndex, 8)
|
|
512
|
+ If DateTime.TryParseExact(datePart, "yyyyMMdd", Nothing, System.Globalization.DateTimeStyles.None, dateValue) Then
|
|
513
|
+ Dim formattedDate As String = dateValue.ToString("yyyy/MM/dd")
|
|
514
|
+ dat1 = formattedDate
|
|
515
|
+ Else
|
|
516
|
+ dat1 = "無效日期"
|
|
517
|
+ End If
|
513
|
518
|
Else
|
514
|
|
- dat1 = "無效日期"
|
|
519
|
+ datePart = DateTime.Now.ToString("yyyyMM")
|
|
520
|
+ dat1 = DateTime.Now.ToString("yyyy/MM")
|
515
|
521
|
End If
|
516
|
|
- Else
|
517
|
|
- datePart = DateTime.Now.ToString("yyyyMM")
|
518
|
|
- dat1 = DateTime.Now.ToString("yyyy/MM")
|
519
|
|
- End If
|
520
|
|
- Dim firstCellValue As Object = 明細_dgv.Rows(0).Cells("會計科目").Value
|
521
|
|
- Dim allSame As Boolean = True
|
|
522
|
+ Dim firstCellValue As Object = 明細_dgv.Rows(0).Cells("會計科目").Value
|
|
523
|
+ Dim allSame As Boolean = True
|
522
|
524
|
|
523
|
|
- For i As Integer = 1 To 明細_dgv.Rows.Count - 1
|
524
|
|
- If Not Object.Equals(明細_dgv.Rows(i).Cells("會計科目").Value, firstCellValue) Then
|
525
|
|
- allSame = False
|
526
|
|
- Exit For
|
527
|
|
- End If
|
528
|
|
- Next
|
529
|
|
- If allSame Then
|
530
|
|
- xlSheet.Cells(2, 3) = 明細_dgv.Rows(0).Cells("會計科目").Value & "-用途說明"
|
531
|
|
- Else
|
532
|
|
- xlSheet.Cells(2, 3) = "用途說明"
|
533
|
|
- End If
|
534
|
|
-
|
535
|
|
- xlSheet.Cells(1, 1) = 公司名稱.Text & "收支粘貼憑證用紙-" & dat1
|
536
|
|
- xlSheet.Cells(2, 1) = "憑證編號" : xlSheet.Cells(2, 2) = "編號" : xlSheet.Cells(2, 9) = "金額"
|
537
|
|
- xlSheet.Cells(2, 10) = "附件" : xlSheet.Cells(3, 10) = "憑證" : xlSheet.Cells(2, 8) = "收" & vbLf & "支"
|
538
|
|
- xlSheet.Cells(4, 10) = 憑證張數_tb.Text & vbCrLf & "張"
|
539
|
|
- If 顯示單據_cb.Checked = True Then
|
540
|
|
- xlSheet.Cells(2, 7) = "單據" & vbLf & "編號"
|
541
|
|
- End If
|
542
|
|
- For i As Integer = 0 To 明細_dgv.Rows.Count - 1
|
543
|
|
- xlSheet.Cells(i + 4, 2) = i + 1
|
544
|
|
- If allSame Then
|
545
|
|
- xlSheet.Cells(i + 4, 3) = 明細_dgv.Rows(i).Cells("用途").Value
|
546
|
|
- If 顯示單據_cb.Checked = True Then
|
547
|
|
- xlSheet.Cells(i + 4, 7) = "'" + 明細_dgv.Rows(i).Cells("票期").Value
|
|
525
|
+ For i As Integer = 1 To 明細_dgv.Rows.Count - 1
|
|
526
|
+ If Not Object.Equals(明細_dgv.Rows(i).Cells("會計科目").Value, firstCellValue) Then
|
|
527
|
+ allSame = False
|
|
528
|
+ Exit For
|
548
|
529
|
End If
|
|
530
|
+ Next
|
|
531
|
+ If allSame Then
|
|
532
|
+ xlSheet.Cells(2, 3) = 明細_dgv.Rows(0).Cells("會計科目").Value & "-用途說明"
|
549
|
533
|
Else
|
550
|
|
- xlSheet.Cells(i + 4, 3) = 明細_dgv.Rows(i).Cells("會計科目").Value
|
551
|
|
- xlSheet.Cells(i + 4, 4) = 明細_dgv.Rows(i).Cells("用途").Value
|
552
|
|
- If 顯示單據_cb.Checked = True Then
|
553
|
|
- xlSheet.Cells(i + 4, 7) = "'" + 明細_dgv.Rows(i).Cells("票期").Value
|
554
|
|
- End If
|
|
534
|
+ xlSheet.Cells(2, 3) = "用途說明"
|
555
|
535
|
End If
|
556
|
|
- xlSheet.Cells(i + 4, 11) = 明細_dgv.Rows(i).Cells("用途").Value
|
557
|
|
- If 明細_dgv.Rows(i).Cells("收入").Value = 0 And 明細_dgv.Rows(i).Cells("支出").Value <> 0 Then
|
558
|
|
- xlSheet.Cells(i + 4, 8) = "支"
|
559
|
|
- Dim value1 As Double = Convert.ToDouble(明細_dgv.Rows(i).Cells("支出").Value)
|
560
|
|
- Dim formattedValue1 As String = value1.ToString("#,##0")
|
561
|
|
- xlSheet.Cells(i + 4, 9) = formattedValue1
|
562
|
|
- 'Dim str As String = 大寫轉換(明細_dgv.Rows(i).Cells("支出").Value)
|
563
|
|
- 'xlSheet.Cells(i + 4, 9) = str & " 元整"
|
564
|
|
- ElseIf 明細_dgv.Rows(i).Cells("收入").Value <> 0 And 明細_dgv.Rows(i).Cells("支出").Value = 0 Then
|
565
|
|
- xlSheet.Cells(i + 4, 8) = "收"
|
566
|
|
- Dim value2 As Double = Convert.ToDouble(明細_dgv.Rows(i).Cells("收入").Value)
|
567
|
|
- Dim formattedValue2 As String = value2.ToString("#,##0")
|
568
|
|
- xlSheet.Cells(i + 4, 9) = formattedValue2
|
569
|
|
- 'Dim str As String = 大寫轉換(明細_dgv.Rows(i).Cells("收入").Value)
|
570
|
|
- 'xlSheet.Cells(i + 4, 9) = str & " 元整"
|
|
536
|
+
|
|
537
|
+ xlSheet.Cells(1, 1) = 公司名稱.Text & "收支粘貼憑證用紙-" & dat1
|
|
538
|
+ xlSheet.Cells(2, 1) = "憑證編號" : xlSheet.Cells(2, 2) = "編號" : xlSheet.Cells(2, 9) = "金額"
|
|
539
|
+ xlSheet.Cells(2, 10) = "附件" : xlSheet.Cells(3, 10) = "憑證" : xlSheet.Cells(2, 8) = "收" & vbLf & "支"
|
|
540
|
+ xlSheet.Cells(4, 10) = 憑證張數_tb.Text & vbCrLf & "張"
|
|
541
|
+ If 顯示單據_cb.Checked = True Then
|
|
542
|
+ xlSheet.Cells(2, 7) = "單據" & vbLf & "編號"
|
571
|
543
|
End If
|
572
|
|
- N2 = i + 4
|
573
|
|
- Next i
|
|
544
|
+ For i As Integer = 0 To 明細_dgv.Rows.Count - 1
|
|
545
|
+ xlSheet.Cells(i + 4, 2) = i + 1
|
|
546
|
+ If allSame Then
|
|
547
|
+ xlSheet.Cells(i + 4, 3) = 明細_dgv.Rows(i).Cells("用途").Value
|
|
548
|
+ If 顯示單據_cb.Checked = True Then
|
|
549
|
+ xlSheet.Cells(i + 4, 7) = "'" + 明細_dgv.Rows(i).Cells("票期").Value
|
|
550
|
+ End If
|
|
551
|
+ Else
|
|
552
|
+ xlSheet.Cells(i + 4, 3) = 明細_dgv.Rows(i).Cells("會計科目").Value
|
|
553
|
+ xlSheet.Cells(i + 4, 4) = 明細_dgv.Rows(i).Cells("用途").Value
|
|
554
|
+ If 顯示單據_cb.Checked = True Then
|
|
555
|
+ xlSheet.Cells(i + 4, 7) = "'" + 明細_dgv.Rows(i).Cells("票期").Value
|
|
556
|
+ End If
|
|
557
|
+ End If
|
|
558
|
+ xlSheet.Cells(i + 4, 11) = 明細_dgv.Rows(i).Cells("用途").Value
|
|
559
|
+ If 明細_dgv.Rows(i).Cells("收入").Value = 0 And 明細_dgv.Rows(i).Cells("支出").Value <> 0 Then
|
|
560
|
+ xlSheet.Cells(i + 4, 8) = "支"
|
|
561
|
+ Dim value1 As Double = Convert.ToDouble(明細_dgv.Rows(i).Cells("支出").Value)
|
|
562
|
+ Dim formattedValue1 As String = value1.ToString("#,##0")
|
|
563
|
+ xlSheet.Cells(i + 4, 9) = formattedValue1
|
|
564
|
+ 'Dim str As String = 大寫轉換(明細_dgv.Rows(i).Cells("支出").Value)
|
|
565
|
+ 'xlSheet.Cells(i + 4, 9) = str & " 元整"
|
|
566
|
+ ElseIf 明細_dgv.Rows(i).Cells("收入").Value <> 0 And 明細_dgv.Rows(i).Cells("支出").Value = 0 Then
|
|
567
|
+ xlSheet.Cells(i + 4, 8) = "收"
|
|
568
|
+ Dim value2 As Double = Convert.ToDouble(明細_dgv.Rows(i).Cells("收入").Value)
|
|
569
|
+ Dim formattedValue2 As String = value2.ToString("#,##0")
|
|
570
|
+ xlSheet.Cells(i + 4, 9) = formattedValue2
|
|
571
|
+ 'Dim str As String = 大寫轉換(明細_dgv.Rows(i).Cells("收入").Value)
|
|
572
|
+ 'xlSheet.Cells(i + 4, 9) = str & " 元整"
|
|
573
|
+ End If
|
|
574
|
+ N2 = i + 4
|
|
575
|
+ Next i
|
574
|
576
|
|
575
|
577
|
|
576
|
|
- Dim 台幣現金餘額 As Decimal
|
577
|
|
- If Decimal.TryParse(台幣現金餘額_tb.Text, 台幣現金餘額) Then
|
578
|
|
- If 台幣現金餘額 > 0 Then
|
579
|
|
- xlSheet.Cells(N2 + 1, 2) = "合計收入 : "
|
580
|
|
- Else
|
581
|
|
- xlSheet.Cells(N2 + 1, 2) = "合計支出 : "
|
582
|
|
- End If
|
583
|
|
- If 台幣現金餘額 < 0 Then
|
584
|
|
- 台幣現金餘額 = Math.Abs(台幣現金餘額)
|
|
578
|
+ Dim 台幣現金餘額 As Decimal
|
|
579
|
+ If Decimal.TryParse(台幣現金餘額_tb.Text, 台幣現金餘額) Then
|
|
580
|
+ If 台幣現金餘額 > 0 Then
|
|
581
|
+ xlSheet.Cells(N2 + 1, 2) = "合計收入 : "
|
|
582
|
+ Else
|
|
583
|
+ xlSheet.Cells(N2 + 1, 2) = "合計支出 : "
|
|
584
|
+ End If
|
|
585
|
+ If 台幣現金餘額 < 0 Then
|
|
586
|
+ 台幣現金餘額 = Math.Abs(台幣現金餘額)
|
|
587
|
+ End If
|
|
588
|
+ Dim value As Double = 台幣現金餘額
|
|
589
|
+ Dim formattedValue As String = value.ToString("#,##0")
|
|
590
|
+ xlSheet.Cells(N2 + 1, 9) = formattedValue
|
|
591
|
+ 'Dim str1 As String = 大寫轉換(台幣現金餘額.ToString())
|
|
592
|
+ 'xlSheet.Cells(N2 + 1, 9) = str1 & " 元整"
|
585
|
593
|
End If
|
586
|
|
- Dim value As Double = 台幣現金餘額
|
587
|
|
- Dim formattedValue As String = value.ToString("#,##0")
|
588
|
|
- xlSheet.Cells(N2 + 1, 9) = formattedValue
|
589
|
|
- 'Dim str1 As String = 大寫轉換(台幣現金餘額.ToString())
|
590
|
|
- 'xlSheet.Cells(N2 + 1, 9) = str1 & " 元整"
|
591
|
|
- End If
|
592
|
594
|
|
593
|
|
- SQL_公司稱謂()
|
594
|
|
- If dr.Read() Then
|
595
|
|
- xlSheet.Cells(N2 + 2, 7) = If(Not IsDBNull(dr("編號一")), dr("編號一").ToString(), "")
|
596
|
|
- xlSheet.Cells(N2 + 2, 6) = If(Not IsDBNull(dr("編號二")), dr("編號二").ToString(), "")
|
597
|
|
- xlSheet.Cells(N2 + 2, 5) = If(Not IsDBNull(dr("編號三")), dr("編號三").ToString(), "")
|
598
|
|
- xlSheet.Cells(N2 + 2, 4) = If(Not IsDBNull(dr("編號四")), dr("編號四").ToString(), "")
|
599
|
|
- xlSheet.Cells(N2 + 2, 3) = If(Not IsDBNull(dr("編號五")), dr("編號五").ToString(), "")
|
600
|
|
- xlSheet.Cells(N2 + 2, 1) = If(Not IsDBNull(dr("編號六")), dr("編號六").ToString(), "")
|
601
|
|
- xlSheet.Cells(N2 + 2, 9) = If(Not IsDBNull(dr("編號七")), dr("編號七").ToString(), "")
|
602
|
|
- End If
|
603
|
|
- AA(xlApp, xlSheet, allSame)
|
604
|
|
- xlApp.Sheets(2).Delete : xlSheet.PageSetup.PrintArea = ""
|
605
|
|
- '----轉成PDF-----
|
606
|
|
- Dim pdfFolderPath As String = Path.Combine(System.Windows.Forms.Application.StartupPath, "pdf")
|
607
|
|
- If Not Directory.Exists(pdfFolderPath) Then
|
608
|
|
- Directory.CreateDirectory(pdfFolderPath)
|
609
|
|
- End If
|
610
|
|
- Dim pdfFilePath As String = Path.Combine(pdfFolderPath, datePart & "-傳票.pdf")
|
611
|
|
- xlBook.Sheets(1).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, pdfFilePath, XlFixedFormatQuality.xlQualityStandard, True)
|
612
|
|
- '--------
|
613
|
|
- xlApp.Cells.Select() : xlApp.Application.WindowState = xlMinimized : xlBook.Close(False)
|
614
|
|
- Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
|
615
|
|
- Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
|
616
|
|
- Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
|
617
|
|
- xlApp.Quit() : xlSheet = Nothing : xlBook = Nothing : xlApp = Nothing : GC.Collect()
|
618
|
|
- Try
|
619
|
|
- Dim chromePath As String = "C:\Program Files\Google\Chrome\Application\chrome.exe"
|
620
|
|
- If System.IO.File.Exists(chromePath) Then
|
621
|
|
- Dim process As New Process()
|
622
|
|
- process.StartInfo.FileName = "chrome"
|
623
|
|
- process.StartInfo.Arguments = """" & pdfFilePath & """"
|
624
|
|
- process.Start()
|
625
|
|
- Else : Dim edgePath As String = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
|
626
|
|
- If System.IO.File.Exists(edgePath) Then
|
|
595
|
+ SQL_公司稱謂()
|
|
596
|
+ If dr.Read() Then
|
|
597
|
+ xlSheet.Cells(N2 + 2, 7) = If(Not IsDBNull(dr("編號一")), dr("編號一").ToString(), "")
|
|
598
|
+ xlSheet.Cells(N2 + 2, 6) = If(Not IsDBNull(dr("編號二")), dr("編號二").ToString(), "")
|
|
599
|
+ xlSheet.Cells(N2 + 2, 5) = If(Not IsDBNull(dr("編號三")), dr("編號三").ToString(), "")
|
|
600
|
+ xlSheet.Cells(N2 + 2, 4) = If(Not IsDBNull(dr("編號四")), dr("編號四").ToString(), "")
|
|
601
|
+ xlSheet.Cells(N2 + 2, 3) = If(Not IsDBNull(dr("編號五")), dr("編號五").ToString(), "")
|
|
602
|
+ xlSheet.Cells(N2 + 2, 1) = If(Not IsDBNull(dr("編號六")), dr("編號六").ToString(), "")
|
|
603
|
+ xlSheet.Cells(N2 + 2, 9) = If(Not IsDBNull(dr("編號七")), dr("編號七").ToString(), "")
|
|
604
|
+ End If
|
|
605
|
+ AA(xlApp, xlSheet, allSame)
|
|
606
|
+ xlApp.Sheets(2).Delete : xlSheet.PageSetup.PrintArea = ""
|
|
607
|
+ '----轉成PDF-----
|
|
608
|
+ Dim pdfFolderPath As String = Path.Combine(System.Windows.Forms.Application.StartupPath, "pdf")
|
|
609
|
+ If Not Directory.Exists(pdfFolderPath) Then
|
|
610
|
+ Directory.CreateDirectory(pdfFolderPath)
|
|
611
|
+ End If
|
|
612
|
+ Dim pdfFilePath As String = Path.Combine(pdfFolderPath, datePart & "-傳票.pdf")
|
|
613
|
+ xlBook.Sheets(1).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, pdfFilePath, XlFixedFormatQuality.xlQualityStandard, True)
|
|
614
|
+ '--------
|
|
615
|
+ xlApp.Cells.Select() : xlApp.Application.WindowState = xlMinimized : xlBook.Close(False)
|
|
616
|
+ Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
|
|
617
|
+ Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
|
|
618
|
+ Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
|
|
619
|
+ xlApp.Quit() : xlSheet = Nothing : xlBook = Nothing : xlApp = Nothing : GC.Collect()
|
|
620
|
+ Try
|
|
621
|
+ Dim chromePath As String = "C:\Program Files\Google\Chrome\Application\chrome.exe"
|
|
622
|
+ If System.IO.File.Exists(chromePath) Then
|
627
|
623
|
Dim process As New Process()
|
628
|
|
- process.StartInfo.FileName = "msedge"
|
|
624
|
+ process.StartInfo.FileName = "chrome"
|
629
|
625
|
process.StartInfo.Arguments = """" & pdfFilePath & """"
|
630
|
626
|
process.Start()
|
631
|
|
- Else
|
632
|
|
- Process.Start(pdfFilePath)
|
|
627
|
+ Else : Dim edgePath As String = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
|
|
628
|
+ If System.IO.File.Exists(edgePath) Then
|
|
629
|
+ Dim process As New Process()
|
|
630
|
+ process.StartInfo.FileName = "msedge"
|
|
631
|
+ process.StartInfo.Arguments = """" & pdfFilePath & """"
|
|
632
|
+ process.Start()
|
|
633
|
+ Else
|
|
634
|
+ Process.Start(pdfFilePath)
|
|
635
|
+ End If
|
633
|
636
|
End If
|
|
637
|
+ Catch ex As Exception
|
|
638
|
+ MsgBox("以存檔至桌面 。" & vbCrLf & "檔案名稱:" & datePart & "-傳票.pdf")
|
|
639
|
+ End Try
|
|
640
|
+ Else
|
|
641
|
+ xlSheet.Cells(1, 1) = 公司名稱.Text & "收支一覽表-" & 開始日期_dtp.Value.ToString("yyyy/MM/dd") & "~" & 結束日期_dtp.Value.ToString("yyyy/MM/dd")
|
|
642
|
+ xlSheet.Cells(2, 1) = "主項" : xlSheet.Cells(2, 2) = "子項" : xlSheet.Cells(2, 3) = "子細項"
|
|
643
|
+ xlSheet.Cells(2, 4) = "收入" : xlSheet.Cells(2, 5) = "支出"
|
|
644
|
+ Dim 支出合計 As Double = 0 : Dim 收入合計 As Double = 0
|
|
645
|
+ For i As Integer = 0 To 財務彙總_dgv.Rows.Count - 1
|
|
646
|
+ Dim 支出 As Double = Convert.ToDouble(財務彙總_dgv.Rows(i).Cells("支出").Value)
|
|
647
|
+ Dim 收入 As Double = Convert.ToDouble(財務彙總_dgv.Rows(i).Cells("收入").Value)
|
|
648
|
+ 支出合計 += 支出
|
|
649
|
+ 收入合計 += 收入
|
|
650
|
+ xlSheet.Cells(i + 3, 1) = 財務彙總_dgv.Rows(i).Cells("主項").Value
|
|
651
|
+ xlSheet.Cells(i + 3, 2) = 財務彙總_dgv.Rows(i).Cells("子項").Value
|
|
652
|
+ xlSheet.Cells(i + 3, 3) = 財務彙總_dgv.Rows(i).Cells("子細項").Value
|
|
653
|
+ xlSheet.Cells(i + 3, 4) = 收入.ToString("#,##0")
|
|
654
|
+ xlSheet.Cells(i + 3, 5) = 支出.ToString("#,##0")
|
|
655
|
+ N2 = i + 4
|
|
656
|
+ Next i
|
|
657
|
+
|
|
658
|
+ xlSheet.Cells(N2, 3) = "合計" : xlSheet.Cells(N2, 4) = 收入合計.ToString("#,##0") : xlSheet.Cells(N2, 5) = 支出合計.ToString("#,##0")
|
|
659
|
+ xlSheet.Cells(N2 + 1, 3) = "總計" : xlSheet.Cells(N2 + 1, 4) = (收入合計 - 支出合計).ToString("#,##0")
|
|
660
|
+ BB(xlApp, xlSheet)
|
|
661
|
+ xlApp.Sheets(2).Delete : xlSheet.PageSetup.PrintArea = ""
|
|
662
|
+ '----轉成PDF-----
|
|
663
|
+ Dim pdfFolderPath As String = Path.Combine(System.Windows.Forms.Application.StartupPath, "pdf")
|
|
664
|
+ If Not Directory.Exists(pdfFolderPath) Then
|
|
665
|
+ Directory.CreateDirectory(pdfFolderPath)
|
634
|
666
|
End If
|
635
|
|
- Catch ex As Exception
|
636
|
|
- MsgBox("以存檔至桌面 。" & vbCrLf & "檔案名稱:" & datePart & "-結帳單.pdf")
|
637
|
|
- End Try
|
|
667
|
+ Dim pdfFilePath As String = Path.Combine(pdfFolderPath, "收支一覽表.pdf")
|
|
668
|
+ xlBook.Sheets(1).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, pdfFilePath, XlFixedFormatQuality.xlQualityStandard, True)
|
|
669
|
+ '--------
|
|
670
|
+ xlApp.Cells.Select() : xlApp.Application.WindowState = xlMinimized : xlBook.Close(False)
|
|
671
|
+ Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
|
|
672
|
+ Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
|
|
673
|
+ Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
|
|
674
|
+ xlApp.Quit() : xlSheet = Nothing : xlBook = Nothing : xlApp = Nothing : GC.Collect()
|
|
675
|
+ Try
|
|
676
|
+ Dim chromePath As String = "C:\Program Files\Google\Chrome\Application\chrome.exe"
|
|
677
|
+ If System.IO.File.Exists(chromePath) Then
|
|
678
|
+ Dim process As New Process()
|
|
679
|
+ process.StartInfo.FileName = "chrome"
|
|
680
|
+ process.StartInfo.Arguments = """" & pdfFilePath & """"
|
|
681
|
+ process.Start()
|
|
682
|
+ Else : Dim edgePath As String = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
|
|
683
|
+ If System.IO.File.Exists(edgePath) Then
|
|
684
|
+ Dim process As New Process()
|
|
685
|
+ process.StartInfo.FileName = "msedge"
|
|
686
|
+ process.StartInfo.Arguments = """" & pdfFilePath & """"
|
|
687
|
+ process.Start()
|
|
688
|
+ Else
|
|
689
|
+ Process.Start(pdfFilePath)
|
|
690
|
+ End If
|
|
691
|
+ End If
|
|
692
|
+ Catch ex As Exception
|
|
693
|
+ MsgBox("以存檔至桌面 。" & vbCrLf & "檔案名稱:收支一覽表.pdf")
|
|
694
|
+ End Try
|
|
695
|
+ End If
|
638
|
696
|
End If
|
639
|
697
|
|
640
|
698
|
End Sub
|
641
|
699
|
Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
|
642
|
700
|
Return CType(xlBook.Worksheets.Add, Worksheet)
|
643
|
701
|
End Function
|
|
702
|
+ Private Sub BB(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
|
|
703
|
+ xlSheet.Activate() ' 激活工作表
|
|
704
|
+ xlSheet.Parent.Windows(1).View = XlWindowView.xlPageLayoutView
|
|
705
|
+ xlSheet.Cells.Select()
|
|
706
|
+ With myExcel.Selection.Font
|
|
707
|
+ .Name = "標楷體"
|
|
708
|
+ .Size = 12
|
|
709
|
+ .Strikethrough = False
|
|
710
|
+ .Superscript = False
|
|
711
|
+ .Subscript = False
|
|
712
|
+ .OutlineFont = False
|
|
713
|
+ .Shadow = False
|
|
714
|
+ .Underline = xlUnderlineStyleNone
|
|
715
|
+ .ThemeColor = xlThemeColorLight1
|
|
716
|
+ .TintAndShade = 0
|
|
717
|
+ .ThemeFont = xlThemeFontNone
|
|
718
|
+ End With
|
|
719
|
+ xlSheet.Range("A2:E" & N2 + 1).Select()
|
|
720
|
+ myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
|
|
721
|
+ myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
|
|
722
|
+ With myExcel.Selection.Borders(xlEdgeLeft)
|
|
723
|
+ .LineStyle = xlContinuous
|
|
724
|
+ .ColorIndex = 0
|
|
725
|
+ .TintAndShade = 0
|
|
726
|
+ .Weight = xlThin
|
|
727
|
+ End With
|
|
728
|
+ With myExcel.Selection.Borders(xlEdgeTop)
|
|
729
|
+ .LineStyle = xlContinuous
|
|
730
|
+ .ColorIndex = 0
|
|
731
|
+ .TintAndShade = 0
|
|
732
|
+ .Weight = xlThin
|
|
733
|
+ End With
|
|
734
|
+ With myExcel.Selection.Borders(xlEdgeBottom)
|
|
735
|
+ .LineStyle = xlContinuous
|
|
736
|
+ .ColorIndex = 0
|
|
737
|
+ .TintAndShade = 0
|
|
738
|
+ .Weight = xlThin
|
|
739
|
+ End With
|
|
740
|
+ With myExcel.Selection.Borders(xlEdgeRight)
|
|
741
|
+ .LineStyle = xlContinuous
|
|
742
|
+ .ColorIndex = 0
|
|
743
|
+ .TintAndShade = 0
|
|
744
|
+ .Weight = xlThin
|
|
745
|
+ End With
|
|
746
|
+ With myExcel.Selection.Borders(xlInsideVertical)
|
|
747
|
+ .LineStyle = xlContinuous
|
|
748
|
+ .ColorIndex = 0
|
|
749
|
+ .TintAndShade = 0
|
|
750
|
+ .Weight = xlThin
|
|
751
|
+ End With
|
|
752
|
+ With myExcel.Selection.Borders(xlInsideHorizontal)
|
|
753
|
+ .LineStyle = xlContinuous
|
|
754
|
+ .ColorIndex = 0
|
|
755
|
+ .TintAndShade = 0
|
|
756
|
+ .Weight = xlThin
|
|
757
|
+ End With
|
|
758
|
+
|
|
759
|
+ myExcel.Application.PrintCommunication = False
|
|
760
|
+ With myExcel.ActiveSheet.PageSetup
|
|
761
|
+ .PrintTitleRows = ""
|
|
762
|
+ .PrintTitleColumns = ""
|
|
763
|
+ End With
|
|
764
|
+ myExcel.Application.PrintCommunication = True
|
|
765
|
+ myExcel.ActiveSheet.PageSetup.PrintArea = ""
|
|
766
|
+ myExcel.Application.PrintCommunication = False
|
|
767
|
+ With myExcel.ActiveSheet.PageSetup
|
|
768
|
+ .LeftHeader = ""
|
|
769
|
+ .CenterHeader = ""
|
|
770
|
+ .RightHeader = ""
|
|
771
|
+ .LeftFooter = ""
|
|
772
|
+ .CenterFooter = ""
|
|
773
|
+ .RightFooter = ""
|
|
774
|
+ .LeftMargin = myExcel.Application.InchesToPoints(0.25)
|
|
775
|
+ .RightMargin = myExcel.Application.InchesToPoints(0.25)
|
|
776
|
+ .TopMargin = myExcel.Application.InchesToPoints(0.75)
|
|
777
|
+ .BottomMargin = myExcel.Application.InchesToPoints(0.75)
|
|
778
|
+ .HeaderMargin = myExcel.Application.InchesToPoints(0.3)
|
|
779
|
+ .FooterMargin = myExcel.Application.InchesToPoints(0.3)
|
|
780
|
+ .PrintHeadings = False
|
|
781
|
+ .PrintGridlines = False
|
|
782
|
+ .CenterHorizontally = True
|
|
783
|
+ .CenterVertically = False
|
|
784
|
+ .Draft = False
|
|
785
|
+ .FirstPageNumber = xlAutomatic
|
|
786
|
+ .BlackAndWhite = False
|
|
787
|
+ .Zoom = False
|
|
788
|
+ .FitToPagesWide = 1
|
|
789
|
+ .FitToPagesTall = 0
|
|
790
|
+ .OddAndEvenPagesHeaderFooter = False
|
|
791
|
+ .DifferentFirstPageHeaderFooter = False
|
|
792
|
+ .ScaleWithDocHeaderFooter = True
|
|
793
|
+ .AlignMarginsHeaderFooter = True
|
|
794
|
+ .EvenPage.LeftHeader.Text = ""
|
|
795
|
+ .EvenPage.CenterHeader.Text = ""
|
|
796
|
+ .EvenPage.RightHeader.Text = ""
|
|
797
|
+ .EvenPage.LeftFooter.Text = ""
|
|
798
|
+ .EvenPage.CenterFooter.Text = ""
|
|
799
|
+ .EvenPage.RightFooter.Text = ""
|
|
800
|
+ .FirstPage.LeftHeader.Text = ""
|
|
801
|
+ .FirstPage.CenterHeader.Text = ""
|
|
802
|
+ .FirstPage.RightHeader.Text = ""
|
|
803
|
+ .FirstPage.LeftFooter.Text = ""
|
|
804
|
+ .FirstPage.CenterFooter.Text = ""
|
|
805
|
+ .FirstPage.RightFooter.Text = ""
|
|
806
|
+ End With
|
|
807
|
+ myExcel.Application.PrintCommunication = True
|
|
808
|
+
|
|
809
|
+ xlSheet.Columns("A:A").ColumnWidth = 15
|
|
810
|
+ xlSheet.Columns("B:B").ColumnWidth = 15
|
|
811
|
+ xlSheet.Columns("C:C").ColumnWidth = 21
|
|
812
|
+ xlSheet.Columns("D:D").ColumnWidth = 15
|
|
813
|
+ xlSheet.Columns("E:E").ColumnWidth = 15
|
|
814
|
+
|
|
815
|
+ xlSheet.Range("A1:E1").Select()
|
|
816
|
+ With myExcel.Selection.Font
|
|
817
|
+ .Name = "標楷體"
|
|
818
|
+ .Size = 14
|
|
819
|
+ .Strikethrough = False
|
|
820
|
+ .Superscript = False
|
|
821
|
+ .Subscript = False
|
|
822
|
+ .OutlineFont = False
|
|
823
|
+ .Shadow = False
|
|
824
|
+ .Underline = xlUnderlineStyleNone
|
|
825
|
+ .ThemeColor = xlThemeColorLight1
|
|
826
|
+ .TintAndShade = 0
|
|
827
|
+ .ThemeFont = xlThemeFontNone
|
|
828
|
+ End With
|
|
829
|
+
|
|
830
|
+ xlSheet.Range("A1:E1").Select()
|
|
831
|
+
|
|
832
|
+ With myExcel.Selection
|
|
833
|
+ .HorizontalAlignment = xlCenter
|
|
834
|
+ .VerticalAlignment = xlCenter
|
|
835
|
+ .WrapText = False
|
|
836
|
+ .Orientation = 0
|
|
837
|
+ .AddIndent = False
|
|
838
|
+ .IndentLevel = 0
|
|
839
|
+ .ShrinkToFit = False
|
|
840
|
+ .ReadingOrder = xlContext
|
|
841
|
+ .MergeCells = False
|
|
842
|
+ End With
|
|
843
|
+ myExcel.Selection.Merge
|
|
844
|
+
|
|
845
|
+ xlSheet.Range("D2,E2").Select()
|
|
846
|
+
|
|
847
|
+ With myExcel.Selection
|
|
848
|
+ .HorizontalAlignment = xlRight
|
|
849
|
+ .VerticalAlignment = xlCenter
|
|
850
|
+ .WrapText = False
|
|
851
|
+ .Orientation = 0
|
|
852
|
+ .AddIndent = False
|
|
853
|
+ .IndentLevel = 0
|
|
854
|
+ .ShrinkToFit = False
|
|
855
|
+ .ReadingOrder = xlContext
|
|
856
|
+ .MergeCells = False
|
|
857
|
+ End With
|
|
858
|
+
|
|
859
|
+ xlSheet.Range("A" & N2 & ":C" & N2).Select()
|
|
860
|
+
|
|
861
|
+ With myExcel.Selection
|
|
862
|
+ .HorizontalAlignment = xlCenter
|
|
863
|
+ .VerticalAlignment = xlCenter
|
|
864
|
+ .WrapText = False
|
|
865
|
+ .Orientation = 0
|
|
866
|
+ .AddIndent = False
|
|
867
|
+ .IndentLevel = 0
|
|
868
|
+ .ShrinkToFit = False
|
|
869
|
+ .ReadingOrder = xlContext
|
|
870
|
+ .MergeCells = False
|
|
871
|
+ End With
|
|
872
|
+ myExcel.Selection.Merge
|
|
873
|
+
|
|
874
|
+ xlSheet.Range("A" & N2 + 1 & ":C" & N2 + 1).Select()
|
|
875
|
+
|
|
876
|
+ With myExcel.Selection
|
|
877
|
+ .HorizontalAlignment = xlCenter
|
|
878
|
+ .VerticalAlignment = xlCenter
|
|
879
|
+ .WrapText = False
|
|
880
|
+ .Orientation = 0
|
|
881
|
+ .AddIndent = False
|
|
882
|
+ .IndentLevel = 0
|
|
883
|
+ .ShrinkToFit = False
|
|
884
|
+ .ReadingOrder = xlContext
|
|
885
|
+ .MergeCells = False
|
|
886
|
+ End With
|
|
887
|
+ myExcel.Selection.Merge
|
|
888
|
+
|
|
889
|
+ xlSheet.Range("D" & N2 + 1 & ":E" & N2 + 1).Select()
|
|
890
|
+
|
|
891
|
+ With myExcel.Selection
|
|
892
|
+ .HorizontalAlignment = xlCenter
|
|
893
|
+ .VerticalAlignment = xlCenter
|
|
894
|
+ .WrapText = False
|
|
895
|
+ .Orientation = 0
|
|
896
|
+ .AddIndent = False
|
|
897
|
+ .IndentLevel = 0
|
|
898
|
+ .ShrinkToFit = False
|
|
899
|
+ .ReadingOrder = xlContext
|
|
900
|
+ .MergeCells = False
|
|
901
|
+ End With
|
|
902
|
+ myExcel.Selection.Merge
|
|
903
|
+
|
|
904
|
+ For i As Integer = 1 To N2 + 1
|
|
905
|
+ xlSheet.Rows(i).AutoFit
|
|
906
|
+ xlSheet.Rows(i).RowHeight = xlSheet.Rows(i).RowHeight + 4
|
|
907
|
+
|
|
908
|
+ Next
|
|
909
|
+
|
|
910
|
+ End Sub
|
644
|
911
|
Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet, ByVal allSame As Boolean)
|
645
|
912
|
xlSheet.Activate() ' 激活工作表
|
646
|
913
|
xlSheet.Parent.Windows(1).View = XlWindowView.xlPageLayoutView
|