Converter (Table to Excel-CSV FILE sjis)

Converter (Table to Excel-CSV FILE sjis)

Stores the values in a Table type data item into a File type data item as an Excel compatible CSV.

2020-02-27 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/converter-tabletoexcelcsvsjis/

Configs
  • A: Select TABLE DATA *
  • B: Set COL IDs for Extraction (e.g. “0,1,5,3,6”) *
  • C: Select STRING DATA for File Name *
  • D: Select FILE DATA (append) *
Script
// Converter from Table to Excel-CSV (ver. 20180829)
// (c) 2018, Questetra, Inc. (the MIT License)

//// == Config Retrieving / 工程コンフィグの参照 ==
const dataIdA = configs.get( "conf_DataIdA" ) + "";
const colIds  = configs.get( "conf_ColIds" )  + "";
const dataIdC = configs.get( "conf_DataIdC" ) + "";
const dataIdD = configs.get( "conf_DataIdD" ) + "";

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

if( myTable === null){
  throw new Error( "Source Table data is NULL" );
}

//// == Calculating / 演算 ==
let colIdArray = colIds.split(",");
let numOfCols = colIdArray.length;
let numOfRows = myTable.size() - 0; // 行(Tableの高さ)

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

// for sjis-csv
let myCsv = myTsv.replace( /,/g, "" ).replace( /\t/g, "," );


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

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

Download

Capture

Notes

  • It is also possible to change the order of columns, filter columns, list columns duplicately etc.
  • The file entity consists of comma-separated-values (Shift-JIS)
  • Compare to tab-separated-values (utf-16le-bom) version, the availability of smartphone display and data import increases, but comma information in data misses.
Scroll to Top

Discover more from Questetra Support

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

Continue reading