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

Convert Text to Table Using Extendscript

Contributor ,
Dec 31, 2022 Dec 31, 2022

Copy link to clipboard

Copied

I'm writing a report to a new document in comma delimited text.  I can select all the text (Ctrl-A) and use FrameMaker's Convert Text to Table dialogue to create the desired table.  However, was wondering if there's a way to convert text to table in extendscript.  I've checked all available posts going back to 2009 and can't seem to find anything.  BTW, Happy New Year to everyone!

Views

179

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 ,
Jan 02, 2023 Jan 02, 2023

Copy link to clipboard

Copied

Happy New Year and a welcome to a great challenge. I have done a few of these over the years but I think they were all in FrameScript before ExtendScript was a thing in FrameMaker. One of the hardest parts can be separating each delimited line into "fields" if there are quoted fields with commas in them. If you don't have that to worry about, it is easier. One thing to google: parse comma delimited text with regular expressions.

 

Since it looks like you want to work with selected text, you can use doc.GetTextForRange (Constants.FTI_PgfBegin) to break the selection into a series of lines or paragraphs. Then, for each one, you will need to parse the line into fields. That will give you a count of how many rows and columns your table needs. I know I am not giving you any code here; just exploring the algorithms.

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 ,
Jan 02, 2023 Jan 02, 2023

Copy link to clipboard

Copied

If you have a lot of these to do, there is another approach that I would explore: Use XSLT to convert the comma-delimited text to XML. FrameMaker has a couple of XSLT processors built into it's structured side that can be automatically triggered on File > Open. I have written XSLT stylesheets to convert comma-delimited text to XML. The XML would mimic the table structure that you want in FrameMaker. You would need a FrameMaker structured application that would convert the XML to a table on File > Open. If you want to explore this further, please contact me offlist. Thank you.

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 ,
Jan 02, 2023 Jan 02, 2023

Copy link to clipboard

Copied

Fightergator: However, was wondering if there's a way to convert text to table in extendscript.

I would think so. It's not that hard to generate FM table MIF. I'm not experienced in either FrameScript or ExtendScript, but I have created spreadsheets into which one pastes raw delimited text on one sheet, the next sheet frames each line with row & cell MIF, and a 3rd sheet concatenates all of it in complete Table MIF (in the desired style). Copy'n'paste into the document's .mif. It's been perhaps a decade since, so don't ask for details…

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 ,
Jan 02, 2023 Jan 02, 2023

Copy link to clipboard

Copied

This is another good approach. If you google FrameMaker MIF Reference, you should see an example of this.

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 ,
Jan 03, 2023 Jan 03, 2023

Copy link to clipboard

Copied

LATEST

My thanks to both of you.  I'll explore both options, but may be easier to just go into my report page, use Ctrl-A to select all the comma delimited text (which is printed in rows), and Convert to Table (using "," as the delimiter).  It's how I do it now.  Was just looking for an automated way.   Interesting how Frame can make what would appear to be a simple task so difficult!  I think it relates back to something I saw posted a few weeks back.  There doesn't appear to be an ExtendScript interface that can execute the keyboard commands; e.g., Ctrl-a to select all text & Esc t v to it convert to table.  Am I missing something?

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