0

I'm using a product called "Aspose Cells" which allows me to generate an Excel workbook from HTML.

Recently, I wrote code to export a large table to Excel using Aspose Cells. I'm running into a problem where line breaks are stripped out of my cells.

So, the HTML may look like this in a browser:

Name | Address
-----+--------------
Bob  | 123 Main St,
     | Miami, FL
-----+--------------
Sue  | 123 Broadway,
     | New York NY

But when rendered by Aspose Cells, it looks like this:

Name | Address
-----+--------------
Bob  | 123 Main St,Miami, FL
-----+--------------
Sue  | 123 Broadway,New York NY

I have tried coding this several different ways. I have tried putting the street and city in different divs within a cell and I've tried putting a line break tag between them, but Aspose Cells seems to be ignoring the line break for some reason.

How do I make this table render with line breaks using Aspose Cells?

Update: Here's a snippet of code that will create a table like this:

html = "<table><tr><td>Bob</td><td>123 Main St,<br />Miami, FL</td></tr><tr><td>Sue</td><td>123 Broadway,<br />New York, NY</td></tr></table>";

Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense("Aspose.Total.lic");

var options = new HTMLLoadOptions(LoadFormat.Html);     
byte[] data = Encoding.UTF8.GetBytes(html);
Workbook workbook;
using (MemoryStream ms1 = new MemoryStream(data))
{
        workbook = new Workbook(ms1, options);
}
MemoryStream ms = new MemoryStream();
workbook.Save(ms, SaveFormat.Xlsx);
ms.Seek(0, SeekOrigin.Begin);
return ms;
Vivian River
  • 31,198
  • 62
  • 198
  • 313

1 Answers1

1

You should try out latest version/fix of Aspose.Cells APIs. I have tested your scenario/ case using the following sample code (I did add/update a few more lines to your code segment) with latest version/fix (e.g v8.8.2.10), it works fine and as expected. e.g. Sample code:

 string html = "<table><tbody><tr><td>Bob</td><td>123 Main St,<br>Miami, FL</td></tr><tr><td>Sue</td><td>123 Broadway,<br>New York, NY</td></tr></tbody></table>";

        LoadOptions options = new HTMLLoadOptions(LoadFormat.Html);
        byte[] data = Encoding.UTF8.GetBytes(html);
        Workbook workbook;
        using (MemoryStream ms1 = new MemoryStream(data))
        {
            workbook = new Workbook(ms1, options);
        }

        //Extend the width and Auto-fit second column
        workbook.Worksheets[0].Cells.SetColumnWidth(1, 13);
        workbook.Worksheets[0].AutoFitColumn(1);


        //Saving&nbsp;the&nbsp;Excel&nbsp;file
        MemoryStream ms = new MemoryStream();
        workbook.Save(ms, SaveFormat.Xlsx);
        ms.Seek(0, SeekOrigin.Begin);
        byte[] buffer = new byte[ms.Length];
        buffer = ms.ToArray();
        FileStream fs = new FileStream("e:\\test2\\outlinebreaks1.xlsx", FileMode.Create);
        fs.Write(buffer, 0, buffer.Length);
        fs.Close();
        ms.Close();

I am working as Support developer/ Evangelist at Aspose

Amjad Sahi
  • 1,813
  • 1
  • 10
  • 15
  • Thanks! I just heard back from enterprise support, who told me the exact same thing. I think we are going to have to upgrade our license to get access to this version. – Vivian River Jun 27 '16 at 19:33