Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
How to get single value from .xml

I have some xml or excel I want to loop through this document in InDesign script and insert values on defined places this is excel or xml enter image description here enter image description here

this I want to get enter image description here

I don't have so much scripting experiences so I can only this piece of code

var doc = app.activeDocument;
var myFile = File("~/Desktop/test.xml");
var textExcel = doc.textFrames.add();
textExcel.geometricBounds = [50, 80, 10, 150];
textExcel.place(myFile);

but now how I can get a single value? for example in indesign template first paragraph should look like table --> lorem--> 150

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can probably do this with xpath and Document. https://developer.mozilla.org/en-US/docs/Web/API/Document/evaluate

You create a new Document with the xml and you evaluate a xPath.

about 4 years ago · Juan Pablo Isaza Relatório

0

Here is the possible solution:

var doc = app.activeDocument;

// get a text from the XLSX file
var inputFile = File("d:/table.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
var rows = text.split('\r');
var table = [];
for (var i = 1; i < rows.length; i++) table.push(rows[i].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 the card to some places
    card.move([10,10]);
    card.move(undefined, [i*75, 0]);
}

// 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;

    // apply styles to the texts in the card
    apply_style('title', title_frame);
    apply_style('description', description_frame);
    apply_style('price', price_frame);

    var group = doc.groups.add([title_frame, description_frame, price_frame]);
    return group;
}

function apply_style(style_name, frame) {
    var doc = app.activeDocument;
    try {
        var style = doc.paragraphStyles.itemByName(style_name);
        frame.paragraphs.everyItem().appliedParagraphStyle = style;
    } catch(e) {}
}

This is the XLSX table:

enter image description here

Here is the result layout (3 cards):

enter image description here

It creates cards from XLSX file (applies the styles to the texts inside cards, why not?) and put them on the page of the current document.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda