How to apply paragraph style ti lines read from a csv file.
Hi, what am I doing wrong?
I am trying to apply a paragraph style based on data read from a csv file.
If the 11th field in the csv data line says "bold" I would like to apply a "bold" paragraph style to that line.
My code:
var csv_file = File('Test.csv');
csv_file.open('r');
var contents = csv_file.read();
csv_file.close();
var lines = contents.split("\n");
var NoOfLines = lines.length;
var data = [];
var myDoc = app.activeDocument;
var myTextFrame = MyDoc.TextFrames[0];
var BOLD = MyDoc.paragraphStyles.item("bold");
for (var i = 0; i < NoOfLines; i++) {
var line = lines[i];
var record = line.split(",");
data.push(record);
}
for (var i = 1; i < NoOfLines; i++){
var line = lines[i];
myTextFrame.contents += line + "\r";
if (data[i][11] == "bold") {
MyDoc.textFrames[0].paragraphs[i].appliedParagraphStyle = BOLD;
}
}
BOLD style gets applied to all the text in the frame. Any suggestions?
Thanks!
