首先声明一个容器
<div id="ss" class="sample-spreadsheets" style="margin:1px 1px 1px 1px;">
</div>
然后初始化表格
var spreadNS = GC.Spread.Sheets;
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), {
sheetCount: 1,
newTabVisible: false
});
导入数据
spread.fromJSON(stylejs);--参数模板数据。json字符串
是否隐藏行头列头,true/false
sheet.options.rowHeaderVisible = true;
sheet.options.colHeaderVisible = true;
spread.options.allowExtendPasteRange = true;
复制样式
spread.options.allowCopyPasteExcelStyle = true;
自动行高
spread.options.highlightInvalidData = true;
暂时挂起表格
spread.suspendPaint();
重新绘制
spread.resumePaint();
//隐藏标签
spread.options.tabStripVisible = false;
spread.options.newTabVisible = false;
PDF导出
function prot_PDF() {
var pdfp = document.createElement('div');
pdfp.className = 'expro';
var pdfc = document.createTextNode("导出PDF");
pdfp.appendChild(pdfc);
return pdfp;
}
//#region pdf字体注册
function addFontsToFontManager(fontsObj) {
var fonts = {
normal: fontsObj["simkai.ttf"]
};
GC.Spread.Sheets.PDF.PDFFontsManager.fallbackFont = function (font) {
var fontInfoArray = font.split(' ');
var fontName = fontInfoArray[fontInfoArray.length - 1];
if (fontName === '宋体') {
return fonts.normal;
}
}
}
//pdf字体设置
var fontsObj = fonts;
registerCustomFont(fontsObj);
addFontsToFontManager(fontsObj);
记得引用字体样式.css
映射键盘
spread.commandManager().register('myCmd',function ColorAction() {}
spread.commandManager().setShortcutKey('myCmd', GC.Spread.Commands.Key.del, false, false, false, false);