本帖最后由 no_map 于 2019-7-1 09:58 编辑
获取数据- getData() {
- getData().then(res => {
- let data = res.data.data;
- let sheet = this._spread.getActiveSheet();
- sheet.suspendPaint();
- this.loadData(data);
- this.setCellStyle();
- sheet.resumePaint();
- })
- }
复制代码 绑定数据
- loadData(data) {
- let sheet = this._spread.getActiveSheet();
- sheet.setDataSource(sd);
- sheet.frozenColumnCount(1);
- sheet.autoGenerateColumns = true;
- let colInfos = [
- ...,
- ...
- ]
- sheet.bindColumns(colInfos)
- }
复制代码 设置样式
- setCellStyle(data){
- console.log("开始设置样式");
- let xhOptions = new GC.Spread.Sheets.CellTypes.ComboBox();
- xhOptions
- .items([
- { text: "个", value: "个" },
- { text: "套", value: "套" },
- { text: "部", value: "部" },
- { text: "件", value: "件" }
- ])
- .editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.text);
- let sheet = this._spread.getActiveSheet();
- sheet.suspendCalcService(false);
- for (let i = 0; i < data.length; i++) {
- // 设置缩进
- let level = (data[i].dypx + "").split(".").length - 1;
- // 设置公式
- sheet.setFormula(i, 5, data[i].equation);
- sheet.getCell(i, 0).textIndent(level);
- // 设置项目名称可修改 以及 不可修改
- if (data[i].sfkxg == 1) {
- sheet.getCell(i, 0).locked(false);
- sheet.getCell(i, 0).backColor("rgb(241, 238, 250)");
- }
- // 设置其他
- let jdid = data[i].jdid;
- let childArr = this.getChildren(data, jdid);
- if (childArr.length == 0) {
- // 设置子级可编辑行
- if (data[i].sfkxg == 1) {
- // 设置型号选择框
- // 设置可编辑子级别单元格解锁与样式
- sheet.getRange(i, 1, 1, 14).locked(false);
- sheet.getRange(i, 1, 1, 14).backColor("rgb(241, 238, 250)");
- // 设置金额锁定
- sheet.getCell(i, 5).locked(true);
- sheet.getRange(i, 5,).backColor(null);
-
- sheet.getCell(i, 2).cellType(xhOptions);
- }
- }
- // 设置修改项 的 背景颜色
- let itemData = sheet.getDataItem(i);
- // 红色
- if (itemData.jdmcbs == 1) {
- sheet.getCell(i, 0).backColor("rgb(232, 109, 133)");
- }
- if (itemData.xhbs == 1) {
- sheet.getCell(i, 1).backColor("rgb(232, 109, 133)");
- }
- if (itemData.jldwbs == 1) {
- sheet.getCell(i, 2).backColor("rgb(232, 109, 133)");
- }
- if (itemData.djbs == 1) {
- sheet.getCell(i, 3).backColor("rgb(232, 109, 133)");
- }
- if (itemData.slbs == 1) {
- sheet.getCell(i, 4).backColor("rgb(232, 109, 133)");
- }
- if (itemData.cxdwbs == 1) {
- sheet.getCell(i, 9).backColor("rgb(232, 109, 133)");
- }
- // 蓝色
- if (itemData.jdmcbs == 2) {
- sheet.getCell(i, 0).backColor("rgb(150, 160, 213)");
- }
- if (itemData.xhbs == 2) {
- sheet.getCell(i, 1).backColor("rgb(150, 160, 213)");
- }
- if (itemData.jldwbs == 2) {
- sheet.getCell(i, 2).backColor("rgb(150, 160, 213)");
- }
- if (itemData.djbs == 2) {
- sheet.getCell(i, 3).backColor("rgb(150, 160, 213)");
- }
- if (itemData.slbs == 2) {
- sheet.getCell(i, 4).backColor("rgb(150, 160, 213)");
- }
- if (itemData.cxdwbs == 2) {
- sheet.getCell(i, 9).backColor("rgb(150, 160, 213)");
- }
- }
- sheet.clearPendingChanges();
- sheet.resumeCalcService(true);
- sheet
- .getRange(0, 0, data.length, 15)
- .setBorder(
- new GC.Spread.Sheets.LineBorder(
- "rgb(67, 67, 67)",
- GC.Spread.Sheets.LineStyle.thin
- ),
- { all: true }
- );
- sheet.getRange(0, 0, data.length, 15).font("8pt Arial");
- sheet.getRange(0, 0, data.length, 15).vAlign = GC.Spread.Sheets.VerticalAlign.center;
- console.log("结束设置样式");
- }
复制代码
|
|