Posted 15 November 2023, 11:04 pm EST
Hi.
I wanna know if i can crop a image based on a range?
For exemple:
select A1:B6, then generate a crop of this range, if is possible in a SVG type.
Forums Home / Spread / SpreadJS
Posted by: ricardo.aleixo on 15 November 2023, 11:04 pm EST
Posted 15 November 2023, 11:04 pm EST
Hi.
I wanna know if i can crop a image based on a range?
For exemple:
select A1:B6, then generate a crop of this range, if is possible in a SVG type.
Posted 16 November 2023, 11:24 pm EST
Hi,
As I can understand, you want to create an image from a cell range on the sheet. For this, you can use the cellRange.toHtml() method to get the html table string for the specified cell range. The html of table can be used to create the SVG image.
Please refer to the code snippet below and the attached sample for more understanding.
// returns blob of svg of cell range
function getCellRangeSvg(sheet, range) {
let htmlString = sheet.getRange(range.row, range.col, range.rowCount, range.colCount).toHtml(GC.Spread.Sheets.HeaderOptions.noHeaders, true);
let height = getCellRangeHeight(sheet, range), width = getCellRangeWidth(sheet, range);
const svg = `
<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}">
<foreignObject width="100%" height="100%">
<div xmlns="http://www.w3.org/1999/xhtml">${htmlString}</div>
</foreignObject>
</svg>
`;
const svgBlob = new Blob([svg], { type: 'image/svg+xml;charset=utf-8' });
return svgBlob;
}
If you face any issues, please let us know.
References:
cellRange.toHtml(): https://developer.mescius.com/spreadjs/api/v16/classes/GC.Spread.Sheets.CellRange#tohtml
Regards