@Kaustubh Deshpande , Welcome to Microsoft Q&A, if you want to get information from docx file, I recommend that you could install nuget-packge Microsoft.Office.Interop.Word
to do it.
First, please add the using statement:
using Word = Microsoft.Office.Interop.Word;
Second, you could try the following code to read some content from docx file:
Word.Application app = new Word.Application();
object path = "test.docx";
Word.Document doc = app.Documents.Open(ref path);
foreach (Paragraph objParagraph in doc.Paragraphs)
{
Console.WriteLine(objParagraph.Range.Text);
}
Third, we could get the image from the docx file in winform app:
private Word.Application m_word;
private int m_i;
private void button1_Click(object sender, EventArgs e)
{
object missing = Type.Missing;
object FileName = "\test.docx";
object readOnly = true;
m_word = new Word.Application();
m_word.Documents.Open(ref FileName);
for (int i = 1; i <= m_word.ActiveDocument.InlineShapes.Count; i++)
{
m_i = i;
// CopyFromClipboardShape();
Thread thread = new Thread(CopyFromClipbordInlineShape);
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
}
}
protected void CopyFromClipbordInlineShape()
{
InlineShape inlineShape = m_word.ActiveDocument.InlineShapes[m_i];
inlineShape.Select();
m_word.Selection.Copy();
if (Clipboard.ContainsImage())
{
System.Windows.Forms.IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(System.Windows.Forms.DataFormats.Bitmap))
{
Image image = (Image)data.GetData(System.Windows.Forms.DataFormats.Bitmap, true);
image.Save("test.png");
}
else
{
MessageBox.Show("The Data In Clipboard is not as image format");
}
}
else
{
MessageBox.Show("The Clipboard was empty");
}
}
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.