1.附件是我测试的excel,导入到页面,图片显示是正常的,我将excel中图片复制出来放到项目里,调用以下代码将图片放到页面上,图片尺寸明显不同,该如何写可以正常显示(像导入excel时图片显示的一样)
- $("#sign").click(function() {
- var spread = GC.Spread.Sheets.findControl(document.getElementById('ss'));
- var sheet = spread.getActiveSheet();
- var spreadNS = GC.Spread.Sheets;
- var SheetArea = spreadNS.SheetArea;
- //获取可视化区域行数和列数
- // var rowcount = sheet.getRowCount();
- // var columncount = sheet.getColumnCount();
- //遍历计算可视化区域宽高(px)
- var width = 0,
- height = 0;
- var sheet = spread.getSheet(0);
- console.log('当前选中区域', sheet.getSelections());
- var rowCount = sheet.getSelections()[0].row;
- var colCount = sheet.getSelections()[0].col;
- for(var i = 0; i < rowCount; i++) {
- height += sheet.getRowHeight(i, SheetArea.viewport);;
- }
- for(var i = 0; i < colCount; i++) {
- width += sheet.getColumnWidth(i, SheetArea.viewport);;
- }
- console.log("行数:", rowCount);
- console.log("列数:", colCount);
- console.log("宽:", width);
- console.log("高", height);
- var img = new Image();
- img.src = "img/sign.png";
- img.onload = function() {
- var imgwidth = img.naturalWidth;
- var imgheight = img.naturalHeight;
- var uid = uuid();
- sheet.pictures.add(uid, "img/sign.png", width, height, imgwidth, imgheight);
- }
- })
复制代码
2.我导出时,上面代码加的那个图片咋导不出来,代码如下
- $("#export").click(function() {
- var excelIo = new GC.Spread.Excel.IO();
- var fileName = "测试导出.xlsx";
- var aa= GC.Spread.Sheets.findControl(document.getElementById('ss'));
- var json = aa.toJSON();
- // here is excel IO API
- excelIo.save(json, function(blob) {
- saveAs(blob, fileName);
- });
- })
复制代码
|