Looping through cells is strange

");

foreach (Cell c in cells)

{

thisRow = c.Row;

if (thisRow != prevRowMarker)

{

str.Append ("

");

}

str.Append("

");

prevRowMarker = thisRow;

}

str.Append ("

");


str.Append("

Cells cells = excel.Worksheets[0].Cells;


StringBuilder str = new StringBuilder();
str.Append("<table border = 1 class=content>");

int thisRow = 0;

int prevRowMarker = 0;

str.Append ("

" + c.Value.ToString().Trim() + " 
");


FileStream file = new FileStream(@liveName, FileMode.OpenOrCreate, FileAccess.Write);




For some reason Cells only contains cells that have data! So there is no easy way to loop through correctly if there are blank cells in the spreadsheet.

I also tried doing ExportToDataTable but that won't work for me because the datatypes are sometimes different in the excel spreadsheet (column 1 is sometimes dates and sometimes hyperlinks and sometimes numbers).

So can someone please just show me some sample code that will loop through a worksheet and display it in a HTML table?

Yes. Cells only contains cells that have data and formatting. That can greatly save memory.

Please try the Cells.ExportDataTableAsString method to see if it could meet your need.

@mrbelvedr,
Aspose.Excel is discontinued now and no more development is done for it. It is replaced with another advanced product Aspose.Cells which supports all the latest features of MS Excel. You can achieve your desired functionality by simply rendering print of area of a worksheet to HTML as demonstrated in the following sample code:

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Load the Excel file.
Workbook wb = new Workbook(sourceDir + "sampleInlineCharts.xlsx");

// Access the sheet
Worksheet ws = wb.Worksheets[0];

// Set the print area.
ws.PageSetup.PrintArea = "D2:M20";

// Initialize HtmlSaveOptions
HtmlSaveOptions options = new HtmlSaveOptions();

// Set flag to export print area only
options.ExportPrintAreaOnly = true;

//Save to HTML format
wb.Save(outputDir + "outputInlineCharts.html", options); 

Here is a detailed section where you will find articles to convert HTML to Excel file and vice versa.
HTML

A free latest trial version can be downloaded from the following link:
Aspose.Cells for .NET (Latest Version)

You can test different features of this product by executing the runnable solution available here.