日期:2014-05-18  浏览次数:20960 次

读取word文档
各位大哥请看:

我有一个word文档,里面可能有图片。

需求:1,如何读取整个word文档,包括图片
2,读取之后放在什么控件里面显示呢(图片也能显示)?


------解决方案--------------------
这个...我也想知道
------解决方案--------------------
我也想知道,标记一下

------解决方案--------------------
实现的思路是先在内存中把这个word文档打开,然后把里面的内容全部拷贝的剪切板中,最后再把数据从剪切板里面取出来.
代码如下:
Word.ApplicationClass wordApp=new ApplicationClass();
object file=path;
object nullobj=System.Reflection.Missing.Value;
Word.Document doc = wordApp.Documents.Open(
ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data=Clipboard.GetDataObject();
txtFileContent.Text=data.GetData(DataFormats.Text).ToString();
doc.Close();

-------------
参考 
只要内容能读出来 显示用什么都取出数据来
------解决方案--------------------
http://topic.csdn.net/t/20040102/11/2625860.html

-------
参考 以备后用
------解决方案--------------------
用这个Aspose.Words.dll
http://download.csdn.net/detail/newxdlysk/4210120
里面有chm帮助文档
贴个例子
C# code

DocumentBuilder builder = new DocumentBuilder();

string imageFileName = MyDir + "Hammer.wmf";

builder.Write("Image linked, not stored in the document: ");

Shape linkedOnly = new Shape(builder.Document, ShapeType.Image);
linkedOnly.WrapType = WrapType.Inline;
linkedOnly.ImageData.SourceFullName = imageFileName;

builder.InsertNode(linkedOnly);
builder.Writeln();


builder.Write("Image linked and stored in the document: ");

Shape linkedAndStored = new Shape(builder.Document, ShapeType.Image);
linkedAndStored.WrapType = WrapType.Inline;
linkedAndStored.ImageData.SourceFullName = imageFileName;
linkedAndStored.ImageData.SetImage(imageFileName);

builder.InsertNode(linkedAndStored);
builder.Writeln();


builder.Write("Image stored in the document, but not linked: ");

Shape stored = new Shape(builder.Document, ShapeType.Image);
stored.WrapType = WrapType.Inline;
stored.ImageData.SetImage(imageFileName);

builder.InsertNode(stored);
builder.Writeln();

builder.Document.Save(MyDir + "Image.CreateLinkedImage Out.doc");
[Visual Basic]

Dim builder As DocumentBuilder = New DocumentBuilder()

Dim imageFileName As String = MyDir & "Hammer.wmf"

builder.Write("Image linked, not stored in the document: ")

Dim linkedOnly As Shape = New Shape(builder.Document, ShapeType.Image)
linkedOnly.WrapType = WrapType.Inline
linkedOnly.ImageData.SourceFullName = imageFileName

builder.InsertNode(linkedOnly)
builder.Writeln()


builder.Write("Image linked and stored in the document: ")

Dim linkedAndStored As Shape = New Shape(builder.Document, ShapeType.Image)
linkedAndStored.WrapType = WrapType.Inline
linkedAndStored.ImageData.SourceFullName = imageFileName
linkedAndStored.ImageData.SetImage(imageFileName)

builder.InsertNode(linkedAndStored)
builder.Writeln()


builder.Write("Image stored in the document, but not linked: ")

Dim stored As Shape = New Shape(builder.Document, ShapeType.Image)
stored.WrapType = WrapType.Inline
stored.ImageData.SetImage(imageFileName)

builder.InsertNode(stored)
builder.Writeln()

builder.Document.Save(MyDir & "Image.CreateLinkedImage Out.doc")

------解决方案--------------------
C# code

Document doc = new Document(MyDir + "Image.SampleImages.doc");

    NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true, false);
    int imageIndex = 0;            
    foreach (Shape shape in sha