Font change clears alignment

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
edbuescher
Posts: 6
Joined: Thu Jul 29, 2010 7:11 pm

Font change clears alignment

Post by edbuescher »

Lars,
It seems in the new XLSReadWrite 5 that if I assign a Font to a cell, then I lose any alignment that I have already set. It even prevents alignment after changing the font.
Example:
XLS.Sheets[0].AsString[1,2]:='Center'; // Text is put in cell
XLS.Sheets[0].Cell[1,2].HorizAlignment:=chaCenter; // Text is properly centered
XLS.Sheets[0].Cell[1,2].FontName:='Tahoma'; // Font name is changed AND THE HORIZALIGNMENT is cleared
XLS.Sheets[0].Cell[1,2].HorizAlignment:=chaCenter; // This doesn't correct the HorizAlignment

I have also tested with the CmdFormat methods and I get the same results.
So it appears that changing the Font will prevent any alignment, even if you try to change the alignment after changing the font. I've only tested the Horiz Alignment.

Am I doing something wrong here?
Thanks
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Font change clears alignment

Post by larsa »

Hello

I can't reproduce this. Do you try this on a blank worksheet? If not, there can be row and column formatting that affects the result.
Lars Arvidsson, Axolot Data
edbuescher
Posts: 6
Joined: Thu Jul 29, 2010 7:11 pm

Re: Font change clears alignment

Post by edbuescher »

Lars,
I have spent many hours trying to figure this out. Seem like a lot of time just to get text aligned. Indeed you are correct that I cannot reproduce the problem using just your tools, which led me to what I think is the problem. I was creating the XLSX files with your tools, but then viewing them in my Delphi code with Dev Express's spreadsheet control, which would then left align any text that had a foreground or background color in the cell. When I opened the files in Excel, they were properly aligned. So late yesterday I sent their support team a message about this with a sample XLSX file.
Here is their response that I just got this mornning:
----------------------
I have reproduced the behavior you described. It looks like this third-party tool saves documents not like MS Excel, but it its own way. Indeed, our Spreadsheet opens your sample document differently than MS Excel. However, when I save this document into a new file via MS Excel's main menu, our Spreadsheet starts opening it correctly. You can use this as temporary workaround while we are searching for a way to open such files like MS Excel in our control.
-----------------------
So I still don't know if the problem is their control not accurately rendering the file, or your control not properly setting the cell color. It seems like since Excel can open your file properly, that the issue might be on their side. We'll see if they come up with a fix.
edbuescher
Posts: 6
Joined: Thu Jul 29, 2010 7:11 pm

Re: Font change clears alignment

Post by edbuescher »

Looks like Dev Express is going to patch their controls to fix this.
Post Reply