如何在c#.net中使用Interop.Word在word文档中插入多个图像 [英] How to insert multiple image in word document using Interop.Word in c#.net

查看:745
本文介绍了如何在c#.net中使用Interop.Word在word文档中插入多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要插入Word文档的数据列表。我使用Microsoft Word Object Library dll在Word文档中插入数据。我的数据看起来像第一列是图像,其他列是名称,地址等。一条记录应该只显示在创建文档中的一个页面。当我使用下面的代码在word文档中插入数据时,所有图像首先显示然后显示其他数据。但我需要显示记录明智的数据,如图像,名称,地址等...



我的C#代码是:



I have a list of data to insert in Word document.I am using Microsoft Word Object Library dll for data insert in Word document.my data look like first column is image and other column is name,address etc..One record should be display in only one page in created document.when I insert data in word document using below code at that time all image display first and then other data display .But I need to display record wise data look like image,name,address etc...

My C# code is :

//Get report Data list

        List<Art> ListData = oArts.LoadListData();

        Paragraph para = document.Content.Paragraphs.Add(ref missing);
        para.Range.InsertParagraphBefore();

        string imgPath;

        for (int i = 0; i < ListData.Count; i++)
        {
           string path = Server.MapPath("~/ArtImages/") + ListData[i].ArtID;
           imgPath = path + @"\" + ListData[i].ImageMaster.ImagePath;

           InlineShape map = document.InlineShapes.AddPicture(imgPath, ref missing, ref missing, ref missing);
           map.Height = 350;
           map.Width = 350;

          para.Range.Text = "Name : " + ListData[i].Name + Environment.NewLine;
          para.Range.Text = "Address : " + ListData[i].Address + Environment.NewLine;
          para.Range.InsertParagraphAfter();
          object oPageBreak = Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
          para.Range.InsertBreak(ref oPageBreak);

        }

        //Save the document

        object filename = "@C:\\ArtDetails.doc";
        document.Close(ref missing, ref missing, ref missing);
        document = null;
        winword.Quit(ref missing, ref missing, ref missing);
        winword = null;

推荐答案

这篇关于如何在c#.net中使用Interop.Word在word文档中插入多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆