- An XML file that contains the code below is available to download
- converter-excelcsv-to-table.xml (C) Questetra, Inc. (MIT License)
- If you are using Professional, you can modify the contents of this file and use it as your own add-on
main();
function main() {
//// == 自動工程コンフィグの参照 / Config Retrieving ==
const myFilesDef = configs.getObject("File_DataId"); // (returns ProcessDataDefinitionView)
const tableDataDef = configs.getObject("Table_DataId"); // (returns ProcessDataDefinitionView)
const myFiles = engine.findData(myFilesDef);
// ファイル型データに複数添付されている場合、エラー
if (myFiles !== null && myFiles.size() > 1) {
throw new Error("Attachment of multiple files can not be supported.");
}
// テーブル型データ項目のために ListArray を作成する
const myTable = tableDataDef.createListArray();
// ファイル型データにファイルが1つ添付されている場合
if (myFiles !== null) {
// ファイル型を1行ずつ読み込んで、テーブル型にセット
fileRepository.readFile(myFiles.get(0), "x-UTF-16LE-BOM", function (line) {
// タブで列分割
const cellsArray = line.split("\t");
// ListArray に行を追加する
const newRow = myTable.addRow();
// テーブル型データ項目の値の行数
const numOfRows = myTable.size();
if (cellsArray.length !== newRow.size()) {
throw `Incorrect number of rows at line ${numOfRows}`;
}
// テーブル型データ項目の列数分繰り返す
for (let j = 0; j < newRow.size(); j++) {
newRow.setCol(j, cellsArray[j]);
}
});
}
//// == ワークフローデータへの代入 / Data Updating ==
// ファイル型データ項目にファイルが1つ添付されている場合はその値、1つも添付されていない場合は空をセット
engine.setData(tableDataDef, myTable);
}