private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog() { Filter = @" Excel文件|*.xlsx;*.xls" };
if (dialog.ShowDialog(this) == DialogResult.OK)
{
fpSpread1.OpenExcel(dialog.FileName,ExcelOpenFlags.NoFlagsSet);
foreach (SheetView sheet in fpSpread1.Sheets)
{
sheet.ColumnCount = sheet.GetLastNonEmptyColumn(NonEmptyItemFlag.Data) + 1;
sheet.RowCount = sheet.GetLastNonEmptyRow(NonEmptyItemFlag.Data) + 1;
//for (int row = 0; row < sheet.RowCount; ++row)
//{
// for (int col = 0; col < sheet.ColumnCount; ++col)
// {
// sheet.Cells[row, col].CellType = null;
// sheet.Cells[row, col].CellType = new RichTextCellType();
// }
//}
sheet.Cells[0, 0, sheet.RowCount - 1, sheet.ColumnCount - 1].CellType = new RichTextCellType();
}
}
}
应该是这个异常导致的
|
|