我最近在弄一个能导出word的一个小网站,在VS上运行没事,但是发布到iis上之后发现一个问题,导出按钮点了之后没反应,就像空按钮事件,刷新了一遍页面。不知道为什么,然后就在代码里弹框,看进了方法没有。后来证明进方法了,部分代码如下,高手们,帮看看啊,急!谢谢!是iis需要配置什么吗?
Object Nothing = System.Reflection.Missing.Value;
object filename = Filename;// "C://CNSI//" + name; //文件保存路径程序走到下面这里不走的
//创建Word文档
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
//添加页眉
WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;
WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;
WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("[项目管理]");
WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;//设置右对齐
WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;//跳出页眉设置WordApp.Selection.ParagraphFormat.LineSpacing = 15f;//设置文档的行间距
Object Nothing = System.Reflection.Missing.Value;
object filename = Filename;// "C://CNSI//" + name; //文件保存路径程序走到下面这里不走的
//创建Word文档
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
//添加页眉
WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;
WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;
WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("[项目管理]");
WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;//设置右对齐
WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;//跳出页眉设置WordApp.Selection.ParagraphFormat.LineSpacing = 15f;//设置文档的行间距
服务器有装对应版本的office和pia没
try
网站属性>http头>新建一个MIME类型
.doc
application/msword
安装一下Office的相关组件
估计有可能是DCOM组件权限的问题。
具体可参考下面的:
http://hi.baidu.com/oldog/blog/item/3799cbfc7a4449fdfd037f72.html