Open-XML-SDK
Open-XML-SDK copied to clipboard
Excel File CustomFilePropertiesPart removed after Save As file
Before submitting an issue, please fill this out
Is this a:
- [x] Question on library usage
Description
I added CustomFilePropertiesPart in an excel file using C# code, but after Save As this file in the machine new file doesn't show any CustomFilePropertiesPart in Open Xml Productivity Tool.
Information
- .NET Target: 4.5
- DocumentFormat.OpenXml Version: 2.8.1.0
Repro After Save as file CustomFilePropertiesPart property gets removed automatically. But some file doesn't remove properly. E6_P1_eStart.xlsx
Observed
After Save as file CustomFilePropertiesPart property gets removed automatically. But some file doesn't remove properly.
Expected
CustomFilePropertiesPart property should be in the new Save as a file.
I tried to reproduce your issue but I was unable to. I grabbed your sample file, ran the following:
using (FileStream fs = new FileStream(@"E6_P1_eStart 2.xlsx", FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (SpreadsheetDocument doc = SpreadsheetDocument.Open(fs, false))
{
var studentProp = doc.CustomFilePropertiesPart.Properties.First() as CustomDocumentProperty;
var value = studentProp.InnerText;
Debug.WriteLine($"{studentProp.Name}: {value}");
doc.SaveAs(@"eStartSaveAs.xlsx");
}
}
using (FileStream fs = new FileStream(@"eStartSaveAs.xlsx", FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (SpreadsheetDocument doc = SpreadsheetDocument.Open(fs, false))
{
var studentProp = doc.CustomFilePropertiesPart.Properties.First() as CustomDocumentProperty;
var value = studentProp.InnerText;
Debug.WriteLine($"{studentProp.Name}: {value}");
}
}
Which produced the output:
StudentID: 148924
StudentID: 148924
Are you able to provide more information on your issue?