You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2021/11/22 02:09:13 UTC

[Bug 65695] New: org.apache.poi.ss.extractor.EmbeddedExtractor extract "xls" embedded file can not be opened by office excel

https://bz.apache.org/bugzilla/show_bug.cgi?id=65695

            Bug ID: 65695
           Summary: org.apache.poi.ss.extractor.EmbeddedExtractor extract
                    "xls" embedded file can not be opened by office excel
           Product: POI
           Version: 4.1.2-FINAL
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
          Assignee: dev@poi.apache.org
          Reporter: 1120955357@qq.com
  Target Milestone: ---

Created attachment 38097
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=38097&action=edit
this is origin excel template

I am trying to extract embedded files from excel using
`org.apache.poi.ss.extractor.EmbeddedExtractor`, But when the embedded file is
xls or xlsx, the extracted file can not be opened by office excel. Here is my
test case.

```
    @Test
    public void testExtractEmbeddedFiles() throws IOException {
        Workbook workbook = WorkbookFactory.create(new File("template.xls"));
        Sheet attachment1 = workbook.getSheet("attachment1");
        EmbeddedExtractor extractor = new EmbeddedExtractor();
        List<EmbeddedData> embeddedData = extractor.extractAll(attachment1);
        for (EmbeddedData embeddedDatum : embeddedData) {
            try (FileOutputStream output = new
FileOutputStream(System.currentTimeMillis() + ".xls")) {
               
org.apache.commons.io.IOUtils.write(embeddedDatum.getEmbeddedData(),
                        output);
            }
        }
        workbook.close();
    }
```

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65695] org.apache.poi.ss.extractor.EmbeddedExtractor extract "xls" embedded file can not be opened by office excel

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65695

--- Comment #6 from 1120955357@qq.com ---
(In reply to 1120955357 from comment #5)
> (In reply to PJ Fanning from comment #4)
> > I get this when trying to open the embedded xls in OneDrive.
> > 
> > We can't open this workbook. It's set to show only certain named items, but
> > they aren't in the workbook.
> > You might want to contact the author for more information.
> > 
> > The file opens in Apple Numbers. HSSFWorkbook can parse it.
> 
> Thank you very much for your reply,
> 
> Sorry, I can't understand One Drive's error message, I have no idea how to
> solve the problem
> 
> I can use POI to parse the embedded excel correctly, And I can use Microsoft
> Office to open the embedded excel from the original document.
> 
> But I can't open the exported embedded excel using POI in Microsoft
> Office.Excel, observe the size of the exported files compared with the
> original file, the size of the exported files is slightly larger than the
> size of the original document.I don't know why it happened.
> 
> By the way, I don't know who you mentioned "You might want to contact the
> author for more information". Microsoft Office?

Now I am trying another solution, using POI to parse the embedded file and copy
it to another new workbook. But I can't find any tool class for copying
workbooks from POI now.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65695] org.apache.poi.ss.extractor.EmbeddedExtractor extract "xls" embedded file can not be opened by office excel

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65695

1120955357@qq.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |1120955357@qq.com

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65695] org.apache.poi.ss.extractor.EmbeddedExtractor extract "xls" embedded file can not be opened by office excel

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65695

--- Comment #5 from 1120955357@qq.com ---
(In reply to PJ Fanning from comment #4)
> I get this when trying to open the embedded xls in OneDrive.
> 
> We can't open this workbook. It's set to show only certain named items, but
> they aren't in the workbook.
> You might want to contact the author for more information.
> 
> The file opens in Apple Numbers. HSSFWorkbook can parse it.

Thank you very much for your reply,

Sorry, I can't understand One Drive's error message, I have no idea how to
solve the problem

I can use POI to parse the embedded excel correctly, And I can use Microsoft
Office to open the embedded excel from the original document.

But I can't open the exported embedded excel using POI in Microsoft
Office.Excel, observe the size of the exported files compared with the original
file, the size of the exported files is slightly larger than the size of the
original document.I don't know why it happened.

By the way, I don't know who you mentioned "You might want to contact the
author for more information". Microsoft Office?

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65695] org.apache.poi.ss.extractor.EmbeddedExtractor extract "xls" embedded file can not be opened by office excel

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65695

--- Comment #2 from 1120955357@qq.com ---
(In reply to PJ Fanning from comment #1)
> I tried this workbook with the latest POI code (basically POI 5.1.0) and did
> not get an error.
> 
> The sheet names in your workbook are:
> data
> attachment1 [details]
> attachment2 [details]
> 
> So I used EmbeddedExtractor on attachment1 [details].
> 
> What error are you getting? If you have a stacktrace can you provide it?
> 
> Can you use POI 5.1.0? POI 4 is no longer supported for patches.


The code is running normally, but after exporting the embedded file, I can't
open it in Office Excel.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65695] org.apache.poi.ss.extractor.EmbeddedExtractor extract "xls" embedded file can not be opened by office excel

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65695

PJ Fanning <fa...@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65695] org.apache.poi.ss.extractor.EmbeddedExtractor extract "xls" embedded file can not be opened by office excel

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65695

1120955357@qq.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |NEW

--- Comment #3 from 1120955357@qq.com ---
(In reply to 1120955357 from comment #2)
> (In reply to PJ Fanning from comment #1)
> > I tried this workbook with the latest POI code (basically POI 5.1.0) and did
> > not get an error.
> > 
> > The sheet names in your workbook are:
> > data
> > attachment1 [details]
> > attachment2 [details]
> > 
> > So I used EmbeddedExtractor on attachment1 [details].
> > 
> > What error are you getting? If you have a stacktrace can you provide it?
> > 
> > Can you use POI 5.1.0? POI 4 is no longer supported for patches.
> 
> 
> The code is running normally, but after exporting the embedded file, I can't
> open it in Office Excel.

My project is rather old, so upgrading POI to 5.0 is difficult because the
maven dependencies after upgrading POI 5.0 conflict with my project.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65695] org.apache.poi.ss.extractor.EmbeddedExtractor extract "xls" embedded file can not be opened by office excel

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65695

PJ Fanning <fa...@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All

--- Comment #1 from PJ Fanning <fa...@yahoo.com> ---
I tried this workbook with the latest POI code (basically POI 5.1.0) and did
not get an error.

The sheet names in your workbook are:
data
attachment1
attachment2

So I used EmbeddedExtractor on attachment1.

What error are you getting? If you have a stacktrace can you provide it?

Can you use POI 5.1.0? POI 4 is no longer supported for patches.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65695] org.apache.poi.ss.extractor.EmbeddedExtractor extract "xls" embedded file can not be opened by office excel

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65695

1120955357@qq.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #7 from 1120955357@qq.com ---
Finally, I found the reason. When inserting an xls or xlsx as an embedded file
into another excel file. Microsoft Office sets the embedded excel view to be
hidden. So using POI to extract the embedded file, Microsoft Office cannot
display the workbook in the GUI. So the solution is to call
Workbook.setHidden(false).

But XSSFWorkbook::setHidden is not supported yet. I found another topic for
this issue and hope it will help you.


https://bz.apache.org/bugzilla/show_bug.cgi?id=61699

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 65695] org.apache.poi.ss.extractor.EmbeddedExtractor extract "xls" embedded file can not be opened by office excel

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65695

--- Comment #4 from PJ Fanning <fa...@yahoo.com> ---
I get this when trying to open the embedded xls in OneDrive.

We can't open this workbook. It's set to show only certain named items, but
they aren't in the workbook.
You might want to contact the author for more information.

The file opens in Apple Numbers. HSSFWorkbook can parse it.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org