Open-XML-SDK icon indicating copy to clipboard operation
Open-XML-SDK copied to clipboard

Charts directory appears under the drawings directory when packaged

Open Tsarass opened this issue 1 year ago • 2 comments

Description We are creating spreadsheets using OpenXML with charts. The resulting xlsx files contain the 'charts' directory as a subdirectory of the 'drawings' directory instead of being at the same level as 'drawings' and 'worksheets' directories (under 'xl'). We could not find a workaround in the API to get the expected result.

The xlsx files output by other applications (Excel, LibreOffice Calc etc) output the 'charts' as a sibling directory of 'drawings' instead.

Note: the file can be opened normally in Excel applications as it is.

Here is a tree view of the packaged structure of the xlsx files we are getting with the minimum repro: image

Here is the expected output: image

To Reproduce

SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create("charts-test.xlsx", SpreadsheetDocumentType.Workbook);
WorkbookPart workbookPart = spreadsheetDocument.AddWorkbookPart();
workbookPart.Workbook = new Workbook();
WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());

Sheets sheets = workbookPart.Workbook.AppendChild(new Sheets());
Sheet sheet = new Sheet() { Id = workbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "mySheet" };
sheets.Append(sheet);

DrawingsPart drawingsPart = worksheetPart.AddNewPart<DrawingsPart>();
drawingsPart.AddNewPart<ChartPart>();

workbookPart.Workbook.Save();
spreadsheetDocument.Dispose();

Desktop:

  • OS: Windows 11
  • Office version 16.0.17231.29236
  • .NET Target: NET Framework 4.7.2
  • DocumentFormat.OpenXml Version: 3.0.0

Tsarass avatar Feb 28 '24 08:02 Tsarass

Hi @Tsarass,

As long as the paths are correct in the rels the file is valid and Excel will open it without issue. Does the file you create not open and/or cause errors when you try to open it in Excel?

mikeebowen avatar Feb 28 '24 17:02 mikeebowen

Hi @Tsarass,

As long as the paths are correct in the rels the file is valid and Excel will open it without issue. Does the file you create not open and/or cause errors when you try to open it in Excel?

The file can be opened normally indeed, its just the file structure that's off. I should probably clarify that in the OP as well.

I happen to have a tool that depends on the file structure being right and was wondering why that would happen, it would seem relatively easy to fix (if there is no workaround already).

Tsarass avatar Feb 28 '24 17:02 Tsarass