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

Charts directory appears under the drawings directory when packaged #1680

Open
Tsarass opened this issue Feb 28, 2024 · 2 comments
Open

Charts directory appears under the drawings directory when packaged #1680

Tsarass opened this issue Feb 28, 2024 · 2 comments

Comments

@Tsarass
Copy link

Tsarass commented Feb 28, 2024

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
@mikeebowen
Copy link
Collaborator

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?

@Tsarass
Copy link
Author

Tsarass commented Feb 28, 2024

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants