質問

I have a code to add inline images to word. Now if I want to add a line between them what shall I do ?

var WordApp = new Microsoft.Office.Interop.Word.Application();         
WordApp.Documents.Add();
WordApp.Visible = true;         
Microsoft.Office.Interop.Word.Document doc = WordApp.ActiveDocument;
doc.InlineShapes.AddPicture("c:\\mypic1.jpeg");
doc.InlineShapes.AddPicture("c:\\20140203_202325.jpg");            
doc.SaveAs2("C:\\MyDocument.doc");            
WordApp.Quit(Type.Missing, Type.Missing, Type.Missing);

I tried with the following line , but that dint help..

WordApp.Selection.InsertAfter("\r\nThis is some random text");

What shall be the one to place a line between them ?

役に立ちましたか?

解決

Use this piece of code :

That would add the image and then a line to it.

        object StartPos = 0;
        object Endpos = 1;
        Microsoft.Office.Interop.Word.Range rng = doc.Range(ref StartPos, ref Endpos);
        object NewEndPos = rng.StoryLength - 1;
        rng = doc.Range(ref NewEndPos, ref NewEndPos);
        rng.Select();

        var pText = doc.Paragraphs.Add();
        pText.Format.SpaceAfter = 10f;
        pText.Range.Text = String.Format("This is line");
        pText.Range.InsertParagraphAfter();

        object StartPos1 = 0;
        object Endpos1 = 1;
        Microsoft.Office.Interop.Word.Range rng1 = doc.Range(ref StartPos1, ref Endpos1);
        object NewEndPos1 = rng.StoryLength - 1;
        rng1 = doc.Range(ref NewEndPos, ref NewEndPos);
        rng1.Select();
        doc.InlineShapes.AddPicture(loc +@"\" + dt + ".jpeg");

I hope this would help.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top