Skip to content

Instantly share code, notes, and snippets.

@milk19873
Created September 4, 2017 09:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save milk19873/f1f1ddd668d3e03407af9cc5eba0d86b to your computer and use it in GitHub Desktop.
ボタンクリックによるPDF出力例1
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