I have the following code in a .Net 4.5 console application. For some reason, it does not like my HtmlString when using the LightCellsDataProvider interface. It allows the excel file to be written but then I get an error when I try and open it. But, it works just fine if I am not using the LightCellsDataProvider interface. Here is some sample code. I am using version 17.9. Any ideas on how to get this working? I need to do some rich text formatting inside of the cells.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Aspose.Cells; namespace ExcelDocumentCreator { class Program { static void Main(string[] args) { try { // Setup License. Aspose.Cells.License license = new Aspose.Cells.License(); license.SetLicense("Aspose.Total.lic"); string tempFolder = @"C:\Temp"; Workbook workbook = new Workbook(); Worksheet worksheet = workbook.Worksheets[0]; //workbook.Save(tempFolder + "\\output_out.xlsx"); //Cell cell = worksheet.Cells["A1"]; //cell.HtmlString = "<Font Style=\"FONT-WEIGHT: bold;FONT-FAMILY: Arial;FONT-SIZE: 10.5pt;COLOR: #222222;\">Other</Font><Font Style=\"FONT-FAMILY: Arial;FONT-SIZE: 10.5pt;COLOR: #222222;\">: <15% of body: $100; ≥15% of body: $500. This benefit is payable only once per covered person, </Font><Font Style=\"FONT-WEIGHT: bold;FONT-STYLE: italic;FONT-FAMILY: Arial;FONT-SIZE: 10.5pt;COLOR: #222222;\">per accident</Font><Font Style=\"FONT-FAMILY: Arial;FONT-SIZE: 10.5pt;COLOR: #222222;\">.</Font>"; ZenLightCellsDataProvider provider = new ZenLightCellsDataProvider(); OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.Xlsx); saveOptions.LightCellsDataProvider = (LightCellsDataProvider)provider; workbook.Save(tempFolder + "\\output_out.xlsx", saveOptions); } catch (Exception exc) { Console.Write(exc); } } } public class ZenLightCellsDataProvider : LightCellsDataProvider { int currentRow = -1; int currentColumn = -1; int maxCellLength = 32767; int maxExportItems = 1048500; #region Constructor public ZenLightCellsDataProvider() : base() { } #endregion #region Properties public long Rows { get { return (long)currentRow; } } #endregion #region LightCellsDataProvider Members public bool IsGatherString() { return false; } public int NextCell() { currentColumn++; if (currentColumn > 0) return -1; else return currentColumn; } public int NextRow() { currentRow++; // if we've passed the max rows, stop getting more if (currentRow > 0) return -1; currentColumn = -1; return currentRow; } public void StartCell(Cell cell) { //cell.HtmlString = "<Font Style=\"FONT-WEIGHT: bold;FONT-STYLE: italic;TEXT-DECORATION: underline;FONT-FAMILY: Arial;FONT-SIZE: 11pt;COLOR: #ff0000;\">This is simple HTML formatted text.</Font>"; cell.HtmlString = "<Font Style=\"FONT-WEIGHT: bold;FONT-FAMILY: Arial;FONT-SIZE: 10.5pt;COLOR: #222222;\">Other</Font><Font Style=\"FONT-FAMILY: Arial;FONT-SIZE: 10.5pt;COLOR: #222222;\">: <15% of body: $100; ≥15% of body: $500. This benefit is payable only once per covered person, </Font><Font Style=\"FONT-WEIGHT: bold;FONT-STYLE: italic;FONT-FAMILY: Arial;FONT-SIZE: 10.5pt;COLOR: #222222;\">per accident</Font><Font Style=\"FONT-FAMILY: Arial;FONT-SIZE: 10.5pt;COLOR: #222222;\">.</Font>"; } public void StartRow(Row row) { } public bool StartSheet(int sheetIndex) { if (sheetIndex == 0) { return true; } else return false; } #endregion } }