0

I have been trying to write html content into Excel spreadsheet's cells using ExcelPackage OpenOfficeXML and c#.

I am getting errors stating that input string has an invalid token. Has anyone came across anything similar?

Saving html directly in Excel works OK.

I do not want to use html encoding as the content has to be in readable form.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Luke G
  • 1,741
  • 6
  • 23
  • 34

2 Answers2

1

Without knowing more of the specifics:

If you're using XML to create your spreadsheet, you should use CDATA tags for HTML content

  <someEntry> <![CDATA[ YOUR HTML HERE ]]> </someEntry>

In c# you can add CDATA. It is a type of element.

XmlCDataSection CData;
CData = doc.CreateCDataSection("<someNodeName><h1>blah</h1></someNodeName>");
XmlElement root = doc.DocumentElement;
root.AppendChild(CData);      

Otherwise, you probably need to escape quotes and double quotes \" \'

Or you can use System.Security.SecurityElement.Escape() to encode both single and double quotes.

FlavorScape
  • 13,301
  • 12
  • 75
  • 117
0

Escaping single quotes solved the problem - Replace("'", @"""");

Thank you all.

Luke G
  • 1,741
  • 6
  • 23
  • 34