0

I have this code that works:

var myTable = app.activeDocument.stories.everyItem().tables.everyItem().getElements();  

for(i=0; i<myTable.length; i++) {  
  myTable[i].cells[0].insertionPoints[0].appliedParagraphStyle = app.activeDocument.paragraphStyleGroups.item("Wycena").paragraphStyles.item("Nazwa A. Numeracja2"); 
}

This code applies one Paragraph Style to all rows in a Table, however what I need is as follows:

  • If I paste text that does begin with a bullet symbol () into a Table then apply "Paragraph Style 1"
  • If I paste text that does not begin with a bullet symbol () into a Table then apply "Paragraph Style 2".

What I think I need is an if statement somewhere, but I cant work it out.

RobC
  • 22,977
  • 20
  • 73
  • 80
dizek
  • 3
  • 2
  • 1
    if this is the same question as [your previous question](https://stackoverflow.com/questions/56764799/adobe-changing-table-style-script), then I suggest you delete your previous question by clicking the _"Delete"_ button below it. In the future, If you want to make changes to a question you should click the `"Edit"` button and make changes to your original question instead of asking the same question twice. – RobC Jun 26 '19 at 11:37

1 Answers1

0

You can apply Paragraph Style 2 to all the text and then run the script to format only the text with the bullet symbol:

var myDocument = app.documents.item(0);    
var allCells = myDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();  
for ( var i = 0; i < allCells.length; i++)  
{  

if ( allCells[i].contents.indexOf('•') > -1)  
{  
    allCells[i].appliedCellStyle = 'Paragraph Style 1';  
    allCells[i].clearCellStyleOverrides();  
 }  
}

You can change the "•" to any other text you want a specific format and that cell will be formatted accordingly.

FONSPA
  • 13
  • 6