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

Free Support Forum - aspose.com

Style in XLS does not get converted to PDF

Hi,

One of my column in the XLS in right justified. When I tried to convert the XLS to PDF, the style information for the right justified column did not get carried over to the PDF - it's always left justified Can you please help?

Below is my code:

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

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

Column columnCurrency = cells.Columns[1];

Aspose.Cells.Style style;

StyleFlag flag;

style = workbook.Styles[workbook.Styles.Add()];

style.Number = 7;

style.HorizontalAlignment = TextAlignmentType.Right;

flag = new StyleFlag();

flag.NumberFormat = true;

columnCurrency.ApplyStyle(style, flag);

sheet.Cells.ImportDataTable(dtData, false, "A8");

sheet.AutoFitColumns();
_SaveAsFileName = SaveAsFileName + ".pdf";
string filePathXLS = Server.MapPath("~/tempdata/xlsToPDF.xls");
string filePathXML = Server.MapPath("~/tempdata/xlsToPDF.xml");
// Saving an XLS file in Aspose.Pdf xml format
workbook.Save(filePathXLS);
workbook.Open(filePathXLS);
workbook.Worksheets[0].PageSetup.FitToPagesWide = 1;
workbook.Save(filePathXML, 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(filePathXML, null);

pdf.IsLandscape = true;
pdf.Save(_SaveAsFileName, Aspose.Pdf.SaveType.OpenInAcrobat, this.Response);

Hi,

I implemented your scenario but could not reproduce the issue you have mentioned.

Could you post your template excel file here, we want to check and figure out the issue if we found.

Thank you.

Ok. thanks. attached please find the xls file.

Hi,

Thanks for providing us the template file.

Well, I checked your code closely in your previous post, I think you are making a minor (small) mistake for a portion, See your code now and correct it accordingly:

...............
Aspose.Cells.Style style;

StyleFlag flag;

style = workbook.Styles[workbook.Styles.Add()];

style.Number = 7;

style.HorizontalAlignment = TextAlignmentType.Right;

flag = new StyleFlag();

flag.NumberFormat = true;

flag.HorizontalAlignment = true;

columnCurrency.ApplyStyle(style, flag);

sheet.Cells.ImportDataTable(dtData, false, "A8");

sheet.AutoFitColumns();
................

Thank you.

Thank you so much! that fixed it.