62,046
社区成员
发帖
与我相关
我的任务
分享
private void ToExcel(DataSet ds)
{
object missing = Missing.Value;
string savePath = Server.MapPath("./") + @"ExcelFile/";
DirectoryInfo upDir = new DirectoryInfo(savePath);
if (!upDir.Exists)
{
upDir.Create();
}
if (ds.Tables[0].Rows.Count != 0)
{
savePath += ds.Tables[0].Rows[0]["员工姓名"].ToString().Trim();
Excel.Application excel = new Excel.ApplicationClass();
excel.Application.Workbooks.Add(true);
//Sheets xslSheets = Excel.Worksheets;
//xslSheets.get
for (int i = 1; i <= ds.Tables[0].Rows.Count; i++)
{
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
{
excel.Cells[i,j] = ds.Tables[0].Rows[i][j].ToString();
}
}
excel.Visible = false;
excel.ActiveWorkbook.SaveCopyAs(savePath);
excel.Workbooks.Close();
excel.Application.Quit();
excel.Quit();
}
}