110,537
社区成员
发帖
与我相关
我的任务
分享
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");