新人提問 我想用.ne.net生成excel.首先判断目录下是否存在excel文件, 有就将他删掉.可debug后说access is denied .我认为是权限问题,但更改后无效.请高手指点 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是否存在excel文件?文件夹是否存在,还有删除的代码帖出来看看 权限问题吧.还是你那个excel正在打开? 检查是否有其他进程打开了这个Excel文件。 private void MakeExcel(DataTable Show_Table) { if(File.Exists(Server.MapPath(".")+"\\Result.xls")) { File.Delete(Server.MapPath(".")+"\\Result.xls"); } try { OWC.SpreadsheetClass xSheet = new OWC.SpreadsheetClass(); int i = 1; foreach (DataColumn DGItem in Show_Table.Columns ) { xSheet.ActiveSheet.Cells[1,i] = DGItem.ColumnName; i++; } for (int irow=0;irow<Show_Table.Rows.Count;irow++) { for(int icolumn=0;icolumn<Show_Table.Columns.Count;icolumn++) { xSheet.ActiveSheet.Cells[irow+2,icolumn+1]=Show_Table.Rows[irow][icolumn].ToString(); } } xSheet.ActiveSheet.Export(Server.MapPath(".")+"\\Result.xls",OWC.SheetExportActionEnum.ssExportActionNone); } catch(Exception ex) { Response.Write("<Script language=javascript>alert('" + ex.Message +"error')"); } finally { } } C#连接excel2007问题 一个gridview 怎样把数据设置为自己的sql语句?先感谢前辈了! 一个关于传递值显示的问题 winform中如何实现QQ好友信息弹出框? winform在网上邻居里运行 如何让C#写的应用程序最小化时显示在右下角的任务栏中?就像金山词霸那样。 名称空间的问题简单 关于增加C#独立编译,C#程序员都来顶,技术讨论 如何实现一行打印?? 请CForce进来拿分 加密SQL连接语句后,再解密后为什么不能用? 单引号问题
文件夹是否存在,还有删除的代码帖出来看看
还是你那个excel正在打开?
{
if(File.Exists(Server.MapPath(".")+"\\Result.xls"))
{
File.Delete(Server.MapPath(".")+"\\Result.xls");
}
try
{
OWC.SpreadsheetClass xSheet = new OWC.SpreadsheetClass();
int i = 1;
foreach (DataColumn DGItem in Show_Table.Columns )
{
xSheet.ActiveSheet.Cells[1,i] = DGItem.ColumnName;
i++;
}
for (int irow=0;irow<Show_Table.Rows.Count;irow++)
{
for(int icolumn=0;icolumn<Show_Table.Columns.Count;icolumn++)
{
xSheet.ActiveSheet.Cells[irow+2,icolumn+1]=Show_Table.Rows[irow][icolumn].ToString();
}
}
xSheet.ActiveSheet.Export(Server.MapPath(".")+"\\Result.xls",OWC.SheetExportActionEnum.ssExportActionNone);
}
catch(Exception ex)
{
Response.Write("<Script language=javascript>alert('" + ex.Message +"error')");
}
finally
{
}
}