Example #1
0
        /// <summary>
        /// 添加尾注
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="str"></param>
        public void AddWeizhu(string filename, string str)
        {
            //获得数据库中str对应的来源
            string str_sql = $"select 来源 from {Setting._cijuchachongbiao} where 内容='{Hulue(str.Trim())}'";
            Dictionary <string, object> dic = mysqliter.ExecuteRow(str_sql, null, null)[0] as Dictionary <string, object>;
            string laiyuan = dic["来源"].ToString();

            Spire.Doc.Document mydoc = new Spire.Doc.Document();
            mydoc.LoadFromFile(filename);
            TextSelection[] texts = mydoc.FindAllString(str, false, true);
            if (texts == null)
            {
                return;
            }
            //给所有查找到的文字添加脚注
            foreach (TextSelection item in texts)
            {
                //实例化一个脚注的同时,直接创建在指定textselection所在的段落
                Spire.Doc.Fields.Footnote footnote = item.GetAsOneRange().OwnerParagraph.AppendFootnote(Spire.Doc.FootnoteType.Endnote);
                //向脚注内添加文字
                footnote.TextBody.AddParagraph().AppendText(laiyuan);
                //获得这个自然段
                Spire.Doc.Documents.Paragraph mypara = item.GetAsOneRange().OwnerParagraph;
                //向这个段落内的子节点添加脚注
                mypara.ChildObjects.Insert(mypara.ChildObjects.IndexOf(item.GetAsOneRange()) + 1, footnote);
            }
            mydoc.SaveToFile(filename);
            mydoc.Dispose();
            //去水印
            ClearShuiyin(filename);
        }
Example #2
0
        public void AddWeizhu(string filename, string str)
        {
            Dictionary <string, object> dic = new Dictionary <string, object> {
                { "内容", this.Hulue(str.Trim()) }
            };
            var    list = _sqlhelper.GetAnySet(Setting._cijuchachongbiao, dic);
            string text = list[0]["来源"].ToString();

            Spire.Doc.Document document = new Spire.Doc.Document();
            document.LoadFromFile(filename);
            TextSelection[] selectionArray = document.FindAllString(str, false, true);
            if (selectionArray != null)
            {
                TextSelection[] selectionArray2 = selectionArray;
                int             index           = 0;
                while (true)
                {
                    if (index >= selectionArray2.Length)
                    {
                        document.SaveToFile(filename);
                        document.Dispose();
                        this.ClearShuiyin(filename);
                        break;
                    }
                    TextSelection             selection = selectionArray2[index];
                    Spire.Doc.Fields.Footnote entity    = selection.GetAsOneRange().OwnerParagraph.AppendFootnote(Spire.Doc.FootnoteType.Endnote);
                    entity.TextBody.AddParagraph().AppendText(text);
                    Paragraph ownerParagraph = selection.GetAsOneRange().OwnerParagraph;
                    ownerParagraph.ChildObjects.Insert(ownerParagraph.ChildObjects.IndexOf(selection.GetAsOneRange()) + 1, entity);
                    index++;
                }
            }
        }