Posted 2 May 2024, 1:01 am EST - Updated 2 May 2024, 1:07 am 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 2 May 2024, 1:01 am EST
Posted 2 May 2024, 1:01 am EST - Updated 2 May 2024, 1:07 am 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 3 May 2024, 3:09 am 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
Posted 4 July 2024, 3:23 am EST
Hi Ankit,
This sample works for us to expand cell when copying wrapped text. But we encounter another error that users cannot undo after paste action.
Is there any solution for it?
Really thank you!
Posted 5 July 2024, 2:05 am EST - Updated 5 July 2024, 2:11 am EST
Hi,
I tested with the previously provided sample, and undo is working, but we need to perform the undo action twice to revert to the previous state. Refer to the attached GIF “version17.0.8behavior.gif”.
Gif:
However, after upgrading to the latest version 17.1.0, it works as expected. Refer to the attached GIF “version17.1.0behavior.gif” and sample.
Gif:
If undo is not working on your end, to better assist you, could you share a sample along with the steps to replicate the behavior you have observed, or modify the existing sample to replicate the behavior? This will enable me to investigate the problem more thoroughly. Additionally, it would be helpful if you could provide a GIF or video illustrating the issue.
Regards,
Priyam
Posted 7 July 2024, 12:07 am EST
Hi Priyam,
The error just happens if we copy-paste a plain text outside spreadsheet.
I add a condition to check this case, and there is no bug now:
spread.bind(GC.Spread.Sheets.Events.ClipboardPasted, function (sender, args) {
if(args.fromRange && args.fromSheet) {
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();
}
})
Posted 8 July 2024, 1:01 am EST
Hi,
We are happy that your query has been resolved.
Regards,
Priyam