Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-03

fpspreadsheet - automatic column width

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Roberto P.

Dear List,

in (the great) fpspreadsheet library, is there a method to calculate the minimum / optimum column width to fit its contents? Or, can anyone suggest me how to write such method?

I have found the CalcAutoRowHeight , but that's different: it compares the font height with the cell height. I don't know how to calculate a string visual length from its font...

Thanks a lot,

Roberto
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160322/9a9613fd/attachment.html>

Reply by email

Werner Pamler
to Roberto P.
Roberto P. wrote 9 lines
Dear List, in (the great) fpspreadsheet library, is there a method to calculate the minimum / optimum column width to fit its contents? Or, can anyone suggest me how to write such method? I have found the CalcAutoRowHeight , but that's different: it compares the font height with the cell height. I don't know how to calculate a string visual length from its font...

FPSpreadsheet consists of two parts: one is the basic FPSpreadsheet itself which provides the basic worksheet and workbook classes and the interface to the file formats; the other one is the collection of visual components - I assume your question is about the basic FPSpreadsheet. The main design goal here is to keep it free from any visual stuff, i.e. avoid the LCL completely (no unit "graphics"). Therefore, I cannot calculate the pixels needed for the length of a string from TCanvas.TextWidth. Ok - I could try FPCanvas... But I would prefer to just add a flag to the column record telling the reading application "this column has an auto-sized width - calculate it after reading", simply because I don't know how the office applications perform their calculations. But while there is such a flag for the row heights, there is none for the column widths. But even the autocalc row height flag does not work as I'd wish because the main office apps additionally want the precise row height.

In the visual package, on the other hand, there's the grid which is allowed to use TCanvas, of course, and there is even an AutoAdjustColumn method. It is called when a double click is performed at the dividing line between two column headers (like in Excel). I did not check, though, how the saved column width fits with what the office application requires.

Reply by email

Roberto P.
to Werner Pamler

I understand...
At the moment I am manually setting the width of a column by looping on the contents of all rows and then setting it to the maximum of the string length (given the unit of measure "width of character '0' "). To make it work well enough, I am still missing one point: is there a way to detect which is the last used row in a column or the last used column in a row?
A single cell is "not enough".

Thanks....great library !!

Roberto

2016-03-22 14:28 GMT+01:00 Werner Pamler :

Show quoted text 40 lines
Am 22.03.2016 um 11:12 schrieb Roberto P.: > Dear List, > > in (the great) fpspreadsheet library, is there a method to calculate the > minimum / optimum column width to fit its contents? > Or, can anyone suggest me how to write such method? > > I have found the CalcAutoRowHeight , but that's different: it compares > the font height with the cell height. I don't know how to calculate a > string visual length from its font... > FPSpreadsheet consists of two parts: one is the basic FPSpreadsheet itself which provides the basic worksheet and workbook classes and the interface to the file formats; the other one is the collection of visual components - I assume your question is about the basic FPSpreadsheet. The main design goal here is to keep it free from any visual stuff, i.e. avoid the LCL completely (no unit "graphics"). Therefore, I cannot calculate the pixels needed for the length of a string from TCanvas.TextWidth. Ok - I could try FPCanvas... But I would prefer to just add a flag to the column record telling the reading application "this column has an auto-sized width - calculate it after reading", simply because I don't know how the office applications perform their calculations. But while there is such a flag for the row heights, there is none for the column widths. But even the autocalc row height flag does not work as I'd wish because the main office apps additionally want the precise row height. In the visual package, on the other hand, there's the grid which is allowed to use TCanvas, of course, and there is even an AutoAdjustColumn method. It is called when a double click is performed at the dividing line between two column headers (like in Excel). I did not check, though, how the saved column width fits with what the office application requires. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160322/f59ef410/attachment.html>

Reply by email

Werner Pamler
to Roberto P.
Roberto P. wrote
To make it work well enough, I am still missing one point: is there a way to detect which is the last used row in a column or the last used column in a row? A single cell is "not enough".

TsWorksheet.GetLastOcccupiedRowIndex, GetLastOccupiedColIndex determine the indexes of the last cell of the worksheet.

There's also a TsWorksheet.GetLastRowIndex, GetLastColIndex which consider also Row and Column records (needed for predefined row heights and column widths) beyond the last occupied cell. Both have an optional parameter "ForceCalculation" which you should set to true in your first call in order to initialize the cached value.

Reply by email

Roberto P.
to Werner Pamler

TOP !!

Thanks,

Roberto

2016-03-22 17:24 GMT+01:00 Werner Pamler :

Show quoted text 24 lines
Am 22.03.2016 um 16:16 schrieb Roberto P.: > To make it work well enough, I am still missing one point: is there a way > to detect which is the last used row in a column or the last used column in > a row? > A single cell is "not enough". > TsWorksheet.GetLastOcccupiedRowIndex, GetLastOccupiedColIndex determine the indexes of the last cell of the worksheet. There's also a TsWorksheet.GetLastRowIndex, GetLastColIndex which consider also Row and Column records (needed for predefined row heights and column widths) beyond the last occupied cell. Both have an optional parameter "ForceCalculation" which you should set to true in your first call in order to initialize the cached value. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160323/c3c5d7df/attachment.html>

Reply by email