怎样读取word文件?

hantao2000 2003-09-23 11:09:31
怎样读取word文件?
...全文
23 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
雪狼1234567 2003-09-23
  • 打赏
  • 举报
回复
Word.ApplicationClass WordApp = new Word.ApplicationClass();
object missing = System.Reflection.Missing.Value;
object fileName = "normal.dot"; // template file name
object newTemplate = false;

object docType = 0;
object isVisible = true;

// Create a new Document, by calling the Add function in the Documents collection

Word.Document aDoc = WordApp.Documents.Add(ref fileName, ref newTemplate, ref docType,
ref isVisible);

WordApp.Visible = true;
aDoc.Activate();
WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;

// Toggle the title to a Bold Font
WordApp.Selection.Font.Bold = (int)Word.WdConstants.wdToggle;

WordApp.Selection.TypeText(listView1.Items[0].Text);

完整代码到这里看:
http://www.c-sharpcorner.com/Code/2002/Mar/WordFromDotNet.asp
雪狼1234567 2003-09-23
  • 打赏
  • 举报
回复
这里有个例子
假如word文件保存在"D:\mydoc.doc"
用这个语句就可以打开word文件:response.redirect("D:\mydoc.doc")

或者用这个 Response.Write("<s" & "cript language=JavaScript> window.open('D:\mydoc.doc','','status=yes,location=yes,toolbar=yes,resizable=yes,directories=yes,menubar=yes')</scrip" & "t>")


需要
Microsoft.Office.Interop.Word.dll
Office.dll

Application app = new Application();
object template=Missing.Value;
object newTemplate=Missing.Value;
object documentType=Missing.Value;
object visible=true;
_Document doc = app.Documents.Add( ref template,ref newTemplate,ref documentType,ref visible);
chinchy 2003-09-23
  • 打赏
  • 举报
回复
http://www.c-sharpcorner.com/Code/2002/Mar/WordFromDotNet.asp
jiezhi 2003-09-23
  • 打赏
  • 举报
回复
http://www.microsoft.com/china/msdn/library/dnexcl2k2/html/odc_offcs.asp

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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