导入excel问题

永动bug制造机 永动bug制造机 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

DataTable dt = new DeceasedManage().BookDetail_Query(from, to);
int rows = dt.Rows.Count;//行数
int columns = dt.Columns.Count;//列数


Workbook book = new Workbook();
Worksheet sheet = new Worksheet("sheet1");


//设置标题
sheet.Cells[0, 0] = new Cell("登记表");

//设置列名
for (int i = 0; i < columns; i++)
{
sheet.Cells[1, i] = new Cell(dt.Columns[i].ColumnName);
}

//导入值
string value = "";
for (int r = 0; r < rows; r++)
{
for (int c = 0; c < columns; c++)
{
value = dt.Rows[r][c].ToString();
sheet.Cells[r + 2, c] = new Cell(value);
}
}

book.Worksheets.Add(sheet);
string name = DateTime.Now.ToString("yyyy-MM-dd hh.mm.ss");
book.Save(@"E:\" + name + ".xls");

在Save的时候有异常,异常如下:
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------

指定的参数已超出有效值的范围。
参数名: SATSectorIndex
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。
参数名: SATSectorIndex

源错误:

执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。

堆栈跟踪:


[ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。
参数名: SATSectorIndex]
ExcelLibrary.Office.CompoundDocumentFormat.MasterSectorAllocation.GetSATSectorID(Int32 SATSectorIndex) +183
ExcelLibrary.Office.CompoundDocumentFormat.SectorAllocation.LinkSectorID(Int32 sectorID, Int32 newSectorID) +164
ExcelLibrary.Office.CompoundDocumentFormat.MasterSectorAllocation.AllocateMSATSector() +242
ExcelLibrary.Office.CompoundDocumentFormat.MasterSectorAllocation.AllocateSATSector() +316
ExcelLibrary.Office.CompoundDocumentFormat.MasterSectorAllocation.GetSATSectorID(Int32 SATSectorIndex) +124
ExcelLibrary.Office.CompoundDocumentFormat.SectorAllocation.LinkSectorID(Int32 sectorID, Int32 newSectorID) +164
ExcelLibrary.Office.CompoundDocumentFormat.MasterSectorAllocation.AllocateMSATSector() +242
ExcelLibrary.Office.CompoundDocumentFormat.MasterSectorAllocation.AllocateSATSector() +316
ExcelLibrary.Office.CompoundDocumentFormat.MasterSectorAllocation.GetSATSectorID(Int32 SATSectorIndex) +124
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
永动bug制造机
C# 111,128 成员 642,537 内容