[Lazarus] fpspreadsheet - automatic column width
werner.pamler at freenet.de
Tue Mar 22 14:28:36 CET 2016
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
More information about the Lazarus