
Converter (TSV File to Table type data)
This item overwrites the value of a Table type data item with a contents of a TSV file stored in a File type data item. It also supports TSV in UTF-16 LE with BOM (so-called Excel compatible CSV files).
Basic Configs
- Step Name
- Note
Configs for this Auto Step
- File_DataId
- A: File type data item that stores target TSV file *
- conf_ReadFileCharset
- B: If charset is specified in Content-Type, give priority to it
- conf_CharacterEncoding
- C: Encoding when reading (UTF-16 if not selected)
- Table_DataId
- D: Table type data item to be overwritten with TSV file content *
Notes
- The input value of a TSV cell must be in the following format according to the data type of the corresponding table sub-item (column)
- String-type: (entered character string)
- Numeric-type: Standard format (period as decimal point, no thousands separator)
- Select-type: Choice ID
- Date-type: yyyy-mm-dd
- TSV in UTF-16 LE with BOM (so-called Excel compatible CSV files)
- A format often used for a file to be imported to Excel
- This is a file format that can avoid garbled characters caused by differences in OS, etc.
- In many cases, it is called a CSV file and the extension is
.csv, but in reality it is tab-delimited - Specify UTF-16 in [C: Encoding when reading] when handling a file in this format
- A format often used for a file to be imported to Excel
Capture

See also
Script (click to open)
- 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 auto step
function main() {
//// == 自動工程コンフィグの参照 / Config Retrieving ==
const myFilesDef = configs.getObject("File_DataId"); // (returns ProcessDataDefinitionView)
const tableDataDef = configs.getObject("Table_DataId"); // (returns ProcessDataDefinitionView)
const readFileCharset = configs.getObject("conf_ReadFileCharset");
const characterEncoding = configs.get("conf_CharacterEncoding");
const myFiles = engine.findData(myFilesDef);
// ファイル型データに複数添付されている場合、エラー
if (myFiles !== null && myFiles.size() > 1) {
throw new Error("Attachment of multiple files can not be supported.");
}
// ファイル型データ項目にファイルが1つ添付されている場合
//// == Determine Charset / charset を決める ==
const charset = determineCharset(myFiles.get(0), readFileCharset, characterEncoding);
// テーブル型データ項目のために ListArray を作成する
const myTable = tableDataDef.createListArray();
// ファイル型データにファイルが1つ添付されている場合
if (myFiles !== null) {
// ファイル型を1行ずつ読み込んで、テーブル型にセット
fileRepository.readFile(myFiles.get(0), charset, function (line) {
// タブで列分割
const cellsArray = line.split("\t");
// ListArray に行を追加する
const newRow = myTable.addRow();
// テーブル型データ項目の値の行数
const numOfRows = myTable.size();
if (cellsArray.length !== newRow.size()) {
throw new Error(`Incorrect number of columns in row ${numOfRows}`);
}
// テーブル型データ項目の列数分繰り返す
for (let j = 0; j < newRow.size(); j++) {
newRow.setCol(j, cellsArray[j]);
}
});
}
//// == ワークフローデータへの代入 / Data Updating ==
// ファイル型データ項目にファイルが1つ添付されている場合はその値、1つも添付されていない場合は空をセット
engine.setData(tableDataDef, myTable);
}
/**
* 文字コードを決定する
* @param {QfileView} myFile ファイル型データ項目
* @param {boolean} readFileCharset Content-Type の charset で読み込むか
* @param {String} characterEncoding 読み込む際の文字コード
* @return {String} charset 文字コード
*/
function determineCharset(myFile, readFileCharset, characterEncoding) {
const charset = myFile.getCharset();
if (readFileCharset === true && charset !== null) {
return charset;
}
if (characterEncoding === null || characterEncoding === "") {
return 'UTF-16';
}
return characterEncoding;
}