求asp.net读取word内容代码

gs8716 gs8716 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
读取出内容是没有问题的,但是现在显示时全部连在一起,密密麻麻地,没有换行符等。
查看了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);
...全文

相关推荐

评论 27
收藏 已收藏
分享
返回顶部
gs8716
.NET社区 62,273 成员 668,968 内容