原創|其它|編輯:郝浩|2011-10-24 16:00:11.000|閱讀 2317 次
概述:本文主要介紹C#使用Aspose.Words導出Word文檔中嵌入的對象,希望對大家有幫助。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
在C#中操作word,使用aspose.words這個控件是很方便的,也能用它來導出嵌入在word文檔中的OLE對象(gif,jpg,png,txt,html等內容)。
代碼如下
public void ExtractImg()
{
Document doc = new Document(@ "c:\test.doc");
//取得對象集合
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
int i = 0;
foreach (Shape shape in shapes)
{
if (shape.OleFormat != null)
{
//生成文件名
string name = @ "c:\obj_" + shape.OleFormat.ProgId + i.ToString();
//判斷OLE格式是否為Package(包)
if (shape.OleFormat.ProgId == "Package")
{
MemoryStream strm = new MemoryStream();
shape.OleFormat.Save(strm);
try
{
//保存圖片
Bitmap img = (Bitmap)Bitmap.FromStream(strm);
img.Save(name + ".png", ImageFormat.Png);
}
catch
{
Stream file = new FileStream(name + ".object", FileMode.Create);
strm.WriteTo(file);
}
}
i++;
}
}
}
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:網絡轉載