Posted 11 February 2025, 8:14 pm EST - Updated 11 February 2025, 8:26 pm EST
Hello,
When I tried to export spread to xlsx, this error occurred.
Here is my cord.
// 1. load Json to Xlsx using fromJSON
var jsonOptions = {
includeBindingSource: true,
ignoreStyle: false,
ignoreFormula: false,
saveAsView: true,
rowHeadersAsFrozenColumns: false,
columnHeadersAsFrozenRows: false,
includeAutoMergedCells: true
};
let spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
function loadXlsxDB() {
$.ajax({
type: "GET",
url: "/SpreadJs/Excel/LoadJson",
success: function (response) {
spread = GC.Spread.Sheets.findControl(document.getElementById('ss'));
spread.fromJSON(JSON.parse(response), jsonOptions);
spread.resumeEvent();
spread.resumeCalcService();
spread.resumePaint();
sheet = spread.getSheet(spread.getSheetIndex("sheet1"));
},
error: function (request, status, error) {
console.log(request.responseText, status, error);
}
});
}
// 2. load data by clicking btn loading this function.
function loadContentXlsx() {
getHeader();
getContent();
getFooter();
}
//3. among those methods, In "getFooter()" methods, some images loaded.
function getFooter() {
let markArray = new Array();
markArray.push("/images/ShippingMark/shippingmark1.png");
markArray.push("/images/ShippingMark/shippingmark2.png");
markArray.push("/images/ShippingMark/shippingmark3.png");
markArray.push("/images/ShippingMark/shippingmark4.png");
markArray.push("/images/ShippingMark/shippingmark5.png");
let row = 163; // images started here
let col = 0;
let nextX = 0;
let nextY = 0;
for(let i=0 ; i<markArray.length; i++) {
let image = sheet.shapes.addPictureShape(i, markArray[i], 0, 0, 0, 0);
// load images in specific row and column.
image.startRow(row);
image.startColumn(col);
switch(i) {
case 0:
case 3:
col += 3;
break;
case 1:
case 4:
col += 5;
break;
case 2:
case 5:
row += 9;
col = 0;
break;
}
}
}
// export SpreadJS to xlsx file
function saveXlsx() {
let printInfo = sheet.printInfo();
printInfo.repeatRowStart(0);
printInfo.repeatRowEnd(5);
printInfo.columnStart(0);
printInfo.columnEnd(16);
printInfo.pageRange("A1:Q240");
printInfo.zoomFactor(0.62);
sheet.setRowPageBreak(94, true);
sheet.setRowPageBreak(181, true);
printInfo.centering(GC.Spread.Sheets.Print.PrintCentering.horizontal);
printInfo.pageHeaderFooter({
normal: {
footer: {
right: "&P/&N"
}
}
});
printInfo.margin({ top: 60, bottom: 20, left: 23, right: 23, header: 30, footer: 30 });
printInfo.paperSize(new GC.Spread.Sheets.Print.PaperSize(GC.Spread.Sheets.Print.PaperKind.a4));
let fileType = "xlsx";
let fileName = "title"+ "." + fileType;
spread.export(
function(blob) {
console.log(blob);
saveAs(blob, fileName);
},
function (e) { console.log(e); }, saveOptions
);
}
there are two types of images in SpreadJS.
- Base images (which are saved in base64 in json file, so when I load json, it is loaded together)
- Data images (which are loaded by button)
The problems are :
- When I load json String, the base images are duplicated. ( I attached sample json file and capture of SpreadJS)
- original excel file
2) SpreadJS (using fromJSON)
(I moved images for examples, but it appear exact same location)
It occurs when I save SpreadJS to xlsx file, so finally there are four same images on xlsx file.
- When I load Data images and try to saving it to xlsx file, this error occurs.
Is there any problems with my code, or should I fix my code?
I need some help.
Thank you.