Free Support Forum - aspose.com

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.