How to copy cell format to a new cell

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
fapeorfer
Posts: 2
Joined: Tue Nov 03, 2009 3:59 pm

How to copy cell format to a new cell

Post 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
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: How to copy cell format to a new cell

Post 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);
Lars Arvidsson, Axolot Data
fapeorfer
Posts: 2
Joined: Tue Nov 03, 2009 3:59 pm

Re: How to copy cell format to a new cell

Post 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
Post Reply