asp.net导出word问题

面向对象三大概念 2015-08-18 02:51:56
我在本机调试时可以导出的,发布之后就不能导出了。发布也是在我本机上面。出现下面错误


下面是我导出word的代码。我感觉跟代码应该没关系。上面要加的那些上面权限我都照网上的方法都加了。
try
{
//模板文件路径
string strFile = "/Content/Documents/abc.doc";
// 在此处放置用户代码以初始化页面
object Missing = Type.Missing;
//取得Word文件路径
string strTemp = strFile;
//新Word文件保存路径
string newFileName = "/Content/PrintWord/" + Guid.NewGuid().ToString() + "项目信息表.doc";
//创建一个名为WordApp的组件对象

Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
//必须设置为不可见
WordApp.Visible = false;
//创建以strTemp为模板的文档
object oTemplate = Server.MapPath(strTemp);
Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add(ref oTemplate, ref Missing, ref Missing, ref Missing);
WordDoc.Activate();
//对标签进行填充
foreach (Microsoft.Office.Interop.Word.Bookmark bm in WordDoc.Bookmarks)
{
for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
{
if (bm.Name == ds.Tables[0].Columns[i].ColumnName)
{
bm.Select();
bm.Range.Text = ds.Tables[0].Rows[0][ds.Tables[0].Columns[i].ColumnName].ToString();
}
}
}
////保存为新文件
object oNewFileName = Server.MapPath(newFileName);
WordDoc.SaveAs(ref oNewFileName, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing);
WordDoc.Close(ref Missing, ref Missing, ref Missing);
WordApp.Quit(ref Missing, ref Missing, ref Missing);
WordApp = null;
WordDoc = null;
result = newFileName;
// Response.Redirect(newFileName);
}
catch (Exception Ex)
{
result = Ex.ToString();
}
...全文
71 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
slwsss 2015-08-18
  • 打赏
  • 举报
回复
试下npoi

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧