Aspone.Word导出字符串到书签

//在WORD文档中添加书签,以下代码自动保存到书签位置  
 protected void sbtnExportWord_Click(object sender, EventArgs e)
        {
            string strGoldSignPath = ConfigurationManager.AppSettings["GoldSignPath"];
            string Path = System.Web.HttpContext.Current.Server.MapPath("~/");
            Path += @"Template";
            string TemplatePath = Path + @"\项目开工通知单.doc";
            string seed = DateTime.Now.ToString("yyyyMMddHHmmss");
            string FilePath = Path + @"\" + seed + ".doc";
            Document doc = new Document(TemplatePath); //载入模板
            // 打开Word文件进行签名
            try
            {
                foreach (var label in new string[] { "EngineeringName", "EngineeringNumber", "EngneeringScaleID", "EngineeringPrType", "BuildCompany", "BuildPlace", "mutualitySpec", "EngEmpID", "SmartTextBox1", "SmartTextBox2", "ProjSyndicContent", "txtSystemContent", "ProductRequire", "ProgressRequire", "SmartTextBox3", "SmartTextBox4", "SmartTextBox5"/*, "stxtEdit", "stxtAuditor", "stxtSubdecanal"*/ ,"EngineeringJoinDepartments"})
                {
                    Bookmark mark = doc.Range.Bookmarks[label];
                    if (mark != null && label != "EngineeringJoinDepartments")
                        mark.Text = (this.FindControl(label) as SmartTextBox).Text;
                }
                // 签名
                int i = 1;
                foreach (var label in new string[] { "stxtEdit", "stxtAuditor", "stxtSubdecanal" })
                {
                    string[] strs = (this.FindControl(label) as SmartTextBox).Text.Split(' ');
                    string value = strs[0];
                    Bookmark mark = doc.Range.Bookmarks[label];
                    if (mark != null)
                    {
                        string signPicPath = string.Format(@"{0}{1}.png", strGoldSignPath, value);
                        if (File.Exists(signPicPath))
                        {
                            InsertPicByPath(doc, signPicPath, value, label, "");
                        }
                        Bookmark markd = doc.Range.Bookmarks["date" + i];
                        if (value != "")
                            markd.Text = strs[2];
                    }
                    i += 1;
                }
            }
            catch
            {
            }
            finally
            {
                //doc.Save(FilePath);
                Aspose.Words.Saving.DocSaveOptions docoptions = new Aspose.Words.Saving.DocSaveOptions(SaveFormat.Doc);
                doc.Save(HttpContext.Current.Response, "项目开工通知单.doc", Aspose.Words.ContentDisposition.Attachment, docoptions);
            }
        }

        //签图片
private static void InsertPicByPath(Aspose.Words.Document doc, string Path, string EmpName, string type, string info, int bit = 0)
        {
            Aspose.Words.DocumentBuilder builder;
            builder = new Aspose.Words.DocumentBuilder(doc);
            string path = Path;
            if (path != "" && File.Exists(path))
            {

                Aspose.Words.Drawing.Shape shape = new Aspose.Words.Drawing.Shape(doc, Aspose.Words.Drawing.ShapeType.Image);
                shape.ImageData.SetImage(path);
                shape.Width = 40;
                shape.Height = 20;
                CompositeNode node = shape.ParentNode;
                builder.MoveToBookmark(type);
                builder.InsertNode(shape);
            }
            else
            {
                //builder = new Aspose.Words.DocumentBuilder(doc);
                builder.MoveToBookmark(type);
                builder.Write(EmpName);
            }


            if (bit == 0)
            {
                builder = new Aspose.Words.DocumentBuilder(doc);
                builder.MoveToBookmark(type + "Info");
                builder.Write(info);
            }

        }




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值