发布时间:2026-07-25阅读(1)
Ecxel是cbrother语言很早的一个模块,当时有开发者提了需求,本来是想封装xlnt库,奈何这个库使用起来总是有崩溃问题,于是就自己简单实现了一个,只实现了读取和修改单元格内容,想等xlnt库稳定一些再换过去。一晃两年过去了,最近又有开发者提出了修改样式的需求,就又看了一下xlnt库这两年的代码修改,发现修改量少的惊人,还是有崩溃问题,无奈又自己实现了样式部分,感觉再经过几次迭代升级,CBrother内置的excel库就要超越xlnt库了,到时候可以考虑把内置的excel库起个名字开源出去。
CBrother升级至v2.4.2
代码太长了,手机不好看下载新版本看 sample/excelrobot.cb
import lib/excelfunction main(parm){ var excel = new Excel(); var path = GetRoot() "excelrobot.xlsx"; var excelsheet = excel.addWorksheet("robot"); excelsheet.setColWidth("D",15); excelsheet.setColWidth("F",3); excelsheet.setColWidth("H",15); excelsheet.setRowHeight(5,81); excelsheet.setRowHeight(6,29); //head var cell = excelsheet.addCell("E6"); cell.set("."); cell.setFontBold(true); cell.setFontSize(36); cell.setAlignmentHorizontal(ALIGNMENT_HORIZONTAL_RIGHT); cell.setAlignmentVertical(ALIGNMENT_VERTICAL_TOP); cell.setBackgroundColor("00B050"); cell.setTopBorderColor("000000"); cell.setTopBorderStyle(BORDER_STYLE_THIN); cell.setLeftBorderStyle(BORDER_STYLE_THIN); cell = excelsheet.addCell("F6"); cell.set("_"); cell.setFontBold(true); cell.setFontSize(72); cell.setAlignmentHorizontal(ALIGNMENT_HORIZONTAL_CENTER); cell.setAlignmentVertical(ALIGNMENT_VERTICAL_BOTTOM); cell.setBackgroundColor("00B050"); cell.setTopBorderColor("000000"); cell.setTopBorderStyle(BORDER_STYLE_THIN); cell = excelsheet.addCell("G6"); cell.set("."); cell.setFontBold(true); cell.setFontSize(36); cell.setAlignmentVertical(ALIGNMENT_VERTICAL_TOP); cell.setBackgroundColor("00B050"); cell.setTopBorderColor("000000"); cell.setTopBorderStyle(BORDER_STYLE_THIN); cell.setRightBorderStyle(BORDER_STYLE_THIN); //arm var cell = excelsheet.addCell("B7"); cell.setBackgroundColor("92D050"); cell.setTopBorderColor("000000"); cell.setTopBorderStyle(BORDER_STYLE_THIN); cell.setLeftBorderStyle(BORDER_STYLE_THIN); cell = excelsheet.addCell("C7"); cell.setBackgroundColor("92D050"); cell.setTopBorderColor("000000"); cell.setTopBorderStyle(BORDER_STYLE_THIN); cell.setBottomBorderStyle(BORDER_STYLE_THIN); excelsheet.mergeCells("B8:B16"); cell = excelsheet.addCell("B8"); cell.setBackgroundColor("92D050"); cell.setLeftBorderColor("000000"); cell.setLeftBorderStyle(BORDER_STYLE_THIN); cell.setRightBorderStyle(BORDER_STYLE_THIN); cell = excelsheet.addCell("I7"); cell.setBackgroundColor("92D050"); cell.setTopBorderColor("000000"); cell.setTopBorderStyle(BORDER_STYLE_THIN); cell.setBottomBorderStyle(BORDER_STYLE_THIN); cell = excelsheet.addCell("J7"); cell.setBackgroundColor("92D050"); cell.setTopBorderColor("000000"); cell.setTopBorderStyle(BORDER_STYLE_THIN); cell.setRightBorderStyle(BORDER_STYLE_THIN); excelsheet.mergeCells("J8:J16"); cell = excelsheet.addCell("J8"); cell.setBackgroundColor("92D050"); for (var i = 8; i <= 16 ; i ) { cell = excelsheet.addCell("B" i); cell.setLeftBorderColor("000000"); cell.setLeftBorderStyle(BORDER_STYLE_THIN); cell.setRightBorderStyle(BORDER_STYLE_THIN); cell.setBottomBorderStyle(BORDER_STYLE_THIN); cell = excelsheet.addCell("J" i); cell.setLeftBorderColor("000000"); cell.setLeftBorderStyle(BORDER_STYLE_THIN); cell.setRightBorderStyle(BORDER_STYLE_THIN); cell.setBottomBorderStyle(BORDER_STYLE_THIN); } //body excelsheet.mergeCells("D7:H21"); cell = excelsheet.addCell("D7"); cell.set("CBrother"); cell.setFontSize(72); cell.setFontName("宋体"); cell.setFontColor("31869B"); cell.setBackgroundColor("00B0F0"); cell.setAlignmentHorizontal(ALIGNMENT_HORIZONTAL_CENTER); cell.setAlignmentVertical(ALIGNMENT_VERTICAL_CENTER); var arr = ["D","E","F","G","H"]; for (var i = 7; i <= 21 ; i ) { for (var j = 0; j < arr.size() ; j ) { cell = excelsheet.addCell(arr[j] i); cell.setLeftBorderColor("000000"); cell.setLeftBorderStyle(BORDER_STYLE_DOUBLE); cell.setRightBorderStyle(BORDER_STYLE_DOUBLE); cell.setTopBorderStyle(BORDER_STYLE_DOUBLE); cell.setBottomBorderStyle(BORDER_STYLE_DOUBLE); } } //leg excelsheet.mergeCells("E22:E31"); cell = excelsheet.addCell("E22"); cell.setBackgroundColor("FFFF00"); cell.setDiagonalBorderStyle(BORDER_STYLE_MEDIUM_DASHDOT); cell.setDiagonalBorderShow(true,false); excelsheet.mergeCells("G22:G31"); cell = excelsheet.addCell("G22"); cell.setBackgroundColor("FFFF00"); cell.setDiagonalBorderStyle(BORDER_STYLE_MEDIUM_DASHDOT); cell.setDiagonalBorderShow(false,true); for (var i = 22; i <= 31 ; i ) { cell = excelsheet.addCell("E" i); cell.setLeftBorderColor("000000"); cell.setLeftBorderStyle(BORDER_STYLE_MEDIUM_DASHDOT); cell.setRightBorderStyle(BORDER_STYLE_MEDIUM_DASHDOT); cell.setTopBorderStyle(BORDER_STYLE_MEDIUM_DASHDOT); cell.setBottomBorderStyle(BORDER_STYLE_MEDIUM_DASHDOT); cell = excelsheet.addCell("G" i); cell.setLeftBorderColor("000000"); cell.setLeftBorderStyle(BORDER_STYLE_MEDIUM_DASHDOT); cell.setRightBorderStyle(BORDER_STYLE_MEDIUM_DASHDOT); cell.setTopBorderStyle(BORDER_STYLE_MEDIUM_DASHDOT); cell.setBottomBorderStyle(BORDER_STYLE_MEDIUM_DASHDOT); } excel.save(path);}
Copyright © 2024 有趣生活 All Rights Reserve吉ICP备19000289号-5 TXT地图HTML地图XML地图