平台介绍 >> js/jsfun/clsExcel Excel操作
js/jsfun/clsExcel Excel操作
============》》》 JS代码 《《《 ============
//新建Excel文件
let exl = new clsExcel();
//设置单元格值
exl.exlSetCellValue("A1", "AAAA")
//新建工作簿
let index = exl.exlNewSheet("新版本")
//设置活动工作簿
exl.exlSetActiveSheetIndex(index)
exl.exlSetCellValue("A1", "AAAA")
exl.exlSetCellValue("B1", "AAAABB")
exl.exlSetCellValue("A2", "BBBB")
//取得活动工作簿的索引
let index2 = exl.exlGetActiveSheetIndex()
fnResponse_write("当前工作簿索引:" + index2)
//取得工作簿列表
let sheets = exl.exlGetSheetList()
console.log(sheets)
fnResponse_write(sheets)
//取得工作簿名称
let sheetName = exl.exlGetSheetName(index2)
//合并单元格
exl.exlMergeCell(sheetName, "A1", "B2")
//变更工作簿名称
exl.exlSetSheetName("新版本", "新版本B")
//设置活动工作簿单元格样式
let aa = {"color": "00FFFF", "size": 26, "bold": true, "italic": true, "horizontal": "right","vertical": "top", "bgColor": "112233"};
exl.exlSetCellStyle("A1", "A2", aa);
//设置工作簿单元格样式
let bb = {"color": "FF0000", "size": 36, "bold": false, "italic": true, "horizontal": "left", "vertical": "bottom", "bgColor": "C0C0C0"};
exl.exlSetSheetCellStyle("Sheet1", "A1", "A2", bb);
//批量设置工作簿数据
let data2 = [{"title": "AAAAA", "price": 123.12}, {"title": "BBBBBB", "price": 1299}]
let columns = [{"cn": "title", "title": "商品名称"}, {"cn": "price", "title": "价格"}]
exl.exlSetData(data2, columns)
//保存EXCEL到本地EXCEL文件
let file = fnJsa_rootPath() + "/aa.xlsx";
exl.exlSaveAs("aa.xlsx")
if (fnIO_exist(file)) {
fnResponse_write("输出EXCEL:aa.xlsx成功")
}
//实例化EXCEL,打开EXCEL 文件
let exl2=new clsExcel(file);
// //取得EXCEL活动工作簿数据
let data3=exl2.exlGetData();
console.log("readData:",data3)