介绍
这篇文章主要介绍“Java怎么删除词的内容”,在日常操作中,相信很多人在Java怎么删除词的内容问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答“Java怎么删除词的内容”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
<强>使用工具:强>免费的尖顶。Java文档(免费版),可通过官网下载Jar包,并解压将自由文件夹下的Jar文件导入Java程序,也可以通过Maven仓库下载导入。如下导入效果:
<强> 1。强> <强>删除表格强>
<>之前,import com.spire.doc。*; ,import com.spire.doc.interfaces.ITable; , ,public class RemoveTable  { ,,,,public static void main (String [], args), { ,,,,,,,,//创建实例 ,,,,,,,,Document doc =, new 文档(); ,,,,,,,,//加载词文档 ,,,,,,,,doc.loadFromFile (“test.docx"); , ,,,,,,,,//获取部分 ,,,,,,,,Section Section =, doc.getSections () . get (0); , ,,,,,,,,//获取表格 ,,,,,,,,ITable table =, section.getTables () . get (0); , ,,,,,,,,//删除表格 ,,,,,,,,section.getTables () .remove(表); , ,,,,,,,,//保存文档 ,,,,,,,,doc.saveToFile (“RemoveTable.docx" FileFormat.Docx_2013); ,,,,,,,,doc.dispose (); ,,,,} 以前,}>表格删除前后效果:
<强> 2。强> <强>删除表格内容强>
<>之前,import com.spire.doc。*; ,public class RemoveTableContent  { ,,,,public static void main (String [], args), { ,,,,,,,,//创建实例,加载测试文档 ,,,,,,,,Document doc =, new 文档(); ,,,,,,,,doc.loadFromFile (“test.docx"); ,,,,,,,, ,,,,,,,,//获取部分 ,,,,,,,,Section Section =, doc.getSections () . get (0); , ,,,,,,,,//获取表格 ,,,,,,,,Table Table =section.getTables () . get (0),,, ,,,,,,,,//遍历表格每行 ,,,,,,,,for (int 小姐:=,0;,小姐:& lt;, table.getRows () .getCount();,我+ +),{ ,,,,,,,,,,,,//获取表格行 ,,,,,,,,,,,,TableRow row =, table.getRows () . get(我); ,,,,,,,,,,,,//遍历每行中的每个单元格 ,,,,,,,,,,,,,,(int j =, 0;, j & lt;, row.getCells () .getCount (); j + +) ,,,,,,,,,,,,,{ ,,,,,,,,,,,,,,,,,//获取单元格 ,,,,,,,,,,,,,,,,,TableCell cell =,, row.getCells () . get (j); ,,,,,,,,,,,,,,,,,cell.getChildObjects () .clear();//清除所有子对象 ,,,,,,,,,,,,,,,,,//cell.getCellFormat () .clearFormatting();//清除单元格格式 ,,,,,,,,,,,,,,,,,//cell.getParagraphs () .removeAt(0);//删除单元格中的段落 ,,,,,,,,,,,,,} ,,,,,,,,} ,,,,,,,,//保存文档 ,,,,,,,,doc.saveToFile (“RemoveContent.docx" FileFormat.Docx_2013); ,,,,,,,,doc.dispose (); ,,,,} null