將欄位較多的Excel文件自動列印在同一頁(將所有欄放入單一頁面)。
作法:
using Excel = Microsoft.Office.Interop.Excel;
Excel.Application excel = new Excel.Application();
Excel.Workbook workbook = excel.Workbooks.Open(excelPath);
Excel.Worksheet worksheet = (Excel.Worksheet)workbook.ActiveSheet;
//Fit all columns on one page
excel.PrintCommunication = false;
Excel.PageSetup pageSetup = worksheet.PageSetup;
//FitToPagesTall property設為false,則以FitToPagesWide來縮放Worksheet
pageSetup.FitToPagesTall = false;
pageSetup.FitToPagesWide = 1;
excel.PrintCommunication = true;
workbook.Save();
worksheet.PrintOutEx();
workbook.Close();
excel.Quit();
參考來源:
https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.pagesetup.fittopagestall(v=office.15).aspx
http://stackoverflow.com/questions/25741049/how-to-set-fit-all-columns-on-one-page-in-print-tab
沒有留言:
張貼留言