• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

remove cell style - preserve formatting

Contributor ,
Dec 14, 2011 Dec 14, 2011

Copy link to clipboard

Copied

Hello Scripters,

Is it possible to preserve the formatting, when I remove an applied cell style with the following code?

     “MyCellStyle.remove(app.activeDokument.cellStyles.firstItem());”

How can I get access to this feature in my script? (see also screenshot->red arrow)

perserve_formating.png

Thanks for hints.

Roland

TOPICS
Scripting

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 15, 2011 Dec 15, 2011

Roland:
You could iterate through all your cells with the applied cell style, select the cells one after another and apply a menu action to break the link to the style ("Break Link to Style" / "Verknüpfung mit Format aufheben").

Then you can remove the cell style without loosing any formatting.

To invoke the menu action you could use this code. For security reasons I wrapped it up with a "try/catch":

//Disconnect the cell with the applied cell style (option in the cell styles panel of the UI: "Break

...

Votes

Translate

Translate
LEGEND ,
Dec 14, 2011 Dec 14, 2011

Copy link to clipboard

Copied

It looks to me like it's missing. File a feature request...

To simulate the funtionality, you'll probably have to grab the properties of the style, and then loop through the doc, find every cell that has the style applied, and apply the styling manually...

Good luck!

Harbs

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 14, 2011 Dec 14, 2011

Copy link to clipboard

Copied

I already feared it. Well, I must try another way.

Many thanks for your answer.

Kind regards

Roland

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Dec 14, 2011 Dec 14, 2011

Copy link to clipboard

Copied

I've haven't tried this or even looked into it, but last week when I was

trying to remove a character style from text and retain formatting, the

answer was to apply the style (which does not remove formatting)

first.

So maybe try applying No Cell Style?

Ariel

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 14, 2011 Dec 14, 2011

Copy link to clipboard

Copied

The problem is this:

I want to convert the formatting from one cell to another (in a different table). After this, the formatting of the new cell should be retained, but the cell Style is to be deleted. 

So I remove the generated cell style and replace it with cellStyle:[None] but there is also no option to reserve formatting via script.

For ChararacterStyle it’s the same: there is no option like in the GUI

void remove([replacingWith: CharacterStyle])

Now I try to work with the properties of the cell.

Kind regards

Roland

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 15, 2011 Dec 15, 2011

Copy link to clipboard

Copied

Roland:
You could iterate through all your cells with the applied cell style, select the cells one after another and apply a menu action to break the link to the style ("Break Link to Style" / "Verknüpfung mit Format aufheben").

Then you can remove the cell style without loosing any formatting.

To invoke the menu action you could use this code. For security reasons I wrapped it up with a "try/catch":

//Disconnect the cell with the applied cell style (option in the cell styles panel of the UI: "Break Link to Style" / "Verknüpfung mit Format aufheben"):

try{app.scriptMenuActions.itemByID(132129).invoke()}catch(e){};


Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 15, 2011 Dec 15, 2011

Copy link to clipboard

Copied

Good point.

Harbs

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 15, 2011 Dec 15, 2011

Copy link to clipboard

Copied

Yes, great! It works. Thanks Uwe.

That avoids a lot of detours ...

Kind regards

Roland

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 15, 2011 Dec 15, 2011

Copy link to clipboard

Copied

Roland wrote:

For ChararacterStyle it’s the same: there is no option like in the GUI

void remove([replacingWith: CharacterStyle])

There we have a different opportunity. We can do that without using menu actions.

As Peter Kahrel pointed out at another thread recently, just apply [None] (myDoc.characterStyles[0]) to the texts using that character style, then you can remove the character style savely. Surprisingly the formatting is preserved after doing so:

http://forums.adobe.com/message/4073431#4073431

Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 15, 2011 Dec 15, 2011

Copy link to clipboard

Copied

LATEST

Yes, you're right.  But if you use the GUI, this is not the case. Strange ...

What I was referring to is: I can't control this behavior with the command "remove".

Kind regards

Roland

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines