Posted 1 May 2024, 4:01 pm EST - Updated 1 May 2024, 4:07 pm EST
Hi team,
When I copy the wrapped text and paste it into other cells, the cell doesn’t expand and show a full text. Is there any way for us to customize it?
Thank you!
Forums Home / Spread / SpreadJS
Posted by: trankhanhngan00 on 1 May 2024, 4:01 pm EST
Posted 1 May 2024, 4:01 pm EST - Updated 1 May 2024, 4:07 pm EST
Hi team,
When I copy the wrapped text and paste it into other cells, the cell doesn’t expand and show a full text. Is there any way for us to customize it?
Thank you!
Posted 2 May 2024, 6:09 pm EST
Hi,
The “wordWrap” and “autoFit” row are two different functionality and SpreadJS as a component, don’t do automatic conversion. SpreadJS provides several APIs to perform the same as Microsoft Excel.
You could monitor the ClipboardPasted Event, check for the wordwrap and autoFit the row to the pasted range. Kindly refer to the following code snippet and the attached sample:
function getRowsWithWordWrap(sheet, fromRange, cellRange) {
let { row: fromRow, col: fromCol, rowCount: fromRowCount, colCount: fromColCount } = fromRange;
let { row: cellRow, col: cellCol, rowCount: cellRowCount, colCount: cellColCount } = cellRange;
let rowsWithWordWrap = new Set();
for (let i = fromRow; i < fromRow + fromRowCount; i++) {
let hasWordWrap = false;
for (let j = fromCol; j < fromCol + fromColCount; j++) {
if (sheet.getCell(i, j).wordWrap()) {
hasWordWrap = true;
break;
}
}
if (hasWordWrap) {
rowsWithWordWrap.add(i + cellRow - fromRow);
}
}
return Array.from(rowsWithWordWrap);
}
spread.bind(GC.Spread.Sheets.Events.ClipboardPasted, function (sender, args) {
let rows = getRowsWithWordWrap(args.sheet, args.fromRange, args.cellRange);
args.sheet.suspendPaint();
for(let i = 0 ; i < rows.length; i++) {
args.sheet.autoFitRow(rows[i]);
}
args.sheet.resumePaint();
})
References:
ClipboardPasted Event: https://developer.mescius.com/spreadjs/api/classes/GC.Spread.Sheets.Events#clipboardpasted
autoFitRow method: https://developer.mescius.com/spreadjs/api/classes/GC.Spread.Sheets.Worksheet#autofitrow
Regards,
Ankit