Spire.Doc系列教程(4):在Word中插入和删除文本框

插入文本框

//加载Word文档Document document = new Document();document.LoadFromFile(@"测试文档.docx");//添加一个段落到第一个section并添加文本框到该段落TextBox textBox = document.Sections[0].AddParagraph().AppendTextBox(150, 30);//设置文本框格式textBox.Format.HorizontalAlignment = ShapeHorizontalAlignment.Left;textBox.Format.LineColor = Color.White;textBox.Format.LineStyle = TextBoxLineStyle.Simple;textBox.Format.FillColor = Color.ForestGreen;//在文本框中添加一个段落,并给段落添加文本Paragraph para = textBox.Body.AddParagraph();TextRange textRange = para.AppendText("文本框");//设置文本格式textRange.CharacterFormat.FontName = "Century Gothic";textRange.CharacterFormat.FontSize = 20;textRange.CharacterFormat.TextColor = Color.White;para.Format.HorizontalAlignment = HorizontalAlignment.Center;//保存文档document.SaveToFile("添加文本框.docx", FileFormat.Docx);

Spire.Doc

删除文本框

//加载文档Document document = new Document();document.LoadFromFile(@"添加文本框.docx");//删除文档中第一个文本框document.TextBoxes.RemoveAt(0);//删除所有文本框//document.TextBoxes.Clear();//保存文档document.SaveToFile("删除文本框.docx", FileFormat.Docx);

Spire.Doc

 

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2018年6月27日
下一篇 2018年6月27日

相关推荐

发表回复

登录后才能评论