本帖最后由 18744279242 于 2017-8-8 11:02 编辑
这个demo是创建了新的spread对象,如果我想在已有的spread对象该怎么做
我这样写只有单元格宽高变了,我想要的角标不显示,而且生成base64码还是错误的。
- var spread;
- var sheetArray=[]; // 添加sheet页的详细信息(存数据库)
- var flag = 1;
- var totalPage = 1; // 总页数
- var pageNum = 1; // 当前页数
- var itemList = []; // 需要传入后台并插入到字表的sheetList
- var zbid; // 主表id
- var GC;
- var pageType = "1";
- (function (GC) {
- (function (Spread) {
- (function (Sheets) {
- (function (designer) {
- (function (index) {
- 'use strict';
- var needSuspend;
- function updateLayout() {
- $(".content").css('height', $(".content").children('.fill-spread-content').height());
- $(".header").css("width", $(window).width() + "px");
- if ($(".ribbon-bar").data("gcui-gcuiribbon")) {
- $(".ribbon-bar").data("gcui-gcuiribbon").updateRibbonSize();
- }
- spread = designer.wrapper.spread;
- if (spread && spread.isPaintSuspended()) {
- spread.resumePaint();
- spread.refresh();
- needSuspend = true;
- }
- }
- var _windowResizeTimer = null;
- function _doWindowResize() {
- if (_windowResizeTimer) {
- window.clearTimeout(_windowResizeTimer);
- }
- _windowResizeTimer = window.setTimeout(function () {
- updateLayout();
- _windowResizeTimer = null;
- if (needSuspend) {
- needSuspend = false;
- window.setTimeout(function() {
- designer.wrapper.spread.suspendPaint();
- }, 300);
- }
- }, 100); //now delay 100ms to resize designer
- }
- ;
- $(document).ready(function () {
- designer.loader.loadContent();
- $(window).resize(_doWindowResize);
- $(window).resize();
-
- var jsonFileName = $("#updateId",window.opener.document).val(); // 文件名
- zbid = jsonFileName; // 主表id就是文件名
- // 读取json文件
- $.getJSON("../modelCertificate/model/certificate/" + jsonFileName + ".ssjson?_t=" + new Date().getTime(), function (data) {
- spread = designer.wrapper.spread;
- spread.fromJSON(data);
- var sheet = spread.getActiveSheet();
- sheet.setColumnWidth(1,300);
- sheet.setRowHeight(1,150);
- sheet.getCell(1, 1).cellType(new HTMLCellType()).value('<sub>5</sup>');
- spread.addCustomFunction(carryF);
- spread.addCustomFunction(effectivenumF);
- getPage(spread.sheets[1]); // 原始记录页 获得当前页和总页数
- });
- $("#verticalSplitter").draggable({
- axis: "y",
- containment: "parent",
- scroll: false,
- zIndex: 100,
- stop: function (event, ui) {
- var $this = $(this), top = $this.offset().top, offset = top - $(".header").height(), $content = $(".content .fill-spread-content");
- // adjust size of related items
- $("#formulaBarText").css({ height: (20 + offset) }); // 20: original height of formulaBarText
- $content.css({ top: top + 10 }); // 10: height of the space for verticalSplitter
- $content.parent().css({ height: $content.height() });
- designer.wrapper.spread.refresh();
- }
- });
- function disableDragDrop(dataTransfer) {
- if (dataTransfer) {
- dataTransfer.effectAllowed = "none";
- dataTransfer.dropEffect = "none";
- }
- }
- window.addEventListener("dragenter", function (e) {
- if (e.target.id != dropzoneId) {
- e.preventDefault();
- disableDragDrop(e.dataTransfer);
- }
- }, false);
- window.addEventListener("dragover", function (e) {
- e = e || event;
- e.preventDefault();
- disableDragDrop(e.dataTransfer);
- }, false);
- window.addEventListener("drop", function (e) {
- e = e || event;
- e.preventDefault();
- disableDragDrop(e.dataTransfer);
- }, false);
- });
- designer.loader.ready(function () {
- //To Fix the designer resize performance issues.
- $(window).unbind("resize.gcuiribbon");
- $("#verticalSplitter").show();
- });
- })(designer.index || (designer.index = {}));
- var index = designer.index;
- })(Sheets.designer || (Sheets.designer = {}));
- var designer = Sheets.designer;
- })(Spread.Sheets || (Spread.Sheets = {}));
- var Sheets = Spread.Sheets;
- })(GC.Spread || (GC.Spread = {}));
- var Spread = GC.Spread;
- })(GC || (GC = {}));
- /*给有下拉列表框的 汉字隐藏框赋值*/
- function addSelectText(selectId, textId) {
- var text = $('#' + selectId + ' option:selected').text();//
- var val = $('#' + selectId + ' option:selected').val();//
- if (val != "") {
- $("#" + textId).val(text);
- } else {
- $("#" + textId).val("");
- }
- }
- function HTMLCellType() {}
- HTMLCellType.prototype = new GC.Spread.Sheets.CellTypes.Text;
- HTMLCellType.prototype.paint = function (ctx, value, x, y, w, h, style, context) {
- var DOMURL = window.URL || window.webkitURL || window;
- var cell = context.sheet.getCell(context.row, context.col);
- var img = cell.tag();
- if (img) {
- try{
- ctx.save();
- ctx.rect(x, y, w, h);
- ctx.clip();
- ctx.drawImage(img, x + 2, y + 2)
- ctx.restore();
- cell.tag(null);
- return;
- }
- catch(err){
- GC.Spread.Sheets.CustomCellType.prototype.paint.apply(this, [ctx, "#HTMLError", x, y, w, h, style, context])
- cell.tag(null);
- return;
- }
- }
- var svgPattern = '<svg xmlns="http://www.w3.org/2000/svg" width="{0}" height="{1}">' +
- '<foreignObject width="100%" height="100%"><div xmlns="http://www.w3.org/1999/xhtml" style="font:{2}">{3}</div></foreignObject></svg>';
- var data = svgPattern.replace("{0}", w).replace("{1}", h).replace("{2}", style.font).replace("{3}", value);
- var doc = document.implementation.createHTMLDocument("");
- doc.write(data);
- // Get well-formed markup
- data = (new XMLSerializer()).serializeToString(doc.body.children[0]);
- console.log(data);
- img = new Image();
- //var svg = new Blob([data], {type: 'image/svg+xml;charset=utf-8'});
- //var url = DOMURL.createObjectURL(svg);
- //img.src = url;
- img.src = 'data:image/svg+xml;base64,'+ window.btoa(data);
- console.log('data:image/svg+xml;base64,'+ window.btoa(data));
- cell.tag(img);
- img.onload = function () {
- context.sheet.repaint(new GC.Spread.Sheets.Rect(x, y, w, h));
- }
- };
复制代码 输出data:<svg xmlns="http://www.w3.org/2000/svg" width="301" height="151"><foreignObject width="100%" height="100%"><div xmlns="http://www.w3.org/1999/xhtml" style="font:14.6667px " times="" new="" roman""="">null</div></foreignObject></svg>
|