Skip to content
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

Copying a sheet containing an OLEObject corrupts the workbook #360

Open
craigbrown opened this issue Apr 9, 2021 · 1 comment
Open

Copying a sheet containing an OLEObject corrupts the workbook #360

craigbrown opened this issue Apr 9, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@craigbrown
Copy link

craigbrown commented Apr 9, 2021

This is an obscure one. I have a worksheet with an OLE Object on it - an Equation object from a very old version of Excel which wasn't visible on the sheet (and I didn't actually realise it was there). When I copy this sheet (either in the same workbook or a new workbook) and then open it in Excel, I get a message from Excel saying that the file is corrupt.

From closer inspection of the XML, it looks like the OLE data is being copied inside the sheet1.xml file, but some of the necessary files aren't:

xl/drawings/drawing1.xml                ✅ copied
xl/drawings/vmlDrawing1.vml             ✅ copied
xl/drawings/_rels/vmlDrawing1.vml.rels  ❌ not copied
xl/embeddings/oleObject1.bin            ❌ not copied
xl/media/image1.wmf                     ❌ not copied
xl/worksheets/_rels/sheet1.xml.rels     ❌ references missing
[Content_Types].xml                     ❌ references missing

If I manually copy the missing files and add the missing lines to sheet1.xml.rels and [Content_Types].xml then I can open the file in Excel without it complaining about it being corrupt.

I've attached a basic file containing an OLE object to demonstrate the bug, and here's some code which will produce a faulty file:

public void CopyWorksheetWithOLEObject()
{
    const string testFilePath = @"C:\OLEObjectTest.xlsx";
    const string outputFilePath = @"C:\OLEObjectTest_Output.xlsx";
    using (var pck = new ExcelPackage(new FileInfo(testFilePath)))
    {
        var ws = pck.Workbook.Worksheets["Sheet1"];
        using (var newPck = new ExcelPackage(new FileInfo(outputFilePath)))
        {
            newPck.Workbook.Worksheets.Add("Sheet1", ws);
            newPck.Save();
        }
    }
}

Probably a very low impact bug, but still thought it was worth letting you know that this problem exists.

OLEObjectTest.xlsx

@JanKallman
Copy link
Contributor

Ole objects are currently not supported by EPPlus, so there are not logic to copy them either. However, it might be a good idea to make sure the copy worksheet copies the bin file and the relations to preserve the objects.

@JanKallman JanKallman added the enhancement New feature or request label Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants