I am trying to save Excel Sheet to HTML using Office Interope libraries. Everything works fine but formatted cells are not shown as they are in excel sheet. Here is how it looks in MS Excel
And here is what it looks like after conversion in HTML
Here is the code I am using to save Excel sheet as HTML
xApp = new Microsoft.Office.Interop.Excel.Application();
object missing = Type.Missing;
object trueObject = true;
xApp.Visible = false;
xApp.DisplayAlerts = false;
xWorkBook = xApp.Workbooks.Open(ExcelFilePath, missing, trueObject, missing,
missing, missing,missing, missing, missing, missing, missing, missing,
missing, missing, missing);
object format = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml;
xWorkBook.SaveAs(tempFileName, format, missing, missing, missing, missing,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
missing, missing, missing,missing, missing);
The cell formatting shouldn't be visible on the paper or HTML pages. Try to print the page.
If you need to see the cells printed or visible on the HTML page, set the Borders property of the Range class:
Sub SetRangeBorder()
With Worksheets("Sheet1").Range("B2").Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 3
End With
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.