c# excel转pdf 页面显示不在一页的问题
用的Microsoft.Office.Interop.Excel的ExportAsFixedFormat,将excel导出成pdf
Workbook workBook = application.Workbooks.Open(sourcePath);
workBook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, desPath);
效果如下:
原始excel
导出的pdf
分了两页。
解决方法,设置workSheet的PageSetup为横向。
Workbook workBook = application.Workbooks.Open(sourcePath); foreach (Worksheet p in workBook.Sheets) { p.PageSetup.Orientation = Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape; p.PageSetup.Zoom = false; p.PageSetup.FitToPagesWide = 1; p.PageSetup.FitToPagesTall = false; } workBook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, desPath);
导出来的效果就和excel一样了