i have a task to create function to export Excel file into PDF with requirements that all columns must fit in 1 page .
This is the code i use to convert excel file to pdf.
xlApp = new Excel.Application();
xlWb = xlApp.Workbooks.Open(textBox3.Text);
xlWb.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, Path.GetDirectoryName(textBox3.Text)+ "\\" + Path.GetFileNameWithoutExtension(textBox3.Text) + ".pdf");
But when i open it , it appears that the columns is separated, like if i have like 10 columns , it will split like the first 6 columns in the first page and the last 4 columns in the second page.
How to make it fit to page? it is okay if the potrait is landscape too
so after i do some research , this is the way to setup your page orientation , and you can fit to page
//setup your page orientation + fit to pages
xlWs2.PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape;
xlWs2.PageSetup.Zoom = false;
xlWs2.PageSetup.FitToPagesWide = 1;
xlWs2.PageSetup.FitToPagesTall = false;
//this is how to save as PDF
xlWb2.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF,Path.GetDirectoryName(textBox3.Text) + "\\" + Path.GetFileNameWithoutExtension(textBox3.Text) + ".pdf");
P.S :xlWs2 is excel.Worksheets, xlWb2 is excel.Workbooks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With