å¯ä»¥æWordä¸çææ¬æ¿æ¢æå¾çå¢ï¼è¯è¯ä¸é¢ç代ç
//å®ä¾åDocumentç±»ç对象ï¼å¹¶å è½½æµè¯ææ¡£
Document doc = new Document();doc.LoadFromFile("testfile.docx");
//å è½½æ¿æ¢çå¾ç
Image image = Image.FromFile("g.png");
//è·å第ä¸ä¸ªsection
Section sec= doc.Sections[0];/
/æ¥æ¾ææ¡£ä¸çæå®ææ¬å
容
TextSelection[] selections = doc.FindAllString("Google", true, true);
int index = 0;
TextRange range = null;
//éåææ¡£ï¼ç§»é¤ææ¬å
容ï¼æå
¥å¾ç
foreach (TextSelection selection in selections){
DocPicture pic = new DocPicture(doc);
pic.LoadImage(image);
range = selection.GetAsOneRange();
index = range.OwnerParagraph.ChildObjects.IndexOf(range);
range.OwnerParagraph.ChildObjects.Insert(index, pic);
range.OwnerParagraph.ChildObjects.Remove(range);
}
//ä¿åææ¡£
doc.SaveToFile("result.docx", FileFormat.Docx);
åºèª ç½é¡µé¾æ¥