主题:关于转到excel?
有程序如下:
Excel.ApplicationClass excel = new Excel.ApplicationClass();
excel.Application.Workbooks.Add(true);
excel.Visible = isShowExcele;
Excel.Sheets m_objSheets = null;
Excel._Worksheet m_objSheet = null;
excel.Cells[1, 1] = "机构编码";
excel.Cells[1, 2] = "机构名称";
excel.Cells[1, 3] = "机构编制人数";
excel.Cells[1, 27] = "图片";
int x = 0;
for (int i = 0; i < gridView.Rows.Count; i++)
{
conn.Open();
string sqlstring1 = "select * from JG where JG_ID ='" + GridView1.DataKeys[i].Value.ToString().Trim() + "'";
SqlCommand cmd1 = new SqlCommand(sqlstring1, conn);
SqlDataReader dr1 = cmd1.ExecuteReader();
if (dr1.Read())
{
excel.Cells[x + 2, 1] = dr1["JG_ID"].ToString().Trim();
excel.Cells[x + 2, 2] = dr1["JG_MingCheng"].ToString().Trim();
excel.Cells[x + 2, 3] = dr1["JG_BianZhiRenShu"].ToString().Trim();
///////图片显示
}
x = x + 1;
}
excel.DisplayAlerts = false;
if (File.Exists(Server.MapPath(".") + "\\" + "zt.xls"))
{
File.Delete(Server.MapPath(".") + "\\" + "zt.xls");
}
excel.Save(Server.MapPath(".") + "\\" + "zt.xls");/////错误就出现在这里,如果点击保存就没有错误,但是如果点击取消就出现错误HRESULT:0X800A03EC
excel.Application.Workbooks.Close();
excel.Application.Quit();
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
//KillProcess(52);
GC.Collect();
发现当保存文件时,弹出文件框,如果点击保存路径,则成功,
但是如果点击--取消,则出现错误,HRESULT:0X800A03EC
不知道是什么原因?大侠帮忙啊!![em10][em10]
Excel.ApplicationClass excel = new Excel.ApplicationClass();
excel.Application.Workbooks.Add(true);
excel.Visible = isShowExcele;
Excel.Sheets m_objSheets = null;
Excel._Worksheet m_objSheet = null;
excel.Cells[1, 1] = "机构编码";
excel.Cells[1, 2] = "机构名称";
excel.Cells[1, 3] = "机构编制人数";
excel.Cells[1, 27] = "图片";
int x = 0;
for (int i = 0; i < gridView.Rows.Count; i++)
{
conn.Open();
string sqlstring1 = "select * from JG where JG_ID ='" + GridView1.DataKeys[i].Value.ToString().Trim() + "'";
SqlCommand cmd1 = new SqlCommand(sqlstring1, conn);
SqlDataReader dr1 = cmd1.ExecuteReader();
if (dr1.Read())
{
excel.Cells[x + 2, 1] = dr1["JG_ID"].ToString().Trim();
excel.Cells[x + 2, 2] = dr1["JG_MingCheng"].ToString().Trim();
excel.Cells[x + 2, 3] = dr1["JG_BianZhiRenShu"].ToString().Trim();
///////图片显示
}
x = x + 1;
}
excel.DisplayAlerts = false;
if (File.Exists(Server.MapPath(".") + "\\" + "zt.xls"))
{
File.Delete(Server.MapPath(".") + "\\" + "zt.xls");
}
excel.Save(Server.MapPath(".") + "\\" + "zt.xls");/////错误就出现在这里,如果点击保存就没有错误,但是如果点击取消就出现错误HRESULT:0X800A03EC
excel.Application.Workbooks.Close();
excel.Application.Quit();
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
//KillProcess(52);
GC.Collect();
发现当保存文件时,弹出文件框,如果点击保存路径,则成功,
但是如果点击--取消,则出现错误,HRESULT:0X800A03EC
不知道是什么原因?大侠帮忙啊!![em10][em10]