I'm working on a function that generates a Google Docx where it is listed, line by line, every character's name and its lyrics.
Every line is made up of two strings: character's name and lyrics.
Well, I get my goal using insertTable and formatting it, getting every line as a two column table.
var table = body.insertTable(0, [[pers, text]]);
var styles = {};
styles[DocumentApp.Attribute.BORDER_COLOR] = '#ffffff';
styles[DocumentApp.Attribute.FONT_FAMILY] = 'Calibri';
styles[DocumentApp.Attribute.FONT_SIZE] = 11;
table.setAttributes(styles);
The issue arises because now I need to manipulate this file and I'm struggling to work with so many tables!
The question is: is there a way to get the same result without using tables? I tried body.appendParagraph() but I can't figure out how to format the paragraph the same as in the above image.
Can you please help me? ..and.. I do apologize for my bad english!!
Yes. You can format a paragraph and get the same look:
You have to insert a tab symbol after a personage name and set so called 'hanging indentation' for the paragraph.
The code could be something like this:
function setIndents() {
var doc = DocumentApp.getActiveDocument();
var indent = 100;
doc.getBody().getParagraphs().forEach(p => p.setIndentStart(indent));
}
It sets the 'hanging indentation' (100 pt) for all existed paragraphs in current document.