I am using Excelpackage.codeplex.com
to create xlsx.
When writing a string with apostrophe (') I get a System.Xml.XPath.XPathException
exception.
How can I write an xlsx cell with ' using that package?
private void ExportApostrphoe()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Name");
dt.Rows.Add(1, "Ben");
dt.Rows.Add(2, "Joe's");
dt.Rows.Add(3, "Mike");
FileInfo newFile = new FileInfo(@"c:\1.xlsx");
using (ExcelPackage xlPackage = new ExcelPackage(newFile))
{
OfficeOpenXml.ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets.Add("Sheet1");
for (int x = 0; x < dt.Columns.Count; ++x)
{
DataColumn column = dt.Columns[x];
worksheet.Cell(1, 1 + x).Value = column.Caption;
}
for (int x = 0; x < dt.Columns.Count; ++x)
{
for (int y = 0; y < dt.Rows.Count; ++y)
{
worksheet.Cell(2 + y, 1 + x).DataType = "text";
worksheet.Cell(2 + y, 1 + x).Value = Convert.ToString(dt.Rows[y][x]);
}
}
xlPackage.Save();
}
}