For all characters which cannot be represented in XML as defined by the XML 1.0 specification, the characters are escaped using the Unicode numerical character representation escape character format _xHHHH_, where H
represents a hexadecimal character in the character's value. This is dedined in the OpenXML specification in 22.9.2.19 ST_Xstring (Escaped String).
Currently this causes the following issues:
- Documents conaining such characters are imported incorrectly, e.g. <si><t>_x001B_</t></si> is imported as the plain text _x001B_
- ArgumentException with clarification similar to "' ', hexadecimal value 0x1B, is an invalid character." is thrown when trying to export such documents. Example code to reproduce:
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets.Add();
CellSelection selection = worksheet.Cells[1, 1]; //B2 cell
selection.SetValue(string.Format("Error Value: {0} ", Encoding.ASCII.GetString(new byte[] { 27 })));
string fileName = @"D:\temp\SampleFile.xlsx";
IWorkbookFormatProvider formatProvider = new XlsxFormatProvider();
using (FileStream output = new FileStream(fileName, FileMode.Create))
{
formatProvider.Export(workbook, output);
}