Created
September 4, 2017 09:55
-
-
Save milk19873/f1f1ddd668d3e03407af9cc5eba0d86b to your computer and use it in GitHub Desktop.
ボタンクリックによるPDF出力例1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class Form1 : Form | |
{ | |
private Excel.Application PDFExcel; | |
private Excel.Workbook PDFWorkbook; | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
//実際にインスタンス生成を行います | |
PDFExcel = new Excel.Application(); | |
// ウィンドウは非表示にします | |
PDFExcel.Visible = false; | |
//Excelファイルをオープンします | |
PDFWorkbook = (Excel.Workbook)(PDFExcel.Workbooks.Open( | |
@"C:\test\TestExcelBook.xlsx"//PDF化するExcelファイルのパス | |
)); | |
//Excelのシートを全て選択状態にします | |
PDFWorkbook.Worksheets.Select(); | |
//Excelのシート全てをPDF化します | |
PDFWorkbook.ExportAsFixedFormat( | |
Excel.XlFixedFormatType.xlTypePDF, | |
@"C:\test\TestExcelBook.pdf",//PDFファイルの出力パス | |
Excel.XlFixedFormatQuality.xlQualityStandard //出力のクオリティ | |
); | |
//ブックをクローズします | |
PDFWorkbook.Close(); | |
//アプリケーションを終了します | |
PDFExcel.Quit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment