Free Support Forum -

Inline styles are not carried while converting excel to HTML

Hello, we have Aspose total and have a excel content file which we get converted to HTML to show the preview of that content file.

In this process, we convert excel to word first and then word to HTML. When we do this, we are losing some of the inline styles like bold, superscript present for a text inside cell. I have attached a sample file where we are losing inline styles.

Aspose cell version:
Aspose word version:

The sample code…

Aspose.Words.Document document = new Aspose.Words.Document( memoryStream, “MyDocumentFileName.docx”, LoadFormat.Docx, string.Empty );
 using( MemoryStream documentStream = new MemoryStream() )
document.Save( documentStream, SaveFormat.Html );
documentStream.Position = 0;

using( StreamReader reader = new StreamReader( documentStream ) )
return reader.ReadToEnd();

Can you please look into this issue and get back to us ASAP?



I am a representative of Aspose.Cells for .NET team. Well, I have tested to convert your Excel documents to html (directly), pdf and even converted to image file(s), it works fine. The superscripts and formatting work fine.
Here is my sample code using your files:
Workbook book = new Workbook(“e:\test2\fundone_fee-expense_table.xlsx”);
// Workbook book = new Workbook(“e:\test2\fundone_aatr_table.xlsx”);
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageFormat = ImageFormat.Jpeg;
imgOptions.PrintingPage = PrintingPageType.Default;
imgOptions.OnePagePerSheet = true;
Worksheet sheet = book.Worksheets[0];
SheetRender sr = new SheetRender(sheet, imgOptions);
sr.ToImage(0, “e:\test2\Mysheetrender_test” + sheet.Index + “.jpg”);
book.Save(“e:\test2\outHtml.html”, SaveFormat.Html);
book.Save(“e:\test2\outPdf.pdf”, SaveFormat.Pdf);

(I am using the latest version/fix of the product for your case. I have also attached latest version v5.2.1.3 here, so you may use it ).

But, since you are converting Excel to Word first and then converting word to html format for which I am not sure about your process or code segments using Aspose.Words and Aspose.Cells products. So, I welcome Aspose.Words team to look into your issue and comment on it.

Thank you.

Hi Venki,

Thanks for your inquiry.

I am a member of the Aspose.Words team. I have taken a look at your documents. I cannot reproduce the issue when exporting to HTML using Aspose.Words. Most likely there is an issue when you are using transfering the content from Cells to Words. Are you able to post your code here and I will take a look for you.

You could also convert directly from xls format to HTML using the method that Amjad suggested instead.


On Behalf of Venki, the creator of this thread. I am posting below the code snippet that creates a Aspose.Word.Run out of Aspose.Cell. We are having problem in maintainig the alignments of cell in word .

Code Snippet:

static Run GetTextFromCell( Aspose.Cells.Cell cell, Document doc )
Run run = new Run( doc );
string text = cell.StringValue;
Aspose.Cells.Style style = cell.GetStyle();
run.Text = text;
ImportFont( run.Font, cell.GetStyle().Font );
return run;

static void ImportFont( Aspose.Words.Font wordsFont, Aspose.Cells.Font excelFont )

wordsFont.Name = excelFont.Name;
wordsFont.Bold = excelFont.IsBold;
wordsFont.Color = excelFont.Color;
wordsFont.Italic = excelFont.IsItalic;
wordsFont.StrikeThrough = excelFont.IsStrikeout;
wordsFont.Subscript = excelFont.IsSubscript;
wordsFont.Superscript = excelFont.IsSuperscript;
wordsFont.Size = excelFont.Size;
wordsFont.Underline = ConvertUnderline( excelFont.Underline );


Hi Vishwa,

Thanks for this additional information.

I think you are referring to the horizontal alignment of the cell? This property is set for the paragraph and not the run in a Word document, so there is no direct map of this from a cell to a run.

Could you please post a full example which demonstrates the issue and I will provide you with some ideas about how you can implement this.


The original problem is that of excel inline style not coming in the converted word and then html.The excel cell contains string which has font-weight:bold for some portion of the text and remaing text is normal.Is there Any property\method aspose exposes through which we can handle this scenario or we need to resort to conventional string manipulation for this.Attached snapshot for the scenario.

I would also like to know the exact way How we can set Horizontal alignment as well as Vertical alignment for text node i.e w:t if not run from excel cell using aspose.


Hi Vishwa,

Thanks for this additional information. I'm afraid it's still not quite clear what the issue is, could you please attach a template and perhaps some sample code which demonstrates the issue?


Hi ,

The html that is returned by Aspose.Cells.Cell.HtmlString is incorrect ,which results in incorrect html .this is the only issue as of now

I am attaching

1. excel file with inline style superscript ,subscript and strikethrough text in a cell.

2. Value Returned by Aspose.Cell.HtmlString Value (which is incorrect)

3. Html Preview of the cell (which is incorrect and doesnot match with excel cell text styles )

Below is the method where I m reading the cell value.The yellow colored line we are setting wrong html string value to text ,which causes the issue of wrong formatting.

Run GetTextFromCell( Aspose.Cells.Cell cell, Document doc )


Run run = new Run( doc );

string text = cell.HtmlString;

Aspose.Cells.Style style = cell.GetStyle();

run.Text = text;

return run;


Hope these details lets u understand the style issue that we are facing



Hi Partha,

Thank you for additional information. What you are expecting to get when set HTML string as Run.Text? In this case, you will see in the output document raw HTML. If you need to insert HTML into the document, you have to use DocumentBuilder.InsertHtml method like described here:

Best regards,


Thanks for your update .But if the Aspose.Cells.Cell.HtmlString is giving me wrong html (As mentioned in my earlier attached screen shots )then any method of inserting html into word document will any way give me wrong output.Please correct me if I am wrong


Thanks for your update .But if the Aspose.Cells.Cell.HtmlString is giving me wrong html (As mentioned in my earlier attached screen shots )then any method of inserting html into word document will any way give me wrong output.Please correct me if I am wrong



Thanks for your request. I tested this on my side and as I can see both Aspose.Cells and Aspose.Words work correctly. Here is simple code I used for testing:

// Get HTML strign from the Excel workbook.

Workbook workbook = new Workbook(@"C:\Temp\SampleExcel.xlsx");

Worksheet worksheet = workbook.Worksheets[0];

Cell cell = worksheet.Cells[1, 0];

string html = cell.HtmlString;


// Insert an HTML string into Word document.

DocumentBuilder builder = new DocumentBuilder();



I also attached the output DOC file produced by this code. As you can see the text looks the same as in the source Excel file.

Best regards,