html table -> excel은 xlsx.js 를 사용안하고 tableExport를 사용했다. 이유는 확장자를 다양하게 지원해줘서.
xlsx에 비하면 상세한 설정은 안되는듯
$('#tree').tableExport({
bootstrap: true,
headings: true,
footers: true,
formats: ["xlsx", "xls", "csv", "txt"],
fileName: "MyExcel",
position: "top",
ignoreRows: null,
ignoreCols: null,
trimWhitespace: true
});
excel -> json은 xlsx.js 사용
var input = event.target;
var reader = new FileReader();
reader.onload = function(){
var fileData = reader.result;
var wb = XLSX.read(fileData, {type : 'binary'});
wb.SheetNames.forEach(function(sheetName){
var rowObj =XLSX.utils.sheet_to_json(wb.Sheets[sheetName]);
console.log(JSON.stringify(rowObj));
addTree(rowObj);
})
};
reader.readAsBinaryString(input.files[0]);
excel에서 읽어온 값을 fancytree나 jqgrid table에 집어넣기
fancytree에 집어넣기
var addTree = function (rowObj) {
var contents = getDict('#tree');
var treeData = contents.children[0]
rowObj=arrayToFancy(rowObj,'root/설치 대상 호스트');
treeData.children=treeData.children.concat(rowObj);
console.log('contents.child',treeData.children,contents);
var option = {
activate: ACTIVATE_ZENIUS3,
source: [treeData], // 필수(트리 데이터)
columns: columns, // 필수(컬럼 정의)
dnd: hostDND,
menu: false, // 컨텍스트 메뉴: 사용하지 않으려면 false 설정
isEdit: isEdit, // 편집 가능 여부, readonly 권한인 경우 false 설정
renderColumns: renderFunction(RENDER_COLUMNS_MULTIHOST, treeid), // 필수(각 트리별 렌더링 함수)
icon: ICON14, // 선택(아이콘 설정)
minExpandLevel: 1,
};
makeZeniusTree(treeid, option);
}
/**
array data를 fancytree에서 쓸수 있는 구조로 변경해야함
경로를 나타내주는 unique값만 넣고
key값은 그냥 null값으로 넣음
arr : 들어가는 arraydata
topname : 트리 최상단 title이름 //unique값에 경로 넣어주기 위함
**/
var arrayToFancy = function(arr,topname){
return arr.map( e =>{
var fancydata={
"title":e.title,
"folder":false,"selected":false,"partsel":false,
"data":e,
}
fancydata.data.unique=`/${topname}/${e.title}`;
return fancydata;
})
}