| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 984 人关注过本帖
标题:asp.net导出图片到word如何定位图片的位置。
只看楼主 加入收藏
wmglh001
Rank: 1
等 级:新手上路
帖 子:2
专家分:4
注 册:2012-3-8
收藏
 问题点数:0 回复次数:0 
asp.net导出图片到word如何定位图片的位置。
程序代码:

        private void SaveImageToWord()
        {
            Application wordApp = new Application();
            Document wordDoc;
            string strContent = Editor1.Text;           // 要生成word的内容
            object strFileName = System.Web.HttpContext.Current.Server.MapPath("~/App_UpLoad/20120703");            // 保存文件路径
            object fileName = System.Web.HttpContext.Current.Server.MapPath("~/App_UpLoad/SXFSZ-NEW-TZMB.dot");     // 模板路径
            Object oMissing = System.Reflection.Missing.Value;
            wordDoc = wordApp.Documents.Add(ref fileName, ref oMissing, ref oMissing, ref oMissing);                // 获取word对象
            wordDoc.Activate();
            object unith;
            foreach (Bookmark bm in wordDoc.Bookmarks)
            {
                if (bm.Name == "通知_Content")
                {
                    bm.Select();                // 将光标移到当前标签内
                    Selection currentSelection = wordApp.Selection;         // 获取当前光标的位置
                    if (Regex.IsMatch(strContent, @"<img[^>]*>"))
                    {
                        string[] matches = Regex.Split(strContent, @"(<img[^>]*>)");
                        foreach (string ma in matches)
                        {
                            if (Regex.IsMatch(ma, @"<img[^>]*>"))
                            {
                                Match match = Regex.Match(ma, @"src=.*");
                                string ss = match.Value.Replace("src=\"/", "").Replace("\" />", "");
                                string imgPath = System.Web.HttpContext.Current.Server.MapPath(ss);//图片所在路径
                                object LinkToFile = false;
                                object SaveWithDocument = true;
                                object Anchor = wordDoc.ActiveWindow.Selection.Range;
                                InlineShape li = currentSelection.InlineShapes.AddPicture(imgPath, ref LinkToFile, ref SaveWithDocument, ref Anchor);

                                Shape shape = li.ConvertToShape();
                                shape.WrapFormat.Type = WdWrapType.wdWrapSquare;
                            }
                            else
                            {
                                currentSelection.TypeText(ma);
                            }
                        }
                    }
                    else
                    {
                        currentSelection.TypeText(strContent);
                    }
                }
            }
            //将WordDoc文档对象的内容保存为DOC文档   
            wordDoc.SaveAs(ref strFileName, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing);
            //关闭WordDoc文档对象   
            wordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
        }
搜索更多相关主题的帖子: 图片 color 如何 
2012-07-04 10:35
快速回复:asp.net导出图片到word如何定位图片的位置。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017700 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved