We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Vertical alignment of Excel cells

Hi,

I am using XlsIO to convert a CSV file to PDF. One requirement is that text is vertically aligned in the centre of each cell. However, applying vertical alignment to the range doesn't seem to have any effect on the final PDF. Other style options such as horizontal alignment and the background colour of the cells work correctly. I think I'm doing this the right way, adding a new style to the workbook, changing the properties of this style and then applying the style to the CellStyle of the range I have selected. I'm using version 14.1.0.41 of Syncfusion.

Here is the code for applying the vertical alignment to the range:

IWorkbook workbook = application.Workbooks.Open(csvPath, ExcelOpenType.CSV);

IWorksheet sheet = workbook.Worksheets[0];

...

IStyle style = workbook.Styles.Add("AlignStyle");

style.VerticalAlignment = ExcelVAlign.VAlignCenter;

IRange range = sheet.Range[4, 1, sheet.UsedRange.LastRow, sheet.UsedRange.LastColumn];

range.CellStyle = style;

range.AutofitColumns();









3 Replies

KD Kesavan D Syncfusion Team June 2, 2016 12:06 PM UTC

Hi Richard, 
 
Thank you for contacting Syncfusion support. 
 
We are unable to reproduce the reported issue from our side. We have prepared a sample based on your requirement and shared it for your reference which can downloaded from the following link. 

 
Kindly try this sample and let us know whether the issue is resolved or not. If you are still facing this issue, then kindly share us the issue reproducing sample which will be helpful for us to provide you a prompt solution at the earliest. 
 
Regards, 
Kesavan


RF Richard Fairweather June 6, 2016 08:27 AM UTC

Hi,

Thanks for the response and sample code.

The only difference in the sample you have provided and my conversion code that I can see is that you are setting the range's RowHeight to 50. This seems to give the appearance of centred vertical alignment. However, if I then reduce the RowHeight, the vertical alignment doesn't seem to be being applied anymore.

I have three PDFs here (attached to this ticket), one with the range's RowHeight set to 50, one set to 25 and one set to 15. I have applied the appearance options from the sample you have provided which seem to display crosses showing the centre of each cell. As you can see in each PDF, the vertical alignment is less and less centred as the RowHeight reduces in each one.

How can I prevent this and have centred vertical alignment regardless of the range's RowHeight?

Regards,
Richard

Attachment: PDF_c4d6b29b.zip


KD Kesavan D Syncfusion Team June 7, 2016 12:09 PM UTC

Hi Richard, 

  

We were able to reproduce the problem and have logged defect report regarding this. A support incident to track the status of this defect has been created under your account. Please log on to our support website to check for further updates 

  

https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents  

  

Please let me know if you have any questions. 

 
Regards, 
Kesavan 


SIGN IN To post a reply.
Loader.
Live Chat Icon For mobile
Up arrow icon