怎样用Java、POI技术来读取Word文档,并把Word文档的原来格式完...
修改完需要写入,也就是保存一下的。
import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import org.apache.poi.hssf.usermodel.HSSFCell;import org.apache.poi.hssf.usermodel.HSSFRow;import org.apache.poi.hssf.usermodel.HSSFSheet;import org.apache.poi.hssf.usermodel.HSSFWorkbook;public class ChangeCell { @SuppressWarnings("deprecation") public static void main(String[] args) { String fileToBeRead = "C:\\exp.xls"; // excel位置 int coloum = 1; // 比如你要获取第1列 try { HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream( fileToBeRead)); HSSFSheet sheet = workbook.getSheet("Sheet1"); for (int i = 0; i HSSFRow row = sheet.getRow((short) i); if (null == row) { continue; } else { HSSFCell cell = row.getCell((short) coloum); if (null == cell) { continue; } else { System.out.println(cell.getNumericCellValue()); int temp = (int) cell.getNumericCellValue(); cell.setCellValue(temp + 1); } } } FileOutputStream out = null; try { out = new FileOutputStream(fileToBeRead); workbook.write(out); } catch (IOException e) { e.printStackTrace(); } finally { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }}
java poi 操作excel 问题
晚上来看一下。
---------------------------------------import java.io.ByteArrayInputStream;import java.io.FileInputStream;import java.io.FileOutputStream;import org.apache.poi.hwpf.extractor.WordExtractor;import org.apache.poi.poifs.filesystem.DirectoryEntry;import org.apache.poi.poifs.filesystem.DocumentEntry;import org.apache.poi.poifs.filesystem.POIFSFileSystem;public class Word {public static void main(String[] args) throws Exception {WordExtractor doc = new WordExtractor(new FileInputStream("D:\\word01.doc"));// 提取.doc正文文本String text = doc.getText();// 提取.doc批注String[] comments = doc.getCommentsText();System.out.println(text);ByteArrayInputStream bais = new ByteArrayInputStream(text.getBytes());POIFSFileSystem fs = new POIFSFileSystem();DirectoryEntry directory = fs.getRoot();DocumentEntry de = directory.createDocument("WordDocument", bais);FileOutputStream ostream = new FileOutputStream("D:\\word02.doc");fs.writeFilesystem(ostream);}}
如何提取word里的批注
工具/原料word方法/步骤1、首先打开已加入批注的文档。
2、点击文件-另存为--计算机-浏览。
4、输入保存名称,类型为网页,然后保存。
5、打开网页后,发现横线下方为批注,直接复制即可。
转载请注明出处51数据库 » poi获取word的批注
亖呉?盀