Converter (Table type data to Excel-CSV File)

Converter (Table type data to Excel-CSV File)
Stores the values in a Table type data item into a File type data item as an Excel compatible CSV. It does not affect existing files. Just add.
2019-10-21 (C) Questetra, Inc. (MIT License)
Configs
  • A: Target Table type data item *
  • B: Saving file name * #{EL}
  • C: File type data item to save CSV *
Script
// Converter from Table to Excel-CSV (ver. 20180829)
// (c) 2018, Questetra, Inc. (the MIT License)

main();
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
var   myFiles  = engine.findDataByNumber( fileId );// java.util.ArrayList
if( myFiles === null ){ myFiles = new java.util.ArrayList(); }

var myTsv = "";

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

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

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


}



  //table to CSV
function tabletocsv(myTable) {

//// == Calculating / 演算 ==
let numOfRows = myTable.size() - 0; // 行(Tableの高さ)
let 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;

}

Download

Capture

Notes

  1. The file entity consists of tab-separated-values (utf-16le-bom)

1 thought on “Converter (Table type data to Excel-CSV File)”

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

Comments are closed.

%d bloggers like this: