轉帖|使用教程|編輯:黃竹雯|2019-04-28 09:30:46.000|閱讀 554 次
概述:題注是指對象下方(或上方)的一行簡短文字,用于描述該對象。在Word中使用題注功能可以保證文檔中圖片、表格或圖表等項目能夠有序地自動編號。如果移動、插入或刪除帶題注的項目時,Word 可以自動更新。本文將詳細介紹如何使用Spire.Doc來添加和刪除題注。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
題注是指對象下方(或上方)的一行簡短文字,用于描述該對象。在Word中使用題注功能可以保證文檔中圖片、表格或圖表等項目能夠有序地自動編號。如果移動、插入或刪除帶題注的項目時,Word 可以自動更新。本文將詳細介紹如何使用Spire.Doc來添加和刪除題注。
代碼如下:
//實例化Document對象
Document document = new Document();
//添加一個Section
Section s = document.AddSection();
//添加一個段落并在其中添加圖片
Paragraph par1 = s.AddParagraph();
par1.Format.AfterSpacing = 10;
DocPicture pic1 = par1.AppendPicture(Image.FromFile(@"logo1.png"));
pic1.Height = 100;
pic1.Width = 120;
//在圖片上添加題注
CaptionNumberingFormat format = CaptionNumberingFormat.Number;
pic1.AddCaption("Spire.Doc Logo_插 圖", format, CaptionPosition.AfterImage);
//另加一個段落進行同樣的操作
Paragraph par2 = s.AddParagraph();
DocPicture pic2 = par2.AppendPicture(Image.FromFile(@"logo2.png"));
pic2.Height = 100;
pic2.Width = 120;
pic2.AddCaption("Spire.Doc Logo_插 圖", format, CaptionPosition.AfterImage);
//更新域并保存文檔
document.IsUpdateFields = true;
document.SaveToFile("caption.docx", FileFormat.Docx);結果如圖:

代碼如下:
//加載剛才的結果文檔
Document doc = new Document();
doc.LoadFromFile("caption.docx");
//查找然后獲取第一個題注
TextSelection[] slcs = doc.FindAllString("Spire.Doc Logo_插 圖", true, true);
TextRange tr=slcs[0].GetAsOneRange();
Paragraph para= tr.OwnerParagraph;
//刪除其所在的段落
doc.Sections[0].Paragraphs.Remove(para);
//更新域, 發現第二張插圖的序號現在更新為1了
doc.IsUpdateFields = true;
doc.SaveToFile("deleteCaption.docx",FileFormat.Docx2010);結果如圖:

想看冰藍更多產品教程嗎?為你推薦:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn