excel = new Excel.Application();
excel.UserControl = true;
excel.DisplayAlerts = false;
excel.Application.Workbooks.Open(fileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
wbs = excel.Workbooks;
wb = wbs[1];
for (int k = 0; k < wb.Worksheets.Count; k++)
{
ws = (Excel.Worksheet)wb.Worksheets[k + 1];
if (ws == null) continue;
int rowCount = ws.UsedRange.Rows.Count;
int colCount = ws.UsedRange.Columns.Count;
sb.AppendLine("<table width=\"100%\" cellpadding=0 cellspacing=0 border=1 bordercolor=\"#888888\" style=\"border-collapse:collapse;padding:4px;\">");
for (int i = 0; i < rowCount; i++)
{
sb.AppendLine("<tr>");
for (int j = 0; j < colCount; j++)
{
range1 = ws.Range[ws.Cells[i + 1, j + 1], ws.Cells[i + 1, j + 1]];
if (range1 != null)
{
if (range1.Text.ToString() == "")
{
sb.AppendLine("<td></td>");
}
else
{
sb.AppendLine("<td>" + range1.Text + "</td>");
}
}
else
{
sb.AppendLine("");
}
}
sb.AppendLine("</tr>");
}
sb.AppendLine("</table>");
sb.AppendLine("<br>");
如题