C# asp.net Word中使用書籤插入圖片匯出

來源:互聯網
上載者:User

#region 擷取到各使用者的簽名圖片,並且插入到我惹的中
                    string strUser = string.Empty;
                    ArrayList lstUser = new ArrayList();
                    for (int i = 0; i < users.Length; i++)
                    {
                        strUser = users[i];
                        if (strUser != null)
                        {
                            lstUser = BusinessFacade.sys_UserListByUCName(strUser);
                            if (lstUser == null)
                                usersMark[i] = string.Empty;
                            else
                            {
                                for (int ii = 0; ii < lstUser.Count; ii++)
                                {
                                    sys_UserTable st = lstUser[ii] as sys_UserTable;
                                    usersMark[i] += st.U_Mark + ",";
                                }
                            }
                        }
                    }

                    //首先在word模版中加入對應的書籤,//以下代碼使用書籤插入圖片確認圖片位置
                    //使用者書籤名稱  
                    string[] bk = { "analyzer", "corrector", "verifier" };
                    //使用者圖片根目錄
                    string basePic = HttpContext.Current.Server.MapPath("~/public/usermark/");

                    foreach (Word.Bookmark bm in doc.Bookmarks)
                    {
                        for (int i = 0; i < bk.Length; i++)
                        {
                            if (bm.Name.ToLower() == bk[i].ToLower())
                            {
                                bm.Select();
                                if (usersMark[i].EndsWith(","))
                                    usersMark[i] = usersMark[i].Substring(0, usersMark[i].Length - 1);

                                string[] pic = usersMark[i].Split(',');
                                for (int ii = 0; ii < pic.Length; ii++)
                                {
                                    //--判斷logo圖片是否存在·不存在則略過插入。
                                    if (File.Exists(basePic + pic[ii]))
                                    {
                                        //要插入的圖片檔案
                                        app.Selection.InlineShapes.AddPicture(basePic + pic[ii], ref oMissing, ref oMissing, ref oMissing);
                                    }
                                    //doc.Application.ActiveDocument.InlineShapes[1].Width = 100f; // 圖片寬度

                                    //doc.Application.ActiveDocument.InlineShapes[1].Height = 8f; // 圖片高度
                                } break;
                            }
                        }
                    }
                    #endregion

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.