Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

index with data from a table

Return to Member Forum

  • Author
    Posts
    • #82450

      Hi

      I need to make a index with data located in a table.
      example:
      3 colums: Product name, dimension, price
      Several rows.

      My client wants an index with
      product name, price, page number.

      I can get al the data from everything that is not in the table but how can i extract the data from the table???

      thanxs

    • #82516
      David Blatner
      Keymaster

      That’s a tricky one. No immediately obvious way to do it. One method would be to make an index (or perhaps easier, a table of contents) based on the product name. Then extract all the data from the table and put it in to Excel. Then create some kind of VLOOKUP to match the price to the product name… the more I think about it, the more I think it’s possible, but it gives me a headache.

    • #82524
      Loic Aigon
      Member

      Probably a good candidate for a script…

    • #82529
      Masood Ahmad
      Participant

      To keep the ball running in an easiest way…

      Create a copy of your InDesign file, Convert the Tables to text and generate the Index. Finally paste that Index to your original InDesign file.

      …let’s see if someone comes up with a script.

    • #82534
      Loic Aigon
      Member

      Hi Masood,

      Converting table to text is indeed what can come to mind first but how would you ensure page location consistency ? You could have different cells heights that a regular leading wouldn’t reproduce. But maybe I am wrong.

      Here is a script approach (given that we have a 3 columns tables as introduced).

      Array.prototype.contains = function ( object )
      {
      var i = 0, n = this.length;

      for ( i = 0 ; i < n ; i++ )
      {
      if ( this[i] === object )
      {
      return true;
      }
      }

      return false;
      }

      var main = function() {
      var t, rows, n, row, data = [], pg;

      if ( !app.properties.activeDocument
      || app.selection.length!=1
      || !(app.selection[0] instanceof TextFrame )
      || !app.selection[0].parentStory.tables.length
      ) {
      alert(“Please select a text frame with on table inside”);
      return;
      }

      t = app.selection[0].parentStory.tables[0];

      if ( app.selection[0].parentStory.overflows
      || t.cells.everyItem().overflows.contains (“true”) ) {
      alert( “please fix overflow first”);
      return;
      }

      if ( t.columns.length < 3 ) {
      alert( “Table must count 3 columns”);
      return;
      }

      rows = t.rows;

      n = rows.length;

      while ( n– ) {
      row = rows[n];
      pg = row.cells[0].insertionPoints[0].parentTextFrames[0].parentPage;
      if ( row.rowType == RowTypes.BODY_ROW ) {
      data[ data.length ] = [row.cells[0].contents, row.cells[2].contents, (pg? pg.name : “?” )];
      }
      }

      makeCSV ( data );

      alert(“OK” );
      }

      var makeCSV = function(data) {
      var f = File ( Folder.desktop+”/index.txt” );
      var n = data.length, sep = “”;
      f.open(‘w’);
      f.writeln ( “Product”+sep+”Price”+sep+”Page” );

      while ( n– ) {
      f.writeln( data[n].join(sep) );
      }

      f.close();
      }

      main();

    • #82837

      Script did not work. :(

      I have solved it with making a paragraph style of the price. And an other one for the productname.
      Exporting everything to an index. After the product name I placed 3 tabs.
      Convert the index to a table. Remove the column I did not need. Convert table to text.
      Find/delete the tab(s) and hard return and yes! Price is perfectly placed after the productname.
      Remove everything that’s not wanted and ready

Viewing 5 reply threads
  • The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
Forum Ads