NET中 从数据库导出数据到EXCEL 求具体代码示例 数据源我已经得到dataset类型
1个回答
展开全部
//获取数据
DataSet ds = ltd.ConvertToDataSet<InfrCenter_LoginLogVO>(IlBLL.GetAllList());
if (ds.Tables[0].Rows.Count > 0)
{
Aspose.Excel.Excel excel = new Aspose.Excel.Excel();
Worksheet sheet = excel.Worksheets["Sheet1"];
sheet.Name = "登陆日志";
Cells cells = sheet.Cells;
cells["A1"].PutValue("记录编号");
cells["B1"].PutValue("用户名");
cells["C1"].PutValue("登陆Ip");
cells["D1"].PutValue("登陆时间");
cells["E1"].PutValue("登出时间");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
{
cells[i, (byte)j].PutValue(ds.Tables[0].Rows[i][j]);
}
}
string nowTime = DateTime.Now.Year + "年" + DateTime.Now.Month + "月" + DateTime.Now.Day + "日" + DateTime.Now.Hour + "时" + DateTime.Now.Minute + "分" + DateTime.Now.Second + "秒-登陆日志报表";
excel.Worksheets.Add();
excel.Save(string.Format("E:/{0}.xls", nowTime));
DataSet ds = ltd.ConvertToDataSet<InfrCenter_LoginLogVO>(IlBLL.GetAllList());
if (ds.Tables[0].Rows.Count > 0)
{
Aspose.Excel.Excel excel = new Aspose.Excel.Excel();
Worksheet sheet = excel.Worksheets["Sheet1"];
sheet.Name = "登陆日志";
Cells cells = sheet.Cells;
cells["A1"].PutValue("记录编号");
cells["B1"].PutValue("用户名");
cells["C1"].PutValue("登陆Ip");
cells["D1"].PutValue("登陆时间");
cells["E1"].PutValue("登出时间");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
{
cells[i, (byte)j].PutValue(ds.Tables[0].Rows[i][j]);
}
}
string nowTime = DateTime.Now.Year + "年" + DateTime.Now.Month + "月" + DateTime.Now.Day + "日" + DateTime.Now.Hour + "时" + DateTime.Now.Minute + "分" + DateTime.Now.Second + "秒-登陆日志报表";
excel.Worksheets.Add();
excel.Save(string.Format("E:/{0}.xls", nowTime));
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询