How to Create and apply a cell format setting

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
David
Posts: 4
Joined: Wed Mar 02, 2011 6:46 am

How to Create and apply a cell format setting

Post by David »

Hi

We have recently upgraded from ReadWriteII to ReadWriteII 4.
We are struggling to get our old format settings recreated after changing to the newer version.

We used to create a list of formats which we would then assign when writing out the cells of the spreadsheet we are creating.
So we create our formats as:

with FXLSWriter.Formats.Add do begin
Name := 'fmtHeader';
FontIndex := FXLSWriter.Fonts.AddIndex;
FXLSWriter.Fonts[FontIndex].Name := 'Arial';
FXLSWriter.Fonts[FontIndex].Size := 11;
FXLSWriter.Fonts[FontIndex].Charset := ANSI_CHARSET;
FXLSWriter.Fonts[FontIndex].Color := xcDarkBlue;
FXLSWriter.Fonts[FontIndex].Style := [];
FXLSWriter.Fonts[FontIndex].SubSuperScript := xssNone;
FXLSWriter.Fonts[FontIndex].Underline := xulNone;
HorizAlignment := chaGeneral;
VertAlignment := cvaTop;
Protection := [];
end;


Then later find the format index and use as below:
fmtHdr := FXLSWriter.Formats.IndexByName('fmtColumnHeader');
FXLSWriter.Sheets.Items[0].WriteString(ColIndex, FCurrentRow, fmtHdr , MemoText);

We cannot seem to get this to work in the new version of ReadWrite.
However we can set all the option on a cell e.g
FXLSWriter4.Sheets.Items[0].Cell[fColumn, FCurrentRow].FontName .FontSize .VertAlignment etc.

Can someone tell us whether it is still possible to keep our old manner of doing things or more or less how we would
go about changing this.

Thanks
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: How to Create and apply a cell format setting

Post by larsa »

Hello

You can't use the old way (with FormatIndex and FontIndex) to format cells. This may result in corrupt files. Use the Cell properties for formatting cells. You can also use the Range properti for formatting whole range of cells.
Lars Arvidsson, Axolot Data
Post Reply