求asp.net读取word内容代码
读取出内容是没有问题的,但是现在显示时全部连在一起,密密麻麻地,没有换行符等。
查看了web页面的源代码,里面的文字格式和word里类似,虽没有换行符但是不是密密麻麻的,就像用了<pre>一样的。
怎么修改才能显示的和word一样的格式呢?
我的想法是读取时把word里的回车符换成<br/>标签,或者以html的格式读取出来。
下面是我的代码:(如果你的代码不能满足功能就不用麻烦你粘了)
Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Word.Document wordDoc = null; //wordApp.ActiveDocument;
Type docstype = wordApp.Documents.GetType();
object filename = Server.MapPath(@"aaa.doc");
wordDoc = (Word.Document)docstype.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, wordApp.Documents, new Object[] { filename, true, true });
object unkown = Type.Missing;
Object Nothing = System.Reflection.Missing.Value;
object format = Word.WdOpenFormat.wdOpenFormatDocument;
wordDoc = wordApp.Documents.Open(ref filename, ref unkown, ref unkown, ref unkown, ref unkown, ref unkown, ref unkown,
ref unkown, ref unkown, ref format, ref unkown, ref unkown, ref unkown,
ref unkown, ref unkown, ref unkown);
Response.Write(wordDoc.Content.Text.ToString());
wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
查看了web页面的源代码,里面的文字格式和word里类似,虽没有换行符但是不是密密麻麻的,就像用了<pre>一样的。
怎么修改才能显示的和word一样的格式呢?
我的想法是读取时把word里的回车符换成<br/>标签,或者以html的格式读取出来。
下面是我的代码:(如果你的代码不能满足功能就不用麻烦你粘了)
Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Word.Document wordDoc = null; //wordApp.ActiveDocument;
Type docstype = wordApp.Documents.GetType();
object filename = Server.MapPath(@"aaa.doc");
wordDoc = (Word.Document)docstype.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, wordApp.Documents, new Object[] { filename, true, true });
object unkown = Type.Missing;
Object Nothing = System.Reflection.Missing.Value;
object format = Word.WdOpenFormat.wdOpenFormatDocument;
wordDoc = wordApp.Documents.Open(ref filename, ref unkown, ref unkown, ref unkown, ref unkown, ref unkown, ref unkown,
ref unkown, ref unkown, ref format, ref unkown, ref unkown, ref unkown,
ref unkown, ref unkown, ref unkown);
Response.Write(wordDoc.Content.Text.ToString());
wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
...全文
相关推荐
ASP如何读取Word文档内容并显示于网页
一般而言 , 在 ASP 或 ASP.Net 中透过 CreateObject 建构函数建立 Word 对象 会有安全性及使用权限上的问题 , 因此若 虚拟目录 不使用 整合 Windows 验证 将无法存取 Word doc 檔 ,更不用说虚拟目录以外的目录
asp.net(c#).winform 读取word文档内容、创建新word文档
本程序可读取word文档内容、创建新word文档
asp.net 利用word模板导出word文件
asp.net 利用word模板导出word文件 实例
asp.net(c#)下读取word文档的方法小结
第一种方法: 代码如下: Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = “Application/msword”; string s=Server.MapPath(“C#语言参考.doc”); Response.WriteFile(“C#语言参考.doc”); Response.Write(s); Response.Flush(); Response.Close(); 第二种方法: 代码如下: Response.ClearContent(); Response.ClearHeaders()
C# ASP.NET - 将Web网页导出至Word文档
说明: 用C#实现“将Web网页导出至Word文档”^_^


