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
{{ message }}
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.
I've come across some unexpected behavior when producing and consuming excel documents using EPPlus (dotnet core, EPPlus version 4.5.3.2, on Windows). When I write a newline as carriage return + line feed but then read it back I only get line feed.
This following code demonstrates the issue. First the output:
using System;
using System.IO;
using System.Linq;
using System.Text;
using OfficeOpenXml;
namespace epplus_newline_issue
{
class Program
{
static void Main(string[] args)
{
var testFile = "test.xlsx";
var testString = "Line1\nLine2\r\nLine3";
File.Delete(testFile);
DebugString("String input", testString);
using (var excelPackage = new ExcelPackage())
{
var ws = excelPackage.Workbook.Worksheets.Add("test");
ws.Cells[1, 1].Value = testString;
File.WriteAllBytes(testFile, excelPackage.GetAsByteArray());
}
using (var stream = File.OpenRead(testFile))
using (var excelPackage = new ExcelPackage(stream))
{
var ws = excelPackage.Workbook.Worksheets.First();
var cellText = ws.Cells[1, 1].Value as string;
DebugString("String output", cellText);
}
DebugString("Environment newline", Environment.NewLine);
}
static void DebugString(string label, string s)
{
Console.WriteLine(label + ":");
Console.WriteLine(s);
Console.WriteLine(PrintBytes(Encoding.UTF8.GetBytes(s)));
}
static string PrintBytes(byte[] byteArray)
{
var sb = new StringBuilder("new byte[] { ");
for (var i = 0; i < byteArray.Length; i++)
{
var b = byteArray[i];
sb.Append(b);
if (i < byteArray.Length - 1)
{
sb.Append(", ");
}
}
sb.Append(" }");
return sb.ToString();
}
}
}
If I unpack the excel zip file and investigate what's inside sharedStrings.xml I can see the difference between lf and crlf - the carriage return is retained there:
I've come across some unexpected behavior when producing and consuming excel documents using EPPlus (dotnet core, EPPlus version 4.5.3.2, on Windows). When I write a newline as carriage return + line feed but then read it back I only get line feed.
This following code demonstrates the issue. First the output:
Then the code:
If I unpack the excel zip file and investigate what's inside sharedStrings.xml I can see the difference between lf and crlf - the carriage return is retained there:
So my conclusion is that there is an issue with how the file is read/parsed, not how it is written.
The text was updated successfully, but these errors were encountered: