新聞中心
這篇文章主要介紹“Java怎么刪除Word的內(nèi)容”,在日常操作中,相信很多人在Java怎么刪除Word的內(nèi)容問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Java怎么刪除Word的內(nèi)容”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
為路北等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及路北網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為做網(wǎng)站、成都做網(wǎng)站、路北網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
使用工具:Free Spire.Doc for Java(免費版),可通過官網(wǎng)下載Jar包,并解壓將lib文件夾下的jar文件導(dǎo)入Java程序;也可以通過Maven倉庫下載導(dǎo)入。如下導(dǎo)入效果:
1.刪除表格
import com.spire.doc.*; import com.spire.doc.interfaces.ITable; public class RemoveTable { public static void main(String[] args) { //創(chuàng)建實例 Document doc = new Document(); //加載Word文檔 doc.loadFromFile("test.docx"); //獲取Section Section section = doc.getSections().get(0); //獲取表格 ITable table = section.getTables().get(0); //刪除表格 section.getTables().remove(table); //保存文檔 doc.saveToFile("RemoveTable.docx",FileFormat.Docx_2013); doc.dispose(); } }
表格刪除前后效果:
2.刪除表格內(nèi)容
import com.spire.doc.*; public class RemoveTableContent { public static void main(String[] args) { //創(chuàng)建實例,加載測試文檔 Document doc = new Document(); doc.loadFromFile("test.docx"); //獲取Section Section section = doc.getSections().get(0); //獲取表格 Table table =section.getTables().get(0); //遍歷表格每行 for (int i = 0; i < table.getRows().getCount(); i++) { //獲取表格行 TableRow row = table.getRows().get(i); //遍歷每行中的每個單元格 for(int j = 0; j < 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(); } }
表格內(nèi)容刪除前后效果:
到此,關(guān)于“Java怎么刪除Word的內(nèi)容”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
新聞標(biāo)題:Java怎么刪除Word的內(nèi)容
地址分享:http://www.ef60e0e.cn/article/igscci.html