Home » C# scripts » Scripts to convert excel to pdf in c# using Microsoft.Office.Interop

Scripts to convert excel to pdf in c# using Microsoft.Office.Interop

Namespace:
using Microsoft.Office.Interop.Excel;

Application application = new Application();
Workbook wbook = application.Workbooks.Open(@"C:\test\TestReport.xls");
foreach (Worksheet wsheet in wbook.Worksheets.OfType<Worksheet>())
{
wsheet.PageSetup.Orientation = XlPageOrientation.xlLandscape;
wsheet.PageSetup.Zoom = false;
wsheet.PageSetup.FitToPagesWide = 1;
wsheet.PageSetup.FitToPagesTall = false;
}
wbook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, @"C:\test\TestReport.pdf", Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityStandard, true, true, 1, 100, false, System.Reflection.Missing.Value);

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *