就是如图的方法,以前也是你们提供的,随便就找个市面上的富文本编辑器,比如ckeditor编辑后得到的富文本字符串
把这个富文本字符串传入帖子图片中的方法
- function _html2img(value, style, cell){
- 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 w = cell.sheet.getCellRect(cell.row, cell.col).width;
- var h = cell.sheet.getCellRect(cell.row, cell.col).height;
- 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]);
- img = new Image();
- img.src = 'data:image/svg+xml;base64,'+window.btoa(unescape(encodeURIComponent(data))); // 涉及中文时的转码
- cell.tag(img);
- img.onload = (function (cell, value, img) {
- return () => {
- cell.cellType(new RenderHTMLTagCellType());
- cell.value(value);
- cell.backgroundImageLayout(GC.Spread.Sheets.ImageLayout.center);
- cell.backgroundImage(img.src);
- }
- })(cell, value, img)
- }
复制代码 |