1
Google 시트를 구문 분석하고 문서에서 셀을 멋지게 형식화하는 스크립트를 작성하고 있습니다. 열 1의 셀 데이터를 항상 굵게 표시하고 열 6의 셀 데이터를 항상 기울임 체로 표시하고 싶습니다. 문제는 단락을 문서 본문에 추가 한 후에 특성 변경이 전체 문서에 적용된다는 것입니다. 문서 본문에 셀 데이터를 추가하기 전에 셀 데이터를 굵게/기울임 꼴로 표시하는 방법이 있습니까?Google 문서 도구 스크립트에서 한 줄을 어떻게 굵게 표시합니까?
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var numCols = rows.getNumColumns();
var values = rows.getValues();
var doc = DocumentApp.create("Smogon Formatted");
var docBody = doc.getBody();
for (var i = 2; i <= numRows; i++) {
for (var j = 1; j <= numCols; j++){
var cellData = rows.getCell(i, j).getValue()
// Format data based on column
if (j == 1) {
docBody.appendParagraph(cellData).editAsText().setBold(true);
} else if (j == 2 || j == 3) {
var imgFormula = rows.getCell(i, j).getFormula();
var imgUrl = getImageUrl(imgFormula);
docBody.appendParagraph("[img]" + imgUrl + "[/img]");
} else if (j == 6) {
docBody.appendParagraph(cellData).editAsText().setItalic(true);
} else {
docBody.appendParagraph(cellData);
}
}
}
};
편집 : 당신이 스타일은 매우 쉽게 모든 단락에 스타일을 할당 할 수 속성을 사용하는 경우 setAttributes 방법
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var numCols = rows.getNumColumns();
var values = rows.getValues();
var doc = DocumentApp.create("Smogon Formatted");
var docBody = doc.getBody();
for (var i = 2; i <= numRows; i++) {
for (var j = 1; j <= numCols; j++){
var cellData = rows.getCell(i, j).getValue()
// Format data based on column
if (j == 1) {
docBody.appendParagraph(cellData).setAttributes(style1);
} else if (j == 2 || j == 3) {
var imgFormula = rows.getCell(i, j).getFormula();
var imgUrl = getImageUrl(imgFormula);
docBody.appendParagraph("[img]" + imgUrl + "[/img]");
} else if (j == 6) {
docBody.appendParagraph(cellData).setAttributes(style2);
} else {
docBody.appendParagraph(cellData);
}
}
}
};
// Style definitions as global variables
var style1= {};
style1[DocumentApp.Attribute.BOLD] = true;
var style2= {};
style2[DocumentApp.Attribute.ITALIC] = true;
합니다. 아마도 제 스크립트가 그대로 작동 할 수 있다고 제안 할 수 있습니까? – Shwheelz