You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I came across this in a more complicated scenario (creating a SpreadsheetDocument from an existing stream, modifying the doc and streaming it out to another different file), but I've distilled the issue to the below example.
In my test the Excel file is created and valid, but trying to use it in "Spreadsheet Compare" causes that app to crash with a "Attempt to read past end of stream" exception.
Opening the generated file in Excel, and saving it again (unchanged) fixes the issue - so the save from within Excel is modifying (fixing) the document.
To Reproduce
Use the following test to create the workbook:
[Fact]
public void CreateAndSaveSpreadsheet()
{
// Arrange
string outputFilename = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location)!, "OutputFolder", "Blank Document Created.xlsx");
if (File.Exists(outputFilename))
File.Delete(outputFilename);
// Act
using (SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.Create(outputFilename, SpreadsheetDocumentType.Workbook))
{
WorkbookPart workbookPart = spreadsheetDoc.AddWorkbookPart();
workbookPart.Workbook = new Workbook();
WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());
Sheets sheets = spreadsheetDoc.WorkbookPart.Workbook.AppendChild(new Sheets());
Sheet sheet = new Sheet()
{
Id = spreadsheetDoc.WorkbookPart.GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "Sheet1"
};
sheets.Append(sheet);
// Save the Workbook
workbookPart.Workbook.Save();
spreadsheetDoc.Save();
}
}
Steps to reproduce the behavior:
Run the test to create the (basically empty) Workbook.
Run Spreadsheet Compare. Choose the above created file for one of the comparison files
See error:
To reproduce a 'fix': Open the created doc in Excel, save it unchanged, redo the Spreadsheet compare (no exception occurs)
Observed behavior
Unexpected exception.
Expected behavior
No exception from spreadsheet compare.
No significant internal file changes when an OpenXml created Workbook is opened in Excel and saved unchanged.
Desktop (please complete the following information):
OS: Windows 10
Office version: Office 365:
.NET Target: .Net 6.0
DocumentFormat.OpenXml Version: 2.20.0
Additional context
Some investigation has led me to believe that the presence of the xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
entry for the default namespace, and the corresponding x: namespace prefixes to the xml tags is the issue.
If I manually edit the internals of the xlsx (sheet1.xml ) file and change the default namespace to have no alias in the 'sheet1.xml' file (as below) the issue is fixed (Spreadsheet Compare does not fail).
I have found to no way to get OpenXml to remove the x alias for the default namespace declared in the document XML.
The text was updated successfully, but these errors were encountered:
Seems this was reported earlier atleast at #509 but a fix was never reached? I'm running into this through ClosedXML (for.ex. ClosedXML/ClosedXML#1436) and would be nice to have it fixed.
Describe the bug
I came across this in a more complicated scenario (creating a SpreadsheetDocument from an existing stream, modifying the doc and streaming it out to another different file), but I've distilled the issue to the below example.
In my test the Excel file is created and valid, but trying to use it in "Spreadsheet Compare" causes that app to crash with a "Attempt to read past end of stream" exception.
Opening the generated file in Excel, and saving it again (unchanged) fixes the issue - so the save from within Excel is modifying (fixing) the document.
To Reproduce
Use the following test to create the workbook:
Steps to reproduce the behavior:
Observed behavior
Unexpected exception.
Expected behavior
No exception from spreadsheet compare.
No significant internal file changes when an OpenXml created Workbook is opened in Excel and saved unchanged.
Desktop (please complete the following information):
Additional context
Some investigation has led me to believe that the presence of the
xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
entry for the default namespace, and the corresponding x: namespace prefixes to the xml tags is the issue.
If I manually edit the internals of the xlsx (sheet1.xml ) file and change the default namespace to have no alias in the 'sheet1.xml' file (as below) the issue is fixed (Spreadsheet Compare does not fail).
I have found to no way to get OpenXml to remove the x alias for the default namespace declared in the document XML.
The text was updated successfully, but these errors were encountered: