Convert Excel Files to Html with row/column header



Is there any way to convert Excel header index and row index when converting excel to html like display same as Aspose cells webgrid

1 col1 col2 col3 col4
2 aa



First of all, please note that I have split the existing thread to create a new one on your behalf because it is advised to post distinct inquiries in separate threads.

Regarding your original concerns, yes, it is possible to insert the row & column headers to the spreadsheet before converting it to HTML. Here are the series of steps that I would suggest you to follow in order to accomplish your goal.

  • Insert an empty row & column at index 0.
  • Insert column names such as A, B, C in the first row. Similarly, insert row numbers such as 1, 2, 3 in the first column. They will serve as the header column & row respectively.
  • Apply styles on the header column & row as they look in the MS Excel application.
  • Create a range of cells covering the original data, and apply styles to replicate the grid view.


Workbook book = new Workbook(dir + “sample.xlsx”);
Worksheet sheet = book.Worksheets[0];


sheet.Cells.Rows[0].Height = 15.75;
sheet.Cells.Columns[0].Width = 4.75;

int maxRow = sheet.Cells.MaxRow;
int maxCol = sheet.Cells.MaxColumn;

for (int i = 1; i <= maxRow; i++)
sheet.Cells[i, 0].PutValue(i);
for (int j = 1; j <= maxCol; j++)
sheet.Cells[0, j].PutValue(CellsHelper.ColumnIndexToName(j - 1));

Aspose.Cells.Style style = book.CreateStyle();
style.ForegroundColor = Color.LightGray;
style.Pattern = BackgroundType.Solid;
style.Font.IsBold = true;
style.VerticalAlignment = TextAlignmentType.Center;
style.HorizontalAlignment = TextAlignmentType.Center;
style.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
style.Borders[Aspose.Cells.BorderType.LeftBorder].Color = Color.Black;
style.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin;
style.Borders[Aspose.Cells.BorderType.RightBorder].Color = Color.Black;
style.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin;
style.Borders[Aspose.Cells.BorderType.TopBorder].Color = Color.Black;
style.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
style.Borders[Aspose.Cells.BorderType.BottomBorder].Color = Color.Black;

StyleFlag styleFlagHeader = new StyleFlag();
styleFlagHeader.All = true;
sheet.Cells.Rows[0].ApplyStyle(style, styleFlagHeader);
sheet.Cells.Columns[0].ApplyStyle(style, styleFlagHeader);

Aspose.Cells.Range range = sheet.Cells.CreateRange(“B1”, CellsHelper.ColumnIndexToName(maxCol) + (maxRow + 1));
StyleFlag styleFlagGrid = new StyleFlag();
styleFlagGrid.Borders = true;
range.ApplyStyle(style, styleFlagGrid);

book.Save(dir + “output.xlsx”, Aspose.Cells.SaveFormat.Xlsx);
book.Save(dir + “output.html”, new HtmlSaveOptions());


This is a wrong way to do this.
When you add a column and row, the formula’s in other cells will mess up and show up wrong in html.
Look in attachment, the fomulat B3:B5 became C3:C5, when in fact col heading shows BUntitled.png (10.3 KB)


Thank you for your query. Please provide your runnable sample console application, template Excel file, program output files and expected output file generated by using Excel only. It will help us to reproduce the scenario with your sample template file and provide our feedback after comparison with the expected output file.

P.S. Please create a new thread as it will help us to maintain the sample data and other information related to this issue.