question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Before submitting an issue, please fill this out

Is this a:

  • 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

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>();
		worksheetPart.Worksheet = new Worksheet(new SheetData());
		var sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild<Sheets>(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

Expected

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

office365_sample.xlsx image

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
twsouthwickcommented, Nov 9, 2021

We changed it to that as it was causing some renderers to have problems (see https://github.com/OfficeDev/Open-XML-SDK/issues/309).

I’m not certain if there’s a specific encoding is required by the spec, but we could potentially enable it to be configurable rather than relying on a specific default.

1reaction
shps951023commented, Jan 2, 2022

@tomjebo So sorry about long time to see notification and to reply!! Some Chinese users need to custom encoding to read non-UTF8.

@twsouthwick Thanks, I’ll try it

Happy new year! Wish everyone having a great new year.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why office365 xlsx sheet utf8 encoding but openxmlsdk is ...
Issue with the OpenXml library; Question on library usage. If you have answered that this is a question, please ask it on StackOverflow...
Read more >
Each XML part of the generated documents has a BOM prefix
Cannot generate document without BOM sequence prefix on every part of the document. Some viewers throw an error and do not open the...
Read more >
Can I export excel data with UTF-8 without BOM?
I want to make eliminate BOM from Test.lua but I don't know how. (Because Test.lua has some unicode text, I have to use...
Read more >
Why are the Microsoft Office file formats so complicated? ...
Differences in encoding or presence/lack of a BOM in UTF8 are a small set of issues. I've dealt with financial data from very...
Read more >
Encode an Excel File to UTF-8 or UTF-16
Open Office.org · Open up OpenOffice, and open your Excel document. · Click File in the upper left-hand corner of your toolbar. ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found