Problem Retaining Font Color in macro when Copying String

Discuss the spreadsheet application

Problem Retaining Font Color in macro when Copying String

Postby alf50 » Thu Apr 30, 2020 7:24 am

I am having a Problem Retaining Font Color in macro when Copying String from one cell to another cell in a Macro.
Code: Select all   Expand viewCollapse view
Cell = Sheet.getCellByPosition(Y+22,X+14)
Crd = Cell.String
Cell = Sheet.getCellByPosition(J+3,I+15)
Cell.string = Crd

The text in the first cell is red, but the text read into variable Crd (a defined String) comes out Black in the second cell.
What is the issue with the "Crd" variable not retaining the Color Characteristic?
OpenOffice 4.1.8 on Mac Catalina(10.15.7) and MS Windows10
User avatar
alf50
 
Posts: 106
Joined: Sun Jun 13, 2010 2:55 pm

Re: Problem Retaining Font Color in macro when Copying Strin

Postby JohnSUN-Pensioner » Thu Apr 30, 2020 9:58 am

If you copy string (only string, not text, not style, not format) why do you wait source font color?

Try to download this book and read chapters 5.23.1 Copy Spreadsheet Cells With The Clipboard and 5.23.2 Copy Spreadsheet Cells Without The Clipboard

 Edit: PDF version of the text John_Sun recommends AndrewMacro.pdf - his link is to an older format. [RoryOF, Moderator] 

 Edit: Update I always encountered the problem of copying code from an PDF file - page numbers got inside, like 106 in this example
Code: Select all   Expand viewCollapse view
Else
For i= 0 to laatsterow - int(mid(oViewCursor.cell.cellname,2,2))
iFotH = iFotH + oViewCursor.texttable.rows.getbyindex(Rindex+ i ).height
Next i
106
End If
Therefore, I usually refer to the text version of this book. 
Last edited by JohnSUN-Pensioner on Fri May 01, 2020 9:14 am, edited 1 time in total.
I may not have a lot to give but what I got I'll give to you...
Apache OpenOffice 4.1.5, LibreOffice 6.4.4.2 (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
User avatar
JohnSUN-Pensioner
Volunteer
 
Posts: 826
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: Problem Retaining Font Color in macro when Copying Strin

Postby Zizi64 » Thu Apr 30, 2020 10:34 am

Apply same cell style what the source cell was applied for. (Get the cell style name from the source cell and Set same cell style for the target cell.)
Use the styles instead of the direct formatting properties. When you use the direct formatting properties, then you must get and set all of the individual properties one by one:
Get text color/set text color;
get background color/set background color;
get font type/set font type;
get font size/set font size;
get border/set border; ...etc...etc...

It is available with only one+one steps when you use the Cell styles (get style/set style)
Tibor Kovacs, Hungary; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.4.5;AOO4.1.7
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 9704
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary


Return to Calc

Who is online

Users browsing this forum: No registered users and 19 guests