We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to adjust column widths while converting from Xls to PDF


I have one page xls file which contains two columns of data. The first column contains strings and the second columns contains some numbers. After converting the xls to PDF, the PDF got divided into two pages. One page contains the first column and the other page contains the second column. The page is set to use Landscape mode. Can you please let me know how to place both columns on the same page? In the XLS file before coversion, both columns fit on the same page. If changing the column width will solve this issue, how do I adjust the PDF's column width?

Below is my code:

Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
sheet.Name = "Expenses";

string fileName = "logo.gif";

//Obtain the cells of the first worksheet.
Aspose.Cells.Cells cells = workbook.Worksheets[0].Cells;

//Accessing a column from the Columns collection
Column columnCurrency = cells.Columns[1];
//Column columnDates = cells.Columns[3];
Aspose.Cells.Row rowHeader = cells.Rows[6]; //first row of data?

Aspose.Cells.Style style;
StyleFlag flag;
style = workbook.Styles[workbook.Styles.Add()];
style.Number = 7;
flag = new StyleFlag();
flag.NumberFormat = true;
columnCurrency.ApplyStyle(style, flag);
sheet.Cells.ImportDataTable(dtData, false, "A8");

workbook.Save("C:\\xls2pdf.xml", FileFormatType.AsposePdf);

// Converting XLS file to PDF through Aspose.Pdf using Aspose.Pdf xml file as a medium
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
pdf.BindXML("c:\\xls2pdf.xml", null);
pdf.IsLandscape = true;
pdf.Save("xls2pdf.pdf", Aspose.Pdf.SaveType.OpenInAcrobat, this.Response);


Well, you may adjust / change the width / height of the columns / rows using Aspose.Cells APIs. Please check:



And I think, alternatively, you may try to add a line of code to use the option i.e. fit to 1 page wide / tall option for your need:



workbook.Worksheets[0].PageSetup.FitToPagesWide =1;

workbook.Save("C:\\xls2pdf.xml", FileFormatType.AsposePdf);


Thank you.

thank you. it works