How to use PasteOptions() in Aspose.Cells Python via Java

Hi, how do I use PasteOptions() properly in the script below for Aspose.Cells Python via Java? I want to copy and paste special formula in Excel. I’m aware there’s an autoFill function but since we’re using version 21 that function is not available, so we’re opting for PasteOptions() instead.

wb = Workbook(Filepath)

wb.calculateFormula()
ws = wb.getWorksheets().get(0)
src = ws.getCells().createRange(“G12:G12”)
dst = ws.getCells().createRange(“G13:G16”)
options = PasteOptions().setPasteType(8)

src.copy(dst, options)

I’m getting an error message:
java.lang.NullPointerException: Cannot invoke “com.aspose.cells.PasteOptions.getTranspose()” because “options” is null
Traceback (most recent call last):
File “”, line 31, in
java.lang.java.lang.NullPointerException: java.lang.NullPointerException: Cannot invoke “com.aspose.cells.PasteOptions.getTranspose()” because “options” is null

Your help is greatly appreciated, thanks!

@myDAN
Would you like to provide your sample file? We will check it soon.

John.He please see attached sample file
Sample Excel Formula.zip (8.7 KB)

@myDAN
By using sample file and code for testing on the latest version v24.2, we were able to reproduce the issue. Found that NullPointerException occurs when copying range with PasteOptions.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSPYTHONJAVA-87

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like

@myDAN
Please change
options = PasteOptions().setPasteType(8)
to
options = PasteOptions()
options.setPasteType(8)
It works now. Thank you.

1 Like

Thank you @Nick.Liu , I also noticed I have my copy code in reverse order, my code now works and the result is as expected

src.copy(dst, options)
to
dst.copy(src, options)

@myDAN,

It’s great to hear that your issue has been resolved by following the suggested code segment. Please don’t hesitate to reach out if you have any further queries or comments, and we will be happy to assist you soon.