-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Charts Not Copied #1300
Comments
Hi, I did some research I didn't find such method in original POI. Try to use |
Thanx for the quick reply, @Bykiev. And thanx for helping maintain a very cool library! I don't understand, though, how |
I tried the following approach but it didn't work:
The exception occurred on the line
|
Basically, you don't even need to create a copy of the sheet - just remove the other sheets and save it as a new workbook. It's just a workaround. |
Good point, thanx. Unfortunately, the resulting workbook is corrupted. When I try to open it I get the following message from Excel after allowing it to try & fix what it can:
I'm wondering if it has to do with the fact the original workbook contains a chartsheet which references named ranges that are defined in a sheet I create (let's call that one the data sheet). Since the first step in the process you described (if I understood it correctly) is to delete the sheets I'll be creating, the data sheet gets deleted before it is created. Might that be triggering a REF error -- because the named ranges the chart depends on are (temporarily) gone -- that ends up corrupting the file? My goal is to take a workbook that contains a chartsheet that draws from a data sheet and replace the information in the datasheet with updated information. Perhaps I'm required to never delete the original data sheet, but just update its contents (and its named ranges, since the number of rows may change with new information)? |
Success! The trick was to not delete and re-create the data sheet but clear its contents -- but not its named ranges -- and then adjust the named ranges' formulas. Thanx for your help, @Bykiev! |
closing... |
We will close the issue after fixing the bug with |
Oops, sorry, forgot about that... |
Sigh... still running into problems. When I try to write the workbook back to the file system, an exception is thrown about the file already being open. I created the workbook from an existing file like this:
Does that not close any streams opened to read the file? I assumed it would. |
Please disregard that last question. I over complicated handling existing files and screwed up the save process. I’ve fixed my code. |
Closing this issue as duplicate. Please subscribe #1338 |
NPOI Version
2.7.0
File Type
Upload the Excel File
Cumulative Active Lapsed - Copy.xlsx
Reproduce Steps
Here is the code fragment I'm using to do the copy.
existingWorkbook
contains the charts, whileworkbook
is a newly-created (by NPOI) XSSFWorkbook. The conditional test simply means "don't copy any sheet with the same name as a sheet that's already been created inworkbook
".Issue Description
When I copy a sheet from an existing workbook (also created by NPOI) to a new workbook, charts do not get copied. Instead, for a chart sheet I end up with a blank sheet (with the correct name). For charts embedded in a sheet, the sheet gets copied (with the correct name), but the embedded chart does not.
The text was updated successfully, but these errors were encountered: