Setting cell sizes is very inaccurate.

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
d3nton
Posts: 133
Joined: Thu Oct 25, 2012 9:48 am

Setting cell sizes is very inaccurate.

Post by d3nton »

If I set the pixelSize of a row or column the width or height of the column/row is very inaccurate.
It seems also to be very inconsistent.
Small example:

Code: Select all

  XLS := TXLSReadWriteII5.Create(nil);
  XLS.Filename := 'D:\test.xlsx';
....
  XLS[0].Columns[0].PixelWidth := 64   <-results in '56'.
...
 for i = 0 to 100 do begin
  XLS[0].Columns[0].PixelWidth := XLS[0].Columns[0].PixelWidth  <- This should not change the width but afterwards the width is '0' or even negative! 
end ...
the same happens to the row height.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Setting cell sizes is very inaccurate.

Post by larsa »

Hello

The problem is that reading/writing the PixelWidth property is not compatible. Unfortunately, it's not possible to change the behavior as other parts is dependent on it. Instead, there is a new property, PixelWidth2 that reads/writes compatible values.
Lars Arvidsson, Axolot Data
d3nton
Posts: 133
Joined: Thu Oct 25, 2012 9:48 am

Re: Setting cell sizes is very inaccurate.

Post by d3nton »

Hello!

Thank you, but the values seem not to be correct.
If I set the pixelwidth2 of a column to e.g.500 pixels and open the file afterwards, excel tells me that the width of the column is 497 pixels.
This is only a minor issue if i format just one column but i need to format lots of columns and the difference between the desired width and the actual width will be greater.
The width of the columns also affects images even if I set the positioning of the images to limage.Positioning := doipdonotmoveorsize;
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Setting cell sizes is very inaccurate.

Post by larsa »

Hello

Sorry, this is the best for the moment. The problem is that the cell width is based on character widths and converting this to pixels is difficult as the documentation is not good on this. My suggestion is to not use pixels when setting the width.
Lars Arvidsson, Axolot Data
Post Reply