spreadjs运用

初始化表单API

const spreadNS = GC.Spread.Sheets;
const SHEETS = new spreadNS.Workbook(this.refs['overseas']);
// set sheet count
// SHEETS.setSheetCount(1);

const sheet = SHEETS.sheets[0];

设置默许属性

const defaultStyle = new GC.Spread.Sheets.Style();
// 设置默许背景色
// @method1 defaultStyle.backColor = "LemonChiffon";
// @method2 SHEETS.options.backColor = "#ccc"; 
//defaultStyle.foreColor = "Red";
//defaultStyle.formatter = "0.00";
defaultStyle.font   = "bold normal 9px normal"
defaultStyle.hAlign = GC.Spread.Sheets.HorizontalAlign.center;
defaultStyle.vAlign = GC.Spread.Sheets.VerticalAlign.center;
//defaultStyle.borderLeft = new GC.Spread.Sheets.LineBorder("Green",GC.Spread.Sheets.LineStyle.medium);
//defaultStyle.borderTop = new GC.Spread.Sheets.LineBorder("Green",GC.Spread.Sheets.LineStyle.medium);
//defaultStyle.borderRight = new GC.Spread.Sheets.LineBorder("Green",GC.Spread.Sheets.LineStyle.medium);
//defaultStyle.borderBottom = new GC.Spread.Sheets.LineBorder("Green",GC.Spread.Sheets.LineStyle.medium);
sheet.setDefaultStyle(defaultStyle, spreadNS.SheetArea.viewport);

表格的四个部份

spreadNS.SheetArea.viewport

// spreadNS.SheetArea include the following parts
// colHeader: 1 ,
//    corner: 0
// rowHeader: 2
//  viewport: 3

// 转变表头的背景 Set the backcolor of second row header.
sheet.getCell(1, 0, GC.Spread.Sheets.SheetArea.rowHeader).backColor("Yellow");

其他设置

// 表格下边的tab的色彩 
sheet.options.sheetTabColor = "red";

// 表格只读 
sheet.options.isProtected = true

// 许可cell内容移除
activeSheet.options.allowCellOverflow = true;

// 第一列不可见
sheet.setColumnVisible(0, false)

// 增加tips 
sheet.comments.add(4, 4, "不要修正!");

// 制止用户编辑公式 
spread.options.allowUserEditFormula = false;

// 不显现格子的边 
sheet.options.gridline = {
    color:"red", 
    showVerticalGridline: true,
    showHorizontalGridline: false
};

// 不显现表头 
activeSheet.options.colHeaderVisible = false;
activeSheet.options.rowHeaderVisible = false;

削减重绘

spread.reset() // 清空数据 
spread.suspendPaint();  //suspendPaint 停息重绘  先如许 许多操纵以后 resumePaint
spread.addSheet(0);
spread.fromJSON(json);  // json data
spread.resumePaint();   // 挪用resumePaint 从新激活Spread重绘 

excel 运算符

援用运算符 寄义(示例)
:(冒号) 地区运算符,发生对包含在两个援用之间的一切单元格的援用 (B5:B15)
,(逗号) 团结运算符,将多个援用合并为一个援用 (SUM(B5:B15,D5:D15))
(空格) 交织运算符发生对两个援用共有的单元格的援用。(B7:D7 C6:C8)

设置单元格属性

      
sheet.getCell(2, 1).
text("huahua").             // 设置笔墨 
backColor("rgba(1,1,1,.3)") //设置背景色 

公式

// 随机数 
 sheet.setFormula(1, 1, "RandBetween(45,85)");

// 乞降 
sheet.setFormula(1, 1, "SUM(A1,B1)"); //A1和B1之和
sheet.setFormula(1, 1, "SUM(A1:H1)"); //A1到H1之和 

// 前提 
sheet.setFormula(4, 1, "IF(A1>10, A1*2, A1*3)");

开启R1C1 援用

// open r1c1 reference
SHEETS.options.referenceStyle = 1;

基础操纵

// 增加行/列 
sheet.addRows(1, 1);    sheet.addColumns(1, 1);

// 设置背景图片
activeSheet.getCell(1, 1).backgroundImage("Image file path name");

设置row和column的背景色

/**
* @name set the bgColor of column
*
* @type1
* sheet.getRange(-1, 1, -1, 1).backColor("lightYellow").width(330);
*
* @name set the bgColor of row
*
* @type1
* sheet.getRange(0, -1, 1, -1).backColor("lightYellow").height(44)
*
* @type2
* const rowStyle1 = new spreadNS.Style();
* rowStyle1.backColor = "#bdcde3";
* sheet.setStyle(0, -1, rowStyle1, spreadNS.SheetArea.viewport);
*/

events

// 猎取点击的cell和地点的sheet 
SHEETS.bind(spreadNS.Events.EnterCell, function (event, data) {
    console.log(data.col)
    console.log(data.row)
    console.log(data)
    var activeSheet = data.sheet;
    activeSheet.startEdit(true);
});

// 脱离cell事宜 
sheet.bind(GC.Spread.Sheets.Events.LeaveCell, function (event, infos) {
    //Reset the backcolor of cell before moving
    infos.sheet.getCell(infos.row, infos.col).backColor(undefined);
});
    原文作者:huahuadavids
    原文地址: https://segmentfault.com/a/1190000019335390
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞