Table to text and format text

Tagged: ,

Viewing 1 reply thread
  • Author
    Posts
    • #104207

      Help! I import XML with multiple tables. I don’t want the tables. I only want the text and I want that text formatted to a certain paragraph style.

      I am new to scripting and I’m struggling to understand it. Google helped me find scripts for table to text. I added to the script to format the text to the paragraph style. The script works, but with an error message. I would like to use the script without the error message. (Now, the script isn’t working at all!)

      Here’s the script:
      var myDoc=app.activeDocument;
      tableList = myDoc.textFrames.everyItem().tables.everyItem();
      tableList.convertToText(“\t”,”\r”);
      var myText = myTextFrame.parentStory.characters.everyItem();
      myText.appliedParagraphStyle = myDoc.paragraphStyles.item(“[Price Section]”);

      Here’s the error message:
      error 30476
      the requested action could not be completed because the object no longer exists
      engine: main
      (script location)
      Line: 3
      Source: tableList.convertToText(“\t”,”\r”);

    • #104209
      Loic Aigon
      Member

      Hi,

      A possible option is to not use scripting but XSLT. You can then easily drop tables out and apply styles:

      <pre class=”brush:xml”>
      <?xml version=”1.0″ encoding=”UTF-8″?>
      <xsl:stylesheet xmlns:xsl=”https://www.w3.org/1999/XSL/Transform&#8221;
      xmlns:xs=”https://www.w3.org/2001/XMLSchema&#8221;
      xmlns:aid=”https://ns.adobe.com/AdobeInDesign/4.0/&#8221;
      xmlns:aid5=”https://ns.adobe.com/AdobeInDesign/5.0/&#8221;
      exclude-result-prefixes=”xs”
      version=”1.0″>

      <xsl:output method=”xml” encoding=”UTF-8″/>

      <xsl:template match=”Root”>
      <Root xmlns:aid=”https://ns.adobe.com/AdobeInDesign/4.0/&#8221;
      xmlns:aid5=”https://ns.adobe.com/AdobeInDesign/5.0/&#8221;
      >
      <xsl:apply-templates/>
      </Root>

      </xsl:template>

      <xsl:template match=”node()|@*”>
      <xsl:copy>
      <xsl:apply-templates select=”node()|@*”/>
      </xsl:copy>
      </xsl:template>

      <xsl:template match=”table”/>

      <xsl:template match=”p” >

      <xsl:copy>
      <xsl:attribute name=”aid:pstyle”>[Price Section]</xsl:attribute>
      <xsl:apply-templates select=”@*|node()”></xsl:apply-templates>

      </xsl:copy>

      </xsl:template>
      </xsl:stylesheet>

      Then you can import and it’s all ok:

      https://image.ibb.co/jEWVdT/Capture_d_e_cran_2018_06_05_a_23_52_49.png

Viewing 1 reply thread
  • You must be logged in to reply to this topic.
>