[Lazarus] fpspreadsheet - automatic column width

Roberto P. padovani.r at gmail.com
Tue Mar 22 16:16:45 CET 2016


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 <werner.pamler at freenet.de>:

> 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
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160322/f59ef410/attachment-0003.html>


More information about the Lazarus mailing list