Using interop.word ranges

假装没事ソ 提交于 2019-12-25 18:12:15

问题


I'm having trouble figuring out how to work with word ranges. I have picture files that I am adding to a word file, but I can't figure out how to add text and tables in between the pictures. The structure I want is this: Text, table, picture. Then repeat.

However, when I add text or tables, they all area added after the four pictures, which stay at the top of the file. I've been reading and I've figured out I need to use ranges to specify where you want to place the tables/text, but all the resources I found only show how to add at the top of the page.

Tables: http://msdn.microsoft.com/en-us/library/w1702h4a.aspx Text: http://msdn.microsoft.com/en-us/library/6b9478cs.aspx

This is how I add pictures:

        Word.Application wdApp = new Word.Application();
        wdApp.Visible = true;

        Document doc = wdApp.Documents.Add();

        foreach (var category in type){
                // add table/text
                doc.Application.Selection.InlineShapes.AddPicture(@path + "\\" + category + "_" + DateTime.Now.ToString(datePatt) + ".jpg");
            }

I expected to be able to add my text/table before the picture, but it seems I have to specify ranges in the file. How can I do this?


回答1:


This is a possible duplicate of one of your previous questions: How to add items one at a time to to a new line a word document using word interop

See my previous answer to your similar question here: https://stackoverflow.com/a/12751805/700926 - it gives a short explanation of how to accomplish this as well as a complete sample implementation in C#.



来源:https://stackoverflow.com/questions/12715858/using-interop-word-ranges

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!