Change all background color X to color Y

Discuss the spreadsheet application
Locked
swampwiz
Posts: 40
Joined: Wed Mar 17, 2010 11:30 am

Change all background color X to color Y

Post by swampwiz »

Would like an extension that can change all cells of a certain background color to another
That's it. I have a spreadsheet with over 100K cells, and I'd like to swap a pair of background colors, both of which are custom colors that for whatever reason have not persisted in the color palette. :crazy:

 Edit: Changed subject, was Would like an extension that can change all cells of a certain background color to another
It's best to say what you want to do without suggesting how because that often leads to XY Problem.
Make your post understandable by others 
-- MrProgrammer, forum moderator 
Last edited by MrProgrammer on Mon Jul 01, 2024 3:29 pm, edited 1 time in total.
Windows XP Professional, Version 5.1, Service Pack 3
OpenOffice 4.1.2
(perhaps later versions since these are really old and obsolete -- MrProgrammer, forum moderator)
User avatar
MrProgrammer
Moderator
Posts: 5430
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Change all background color X to color Y

Post by MrProgrammer »

swampwiz wrote: Sun Jun 09, 2024 1:25 pm both of which are custom colors that for whatever reason have not persisted in the color palette
Color picker not showing current color
[Solved] I've accidentally modified a pre-defined color! (your own topic)

swampwiz wrote: Sun Jun 09, 2024 1:25 pm I have a spreadsheet with over 100K cells, and I'd like to swap a pair of background colors
When you use styles instead of directly setting the cell background color with Format → Cells, then this task is trivial. You just select the two styles and change their background colors. All of the cells which use those styles are immediately changed.

You will continue to struggle with spreadsheets until you learn how to use styles. The best solution is to remove all direct formatting in your entire spreadsheet, then create and apply styles to set the background colors and other formatting attributes like font, alignment, underlining, number format, etc. It is easy to apply a style to a range of cells by selecting them and double-clicking the style in Format → Styles and Formatting. You were advised to use styles in 2016 so this mess is something you created for yourself. It is better to apply formatting as the last step in creating a spreadsheet.

swampwiz wrote: Sun Jun 09, 2024 1:25 pm Would like an extension that can change all cells of a certain background color to another.
You could try RGB which I found immediately by searching the extension website for color. But I don't think this will fix the underlying problem that your spreadsheet does not use styles. I have never installed any extensions from that website. If RGB doesn't seem to help for this task you can make the changes to the cell background colors with macros, as explained in these two topics. I would use a new range to get the background color of every cell in the range which needs to be updated. Then I'd use Find&Replace to change the colors there as desired, for example swapping AABBCC with DDEEFF and leaving the other colors unchanged. Finally I'd set the color of every cell in the range which needs to be updated to the new colors. You might need to modify the macro from the second topic a bit for your task. I do not offer to help with that.
Get cell color as RGB value in another cell
Set cell color from RGB value in another cell

If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.

[Tutorial] Ten concepts that every Calc user should know
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.8, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
swampwiz
Posts: 40
Joined: Wed Mar 17, 2010 11:30 am

Re: Change all background color X to color Y

Post by swampwiz »

> You will continue to struggle with spreadsheets until you learn how to use styles.

Redditors would say, "you will continue to struggle while you continue to use Apache OpenOffice".

I guess I'm hosed in that there will be no way to easily change every cell that has a certain background color to having a style. And it would probably be easier for me to write my own console app that would do this programmatically.
Windows XP Professional, Version 5.1, Service Pack 3
OpenOffice 4.1.2
(perhaps later versions since these are really old and obsolete -- MrProgrammer, forum moderator)
User avatar
RoryOF
Moderator
Posts: 35210
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Change all background color X to color Y

Post by RoryOF »

You might investigate editing content.xml with a suitable editor. The OpenOffice file is in fact a .zip file and can be opened with an archive manager, to permit access to its components.
Apache OpenOffice 4.1.16 on Xubuntu 24.04.4 LTS
FJCC
Moderator
Posts: 9623
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Change all background color X to color Y

Post by FJCC »

@swampwiz - There might be a way to recolor your cells easily with a formula or a simple macro. Are the cells colored because they meet some criteria? Is the whole data set confined to a single block without blank rows or merged cells? Please describe the data layout, make an example document with a much small data set and post it here.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
swampwiz
Posts: 40
Joined: Wed Mar 17, 2010 11:30 am

Re: Change all background color X to color Y

Post by swampwiz »

FJCC wrote: Sun Jun 09, 2024 10:41 pm @swampwiz - There might be a way to recolor your cells easily with a formula or a simple macro. Are the cells colored because they meet some criteria? Is the whole data set confined to a single block without blank rows or merged cells? Please describe the data layout, make an example document with a much small data set and post it here.
No, the colored cells are all over the place, with no other identifying information.
Windows XP Professional, Version 5.1, Service Pack 3
OpenOffice 4.1.2
(perhaps later versions since these are really old and obsolete -- MrProgrammer, forum moderator)
User avatar
RoryOF
Moderator
Posts: 35210
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Change all background color X to color Y

Post by RoryOF »

With an archive manager, open the OpenOffice file and then open content.xml with a suitable plain text editor. Find all instances of "aabbcc" and replace with "xxyyzz" where "aabbcc" is the six letter/digit code of the unwanted colour and "xxyyzz" is the code for the new replacement colour. Global Find and Replace will probably do the job very swiftly. Then Save content.xml, rezip the archive with this new content.xml, and all should be correct.

Of course, the usual caveats about using a copy file apply, as also ability to use the various tools correctly.

This would take less than five minutes for the entire process.
Apache OpenOffice 4.1.16 on Xubuntu 24.04.4 LTS
Alex1
Volunteer
Posts: 852
Joined: Fri Feb 26, 2010 1:00 pm
Location: Netherlands, EU

Re: Change all background color X to color Y

Post by Alex1 »

I tried RoryOF's solution. A spreadsheet with 100k cells isn't too big for Notepad. Keep in mind that all sheets are processed with global replacing.
Unlike OpenOffice, LibreOffice shows the hexadecimal color values in the cell formatting dialog.
AOO 4.1.16 & LO 25.8.3 on Windows 10
User avatar
RoryOF
Moderator
Posts: 35210
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Change all background color X to color Y

Post by RoryOF »

Users often overlook the possibility of editing content.xml. This can be dangerous, as an error can (read: probably will) damage the altered file, hence the suggestion to use a copy file until all is well.
Apache OpenOffice 4.1.16 on Xubuntu 24.04.4 LTS
swampwiz
Posts: 40
Joined: Wed Mar 17, 2010 11:30 am

Re: Change all background color X to color Y

Post by swampwiz »

RoryOF wrote: Mon Jun 10, 2024 3:15 pm With an archive manager, open the OpenOffice file and then open content.xml with a suitable plain text editor. Find all instances of "aabbcc" and replace with "xxyyzz" where "aabbcc" is the six letter/digit code of the unwanted colour and "xxyyzz" is the code for the new replacement colour. Global Find and Replace will probably do the job very swiftly. Then Save content.xml, rezip the archive with this new content.xml, and all should be correct.

Of course, the usual caveats about using a copy file apply, as also ability to use the various tools correctly.

This would take less than five minutes for the entire process.
What is an "archive manager"?
Windows XP Professional, Version 5.1, Service Pack 3
OpenOffice 4.1.2
(perhaps later versions since these are really old and obsolete -- MrProgrammer, forum moderator)
User avatar
Hagar Delest
Moderator
Posts: 33629
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Change all background color X to color Y

Post by Hagar Delest »

An application like Winzip or 7zip to compress/decompress files.
LibreOffice 25.2 on Linux Mint Debian Edition (LMDE 7 Gigi) and 25.2 portable on Windows 11.
swampwiz
Posts: 40
Joined: Wed Mar 17, 2010 11:30 am

Re: Change all background color X to color Y

Post by swampwiz »

Hagar Delest wrote: Mon Jul 01, 2024 11:37 pm An application like Winzip or 7zip to compress/decompress files.
But wouldn't the file be all mangled because of the compression?
Windows XP Professional, Version 5.1, Service Pack 3
OpenOffice 4.1.2
(perhaps later versions since these are really old and obsolete -- MrProgrammer, forum moderator)
FJCC
Moderator
Posts: 9623
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Change all background color X to color Y

Post by FJCC »

All OpenOffice files are zip files. You can change the name of a Calc file named Data.ods to Data.zip and then open it with and archive manager. Windows will show a warning when you change the file extension, but it's safe to do. In the zip file you will see a file named Content.xml which contains the data and formatting of your spreadsheet. However, if you are not familiar with editing xml data, you might find the Content.xml file rather imposing. Always make a back up copy of a file before editing its Content.xml file.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
Zizi64
Volunteer
Posts: 11505
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Change all background color X to color Y

Post by Zizi64 »

And it would probably be easier for me to write my own console app that would do this programmatically.
vs:
What is an "archive manager"?
But wouldn't the file be all mangled because of the compression?

I suggest you to use
- the existing features of the office suites (mainly the styles)
- LibreOffice instead of the OpenOffice


All of the XML based documents (the ODF of the Document Foundation and the OOXML of the Microsoft) use compressed (lossless compressed) formats, because they have normal file system stuctures inside: There are Folders and Files inside the "document file".
Tibor Kovacs, Hungary; LO7.5.8/25.8.5.2 /Win7-10-11 x64Prof.
PortableApps: LO3.3.0-25.8.5.2;AOO4.1.14
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.
swampwiz
Posts: 40
Joined: Wed Mar 17, 2010 11:30 am

Re: Change all background color X to color Y

Post by swampwiz »

Zizi64 wrote: Tue Jul 02, 2024 6:44 am
And it would probably be easier for me to write my own console app that would do this programmatically.
vs:
What is an "archive manager"?
But wouldn't the file be all mangled because of the compression?

I suggest you to use
- the existing features of the office suites (mainly the styles)
- LibreOffice instead of the OpenOffice


All of the XML based documents (the ODF of the Document Foundation and the OOXML of the Microsoft) use compressed (lossless compressed) formats, because they have normal file system stuctures inside: There are Folders and Files inside the "document file".
It's far too late to modify all the cels. I have about 24K of them in no particular order. :knock:
Windows XP Professional, Version 5.1, Service Pack 3
OpenOffice 4.1.2
(perhaps later versions since these are really old and obsolete -- MrProgrammer, forum moderator)
User avatar
Hagar Delest
Moderator
Posts: 33629
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Change all background color X to color Y

Post by Hagar Delest »

swampwiz wrote: Sun Jun 09, 2024 5:38 pm Redditors would say, "you will continue to struggle while you continue to use Apache OpenOffice".
In this very case, I doubt any application would natively do better.
swampwiz wrote: Sun Jun 09, 2024 5:38 pm it would probably be easier for me to write my own console app that would do this programmatically.
Then go for it, you have all you need. Either the macro way by testing the background color and replacing it when needed or the surgical way by doing that manually find and replace directly in the inner files of the .ods.
LibreOffice 25.2 on Linux Mint Debian Edition (LMDE 7 Gigi) and 25.2 portable on Windows 11.
Locked