Page 1 of 1

How to copy cell format to a new cell

Posted: Tue Nov 03, 2009 4:34 pm
by fapeorfer
Hello,

I have a cell which has a specific format and I would like to copy the format to a new cells.
The cell contains basically a bunch of text. The text is multi-line.
The first 50 rows in my sheet is formated as follows:

E.g.

========================================================
This is a sample for Axolot

This format is basically for demonstration
text
text
text
========================================================

I tried using the following command, but it does not work.
XLS.CopyCells(ACurrSheet,2,2,2,2,ACurrSheet,2,AIndex,[ccoAdjustCells,ccoForceAdjust,ccoCopyCondFmt]);

I saw a sample before in a thread called "Copy cell-format-settings to a new cell" and it says to use the Assign method, but using the method is not possible:
XLS.Sheets[0].Cell[0,0].Assign(XLS.Sheets[0].Cell[2,2]); .

I also tried also the following code but I get access violation when assigning the second cell in my loop:
XLS.Sheet[ACurrSheet].Cell[2,AIndex].Format.Assign(XLS.Sheets[ACurrSheet].Cell[2,2].Format);

So, after all, how can I copy the the formats from another cell?

Thanks,
Fabio

Re: How to copy cell format to a new cell

Posted: Wed Nov 04, 2009 9:59 pm
by larsa
Hello

Your first example shall work, but omit the copy options. Just use: XLS.CopyCells(ACurrSheet,2,2,2,2,ACurrSheet,2,AIndex);

Re: How to copy cell format to a new cell

Posted: Thu Nov 05, 2009 7:33 am
by fapeorfer
Hello Lars,

[quote="larsa"]Just use: XLS.CopyCells(ACurrSheet,2,2,2,2,ACurrSheet,2,AIndex);[/quote]
It did the job.

I also found another way to do it.
XLS.Sheet[ACurrSheet].AsRichText[2,AIndex] := XLS.Sheets[ACurrSheet].AsRichText[2,2];

Thanks for the answer.

Br,
Fabio