With following code I am trying to import excel file to indesign. I can get data but if in table is more then 3 rows it just continue in line and doesn't create new line.
var doc = app.activeDocument;
// get a text from the XLSX file
var inputFile = File("~/Desktop/test.xlsx");
var temp_frame = doc.textFrames.add();
temp_frame.place(inputFile);
var text = temp_frame.parentStory.contents;
temp_frame.remove();
// make a table from the text
text = text.split('\r');
var table = [];
for (var row = 1; row < text.length; row++) {
table.push(text[row].split('\t'));
}
// loop through the table and make the cards
for (var i = 0; i < table.length; i++) {
var title = table[i][0];
var description = table[i][1];
var price = table[i][2];
var card = make_card(title, description, price);
// move card to some place
card.move([10,10]);
card.move(undefined, [i*75, 0]);
if(i > 2){
card.move([20,10]);
card.move(undefined, [i*75, 20]);
}
}
// the function to create and return a card
function make_card(title, description, price) {
var doc = app.activeDocument;
var title_frame = doc.textFrames.add();
title_frame.geometricBounds = [20, 80, 30, 150];
title_frame.contents = title;
var description_frame = doc.textFrames.add();
description_frame.geometricBounds = [30, 80, 80, 150];
description_frame.contents = description;
var price_frame = doc.textFrames.add();
price_frame.geometricBounds = [80, 80, 100, 150];
price_frame.contents = price;
var group = doc.groups.add([title_frame, description_frame, price_frame]);
return group;
}
My question is how to write code that card doesn't go out of the document but follow on next line and as well as how to add new page automatically when current document is already full.
I tried do do it with following code in loop if index is heigher than 2 move card down. It move it down but it follow in the same line (out of the document) and I also think there is better way how to write it because if excel has 1000 rors and I have to set up this if index condition for every third element ... code will be one mash
if(i > 2){
card.move([20,10]);
card.move(undefined, [i*75, 20]);
}

