I have been trying the following C# code to extract image from the doc file but it is not working:
object missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document oDoc = new Microsoft.Office.Interop.Word.Document();
oWord.Visible = false;
object str1 = "C:\doc.doc";
oDoc = oWord.Documents.Open(ref str1, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
if (oDoc.InlineShapes.Count > 0) {
for (int j = 0; j < oDoc.InlineShapes.Count; j++)
{
oWord.ActiveDocument.Select();
oDoc.ActiveWindow.Selection.CopyAsPicture();
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(typeof(System.Drawing.Bitmap)))
{
object bm = data.GetData(DataFormats.Bitmap);
Bitmap bmp;
bmp = (Bitmap)data.GetData(typeof(System.Drawing.Bitmap));
bmp.Save("C:\test.bmp");
}
}
Can anybody give the proper code for extracting the image from word file?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…