只要是下载的都是这样的吧。if(this.Request.QueryString["ClassGuid"]!=null)
{
JBInfoBase.SingMems pSM=new JBInfoBase.SingMems();
string pFileName=this.Request.QueryString["ClassName"].ToString();
System.Data.DataTable pDateTable=pSM.SearchExcelDate(this.Request.QueryString["ClassGuid"].ToString().Trim());
HttpResponse rsp;
rsp=Page.Response;
rsp.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//乱码问题
rsp.AppendHeader("Content-Disposition", "attachment;filename="+pFileName ); //'必要,做成下载文件 Excel.Application oExcel=null;
Excel.Workbook oBook;
Object oMissing=System.Reflection.Missing.Value ;
oExcel=new Excel.Application();
oBook=oExcel.Workbooks.Add(oMissing);
int rows;
int clumns;
// System.Globalization.CultureInfo pa=new System.Globalization.CultureInfo("zh-CHS");
//
// System.Globalization.NumberFormatInfo pN=new System.Globalization.NumberFormatInfo();
rows=pDateTable.Rows.Count-1;
clumns=pDateTable.Columns.Count-1;
for(int i=0;i<=rows;i++)
{
// oExcel.get_Range(oExcel.Cells[i,6],oExcel.Cells[i+1,6]).ClearFormats();
for(int j=0;j<=clumns;j++)
{
if(i==0)
{
oExcel.Cells[1,j+1]=pDateTable.Columns[j].ColumnName.ToString();
}
oExcel.Cells[i+2,j+1]=pDateTable.Rows[i][j].ToString();
}
}
oBook.Saved=true;
oExcel.UserControl=false;
string file=Server.MapPath(".")+"\\" + pFileName;//Server.MapPath(".")服务器保存地址
oExcel.ActiveWorkbook.SaveCopyAs(file);
//oExcel.Quit();
rsp.WriteFile(file);
oExcel.Quit();
oExcel=null;
// rsp.Flush();
// rsp.End();
//JBInfoBase.MakeExcel pME=new JBInfoBase.MakeExcel();
//pME.GenerateFile(this.Page,this.Request.QueryString["ClassName"].ToString(),pDT);
}看看这个。我就没有你说的那样
{
JBInfoBase.SingMems pSM=new JBInfoBase.SingMems();
string pFileName=this.Request.QueryString["ClassName"].ToString();
System.Data.DataTable pDateTable=pSM.SearchExcelDate(this.Request.QueryString["ClassGuid"].ToString().Trim());
HttpResponse rsp;
rsp=Page.Response;
rsp.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//乱码问题
rsp.AppendHeader("Content-Disposition", "attachment;filename="+pFileName ); //'必要,做成下载文件 Excel.Application oExcel=null;
Excel.Workbook oBook;
Object oMissing=System.Reflection.Missing.Value ;
oExcel=new Excel.Application();
oBook=oExcel.Workbooks.Add(oMissing);
int rows;
int clumns;
// System.Globalization.CultureInfo pa=new System.Globalization.CultureInfo("zh-CHS");
//
// System.Globalization.NumberFormatInfo pN=new System.Globalization.NumberFormatInfo();
rows=pDateTable.Rows.Count-1;
clumns=pDateTable.Columns.Count-1;
for(int i=0;i<=rows;i++)
{
// oExcel.get_Range(oExcel.Cells[i,6],oExcel.Cells[i+1,6]).ClearFormats();
for(int j=0;j<=clumns;j++)
{
if(i==0)
{
oExcel.Cells[1,j+1]=pDateTable.Columns[j].ColumnName.ToString();
}
oExcel.Cells[i+2,j+1]=pDateTable.Rows[i][j].ToString();
}
}
oBook.Saved=true;
oExcel.UserControl=false;
string file=Server.MapPath(".")+"\\" + pFileName;//Server.MapPath(".")服务器保存地址
oExcel.ActiveWorkbook.SaveCopyAs(file);
//oExcel.Quit();
rsp.WriteFile(file);
oExcel.Quit();
oExcel=null;
// rsp.Flush();
// rsp.End();
//JBInfoBase.MakeExcel pME=new JBInfoBase.MakeExcel();
//pME.GenerateFile(this.Page,this.Request.QueryString["ClassName"].ToString(),pDT);
}看看这个。我就没有你说的那样
问题应该是这样。