Posted 28 September 2020, 3:00 am EST - Updated 29 September 2022, 3:48 pm EST
Hello!
I’m trying to perform a copy operation between workbooks on a range that intersects a merged cell that it doesn’t fully contain.
See the image for illustration of the range
A:A
that I’m trying to copy:
The operation fails with an exception “java.lang.IllegalStateException: Invalid Paste Operation: can’t paste partially on an array formula, merge cell or pivot table.”
However, copy-pasting in excel of that kind of range is not considered illegal. The merged cell is simply ignored. The outcome looks like this:
This is the code I’m using:
var rangeAddress = "A:A"
var filePath = "..."
var sourceWorkbook: Workbook = Workbook().apply { open(filePath) }
val sourceSheet: IWorksheet = sourceWorkbook.worksheets.get(0)
var sourceRange: IRange = sourceSheet.getRange(rangeAddress)
var destinationWorkbook = Workbook()
val destinationSheet: IWorksheet = destinationWorkbook.worksheets.get(0)
var destRange: IRange = destinationSheet.getRange(rangeAddress)
sourceRange.copy(destRange, EnumSet.allOf(PasteType::class.java))
My questions:
- do you plan to support this (in the sense of Excel behavior)?
- how would you recommend to work around this problem?