Converter (Table type data to Excel-CSV File)

Converter (Table type data to Excel-CSV File)

コンバータ (テーブル型データ to Excel-CSV ファイル)

This item stores the values in a Table type data item into a File type data item as an Excel compatible CSV. The file is added and does not affect existing files.

Auto Step icon
Basic Configs
Step Name
Note
Configs for this Auto Step
Table_DataId
A: Target Table type data item *
File_Name
B: Saving file name *#{EL}
File_DataId
C: File type data item to save CSV *

Capture

Notes

  • The file entity consists of tab-separated-values (utf-16le-bom)
  • The input values of the table cells are converted to strings in the following format according to the data type of the 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

See also

Script (click to open)
  • An XML file that contains the code below is available to download
    • converter-table-to-excelcsv.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 tableId = configs.get("Table_DataId");
    const filename = configs.get("File_Name");
    const fileId = configs.get("File_DataId");

    if (filename === "" || filename === null) {
        throw new Error("File Name is blank");
    }

    //// == Data Retrieving / ワークフローデータの参照 ==
    const myTable = engine.findDataByNumber(tableId);
    // com.questetra.bpms.core.model.formdata.ListArray
    let myFiles = engine.findDataByNumber(fileId); // java.util.ArrayList
    if (myFiles === null) {
        myFiles = new java.util.ArrayList();
    }

    let myTsv = "";

    if (myTable !== null) {
        myTsv = tableToTsv(myTable);
    }

    myFiles.add(
        new com.questetra.bpms.core.event.scripttask.NewQfile(
            filename,
            "text/tab-separated-values; charset=UTF-16",
            "x-UTF-16LE-BOM",
            myTsv
        )
    );

    //// == Data Updating / ワークフローデータへの代入 ==
    engine.setDataByNumber(fileId, myFiles);
}

/**
 * テーブル型データ を tsv に変換する
 * @param {com.questetra.bpms.core.model.formdata.ListArray} myTable テーブル型データ
 * @return {String} mytsv 変換後の tsv 形式の文字列
 */
function tableToTsv(myTable) {
    //// == Calculating / 演算 ==
    const numOfRows = myTable.size() - 0; // 行(Tableの高さ)
    const numOfCols = myTable.getRow(0).size(); // 列(Tableの幅)
    let mytsv = "";

    for (let i = 0; i < numOfRows; i++) {
        for (let j = 0; j < numOfCols; j++) {
            mytsv += myTable.get(i, j);
            if (j != numOfCols - 1) {
                mytsv += "\t";
            }
        }
        if (i != numOfRows - 1) {
            mytsv += "\n";
        }
    }

    return mytsv;
}

3 thoughts on “Converter (Table type data to Excel-CSV File)”

  1. Pingback: Converter (Table to Excel-CSV FILE sjis) – Questetra Support

  2. Pingback: Email a Excel-CSV (Table) SJIS – Questetra Support

  3. Pingback: Order Report Process – Questetra Support

Comments are closed.

Scroll to Top

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading