Copy cell-format-settings to a new cell

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
Ironarrow
Posts: 4
Joined: Thu Dec 13, 2007 1:07 pm
Location: Cologne, Germany

Copy cell-format-settings to a new cell

Post by Ironarrow »

Hi everyone,

I want to use a "normal" (with Excel created) file as a template. So my customers can create their own designs for output.
My program uses two XLSReadWriteII components. One to read the template file and one to create the new output-file.

In the template file, each cell is already formated (currency, float, date, font color, border ect.).

It should work like this (I know this aren't the correct commands, but they show what I want to do):

Code: Select all

XLSTemplate.FileName:='c:\template.xls';
XLSTemplate.Read;

myFormat := XLSTemplate.Sheet[0].GetFormat['A1'];
XLSOutPut.Sheet[0].AsString['A1'] := '24';
XLSOutPut.Sheet[0].SetFormat['A1'] := myFormat;

XLSOutPut.FileName :='myoutput.xls';
XlsOutPut.Write;

The cell A1 is a currency-cell. So the final result in cell A1 in XLSOutput should be 24,00 €.

It would be fine, if fontstyle, font color ect. will be copied, too.

Has anyone an idea how this can be done ??

Regards,

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

Post by larsa »

Hello

Use the Assign method.

Example: XLS.Sheets[0].Cell[0,0].Assign(XLS.Sheets[0].Cell[2,2]);


Lars Arvidsson
Ironarrow
Posts: 4
Joined: Thu Dec 13, 2007 1:07 pm
Location: Cologne, Germany

Post by Ironarrow »

Thank you very much.

I will test it as soon as possible.

Regards,

Rainer
Post Reply