dotnet / dotnet/Open-XML-SDK

Why office365 xlsx sheet utf8 encoding but openxmlsdk is utf8-withbom

Open
#1,064 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4.6k
Forks
605
PR merge metrics
No merged PRs in 30d

Description

# Before submitting an issue, please fill this out

Is this a:
- [X] Issue with the OpenXml library
- [ ] Question on library usage

If you have answered that this is a question, please ask it on StackOverflow instead of here.
This issue tracker is meant to track product issues while StackOverflow excels at answering questions

---------------- Remove this line and above before posting ----------------

**Description**

Please provide a simple description of the issue encountered.

**Information**

- .NET Target: .NET Core
- DocumentFormat.OpenXml Version: 2.14.0

**Repro**

```csharp
public class Program
{
public static void Main(string[] args)
{
var directoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory());
var fileName = $@"PracticePart1-{DateTime.Now:yyyyMMddHHmmss}.xlsx";
var filepath = Path.Combine(directoryInfo.ToString(), fileName);
Console.WriteLine($"FilePath: {filepath}");
var spreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook);
var workbookPart = spreadsheetDocument.AddWorkbookPart();
workbookPart.Workbook = new Workbook();
var worksheetPart = workbookPart.AddNewPart();
worksheetPart.Worksheet = new Worksheet(new SheetData());
var sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
var sheet = new Sheet()
{
Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "myFirstSheet"
};
sheets.Append(sheet);
workbookPart.Workbook.Save();
spreadsheetDocument.Close();
}
}

```

**Observed**

Office 365 encoding are all utf-8 without bom, but openxmlsdk some're utf-8 with bom and some not
![image](https://user-images.githubusercontent.com/12729184/140602402-3c92c12f-07d5-4c1c-bee6-6bf6c2e5205b.png)

**Expected**

Should we follow office365 encoding standard? (below image is office 365 xlsx)

[office365_sample.xlsx](https://github.com/OfficeDev/Open-XML-SDK/files/7490064/office365_sample.xlsx)
![image](https://user-images.githubusercontent.com/12729184/140602536-25a05fd2-ca55-443d-91bd-7366bfac2f69.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.