时间太紧,老板又催得急,故高分仅求极度关注,提供线索也给分。 http://expert.csdn.net/Expert/topic/1604/1604105.xml?temp=.669552 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不懂你的意思。导出这个过程是Web 实现的?? 那咋来后台进程??还是有个后台进程,这个进程访问个有DataGrid的页面,然后把其中DataGrid中的数据导出到Excel ?? 导出到excel时,打开execl文件,服务器后台应该有一个excel.exe进程,据说很难将他shutdown掉,自己顶一下。up! Excel.Application.DisplayAlert = falseExcel.Application.Quitforeach(System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses()) { if(p.ProcessName.ToUpper() == "EXCEL") { p.Kill(); } } 关于Excel的导入导出:我是这样导出Excel的。//导出到EXCEL的函数 public void ToExcel(System.Web.UI.Control ctl) { HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=Excel.txt"); HttpContext.Current.Response.Charset = "gb2312"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default; HttpContext.Current.Response.ContentType = "application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword // HttpContext.Current.Response.ContentType ="application/Microsoft Excel"; // ctl.Page.EnableViewState = false; System.IO.StringWriter tw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw); ctl.RenderControl(hw); HttpContext.Current.Response.Write(tw.ToString()); HttpContext.Current.Response.End(); ctl.Visible = false; }但是我用这种方法导出的EXCEL表不能导入。导入的方法: private void BindExcel(string Excel_File_Name) { string My_ExeclConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Excel_File_Name + ";" + "Extended Properties='Excel 8.0;HDR=YES;'" ; string My_ExeclComm_Str = "Select * From [Sheet2$]"; OleDbDataAdapter My_ExeclAdapter = new OleDbDataAdapter(My_ExeclComm_Str, My_ExeclConn); DataSet My_ExeclDataSet = new DataSet(); //Fill方法将数据从数据源复制到DataSet中 My_ExeclAdapter.Fill(My_ExeclDataSet); Excel_DataGrid.DataSource = My_ExeclDataSet; // Excel_DataGrid.DataMember = "Excel"; Excel_DataGrid.DataBind(); }请大侠救命,感激不尽。感激不尽答:用这个方法做出的Excel表是网页形式,是用MS—EXCEL强制打开的。本身是个网页。所以要打开这个。XLS文件,需要: C_Act Use_Act = new C_Act(); Excel.Application myExcel = new Excel.Application(); Object oMissing=System.Reflection.Missing.Value; Excel.Workbook Tw = myExcel.Application.Workbooks.Open(Excel_File_Name,oMissing,true,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing);独占的方式打开这个文件。直接导出 this.Page.Response.AddHeader("Content-Disposition", "attachment; filename=Client.xls"); this.Page.Response.Charset = "GB2312"; this.Page.Response.ContentEncoding =System.Text.Encoding.Default; this.Page.Response.ContentType = "application/vnd.ms-excel"; System.IO.StringWriter textstring = new System.IO.StringWriter(); HtmlTextWriter htmltext = new HtmlTextWriter(textstring); this.DataGrid1.RenderControl(htmltext); this.Page.Response.Write(textstring); this.Page.Response.End(); http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=6AFBF00B-459D-4642-AD14-8A4765FFAFCC 用ActiveX技术来操作Excel的一个最大的问题是有时就是关不了后台的Excel,我试了很多方法,有时能关有时不能关,很奇怪。你可以用ODBC来将数据写入Excel文件,而不用后台打开Excel,这样效率要高得多,而且不存在关不了进程的问题! 在C#中使用Excel,要先做一点准备工作,通过查找(前提是你安装Visual Studio.Net和Excel 2000),在你的计算机中找到TlbImp和Excel9.olb,将他们复制到一个文件夹中,在DOS窗口中执行 TlbImp Excel9.olb,这时会产生以下三个文件:Excel.dll、Office.dll和VBIDE.dll然后引用 //创建一个Excel文件 Excel.Application myExcel = new Excel.Application ( ) ; myExcel.Application.Workbooks.Add ( true ) ; //让Excel文件可见 myExcel.Visible=true; //第一行为报表名称 myExcel.Cells[1,4]="普通报表"; //逐行写入数据, for(int i=0;i<11;i++) { for(int j=0;j<7;j++) { //以单引号开头,表示该单元格为纯文本 myExcel.Cells[2+i,1+j]="'"+myData[i,j]; } } }myData是个数组 把你的数据放里面就行了 在Excel中单击“插入”——“名称”——“定义”,将你要插入数据的单元格定义为一个名称(包括标题行,标题行会自动作为字段名),然后你就可能用ODBC来访问它了。 求高人指点啊!公司网站 卡着不动 重启站点就好了,最近越来越卡 winform程序如何备份mysql数据库。 wcf能不能转换为wpf?怎么转换? 繼續問個C#操作INI文件 datalist应用ascx控件后台问题 请问,获得程序当前最靠前的窗口 为什么无法ref string 转换为 ref object 请问一下大家怎么在datagrid中移动行的光标,用函数 动软代码生成器生成的代码怎么去调用写在config里的数据库连接字符串 连Oracle数据库出错! 快来帮忙! C#支持多流文件吗? 100分!!关于做.net安装程序快捷方式问题!紧急!!!
Excel.Application.Quit
foreach(System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses())
{
if(p.ProcessName.ToUpper() == "EXCEL")
{
p.Kill();
}
}
//导出到EXCEL的函数
public void ToExcel(System.Web.UI.Control ctl)
{
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=Excel.txt");
HttpContext.Current.Response.Charset = "gb2312";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType = "application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
// HttpContext.Current.Response.ContentType ="application/Microsoft Excel";
// ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
ctl.Visible = false;
}
但是我用这种方法导出的EXCEL表不能导入。导入的方法:
private void BindExcel(string Excel_File_Name)
{
string My_ExeclConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Excel_File_Name + ";" +
"Extended Properties='Excel 8.0;HDR=YES;'" ;
string My_ExeclComm_Str = "Select * From [Sheet2$]";
OleDbDataAdapter My_ExeclAdapter = new OleDbDataAdapter(My_ExeclComm_Str, My_ExeclConn);
DataSet My_ExeclDataSet = new DataSet(); //Fill方法将数据从数据源复制到DataSet中
My_ExeclAdapter.Fill(My_ExeclDataSet);
Excel_DataGrid.DataSource = My_ExeclDataSet;
// Excel_DataGrid.DataMember = "Excel";
Excel_DataGrid.DataBind();
}
请大侠救命,感激不尽。感激不尽答:
用这个方法做出的Excel表是网页形式,是用MS—EXCEL强制打开的。本身是个网页。所以要打开这个。XLS文件,需要:
C_Act Use_Act = new C_Act();
Excel.Application myExcel = new Excel.Application();
Object oMissing=System.Reflection.Missing.Value;
Excel.Workbook Tw = myExcel.Application.Workbooks.Open(Excel_File_Name,oMissing,true,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing);独占的方式打开这个文件。直接导出
this.Page.Response.AddHeader("Content-Disposition", "attachment; filename=Client.xls");
this.Page.Response.Charset = "GB2312";
this.Page.Response.ContentEncoding =System.Text.Encoding.Default;
this.Page.Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter textstring = new System.IO.StringWriter();
HtmlTextWriter htmltext = new HtmlTextWriter(textstring);
this.DataGrid1.RenderControl(htmltext);
this.Page.Response.Write(textstring);
this.Page.Response.End();
然后引用
//创建一个Excel文件
Excel.Application myExcel = new Excel.Application ( ) ;
myExcel.Application.Workbooks.Add ( true ) ;
//让Excel文件可见
myExcel.Visible=true;
//第一行为报表名称
myExcel.Cells[1,4]="普通报表";
//逐行写入数据,
for(int i=0;i<11;i++)
{
for(int j=0;j<7;j++)
{
//以单引号开头,表示该单元格为纯文本
myExcel.Cells[2+i,1+j]="'"+myData[i,j];
}
} }
myData是个数组 把你的数据放里面就行了