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("
for (int i = 0; i < rowCount; i++)
{
sb.AppendLine("
");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("
");}
else
{
sb.AppendLine("
" + range1.Text + "");}
}
else
{
sb.AppendLine("");
}
}
sb.AppendLine("
");}
sb.AppendLine("
");sb.AppendLine("
");
如题