本文概述
- Apache POI重写示例
Apache POI重写示例
package poiexample;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
public class RewritingExample {
public static void main(String[] args) throws FileNotFoundException, IOException, EncryptedDocumentException, InvalidFormatException {
try (InputStream inp = new FileInputStream("srcmini.xls")) {
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(2);
Cell cell = row.getCell(3);
if (cell == null)
cell = row.createCell(3);
cell.setCellType(CellType.STRING);
cell.setCellValue("101");
try (OutputStream fileOut = new FileOutputStream("srcmini.xls")) {
wb.write(fileOut);
}
}catch(Exception e) {
System.out.println(e);
}
}
}
输出:
文章图片
【apache poi重写】之后在202处重写102。
文章图片
推荐阅读
- apache poi样式化形状
- apache poi读取单元内容
- apache poi移位行
- apache poi页码
- apache poi概述
- apache poi单元格中的换行
- apache poi excel图片
- apache poi绘制形状
- apache poi excel单元格类型