Java excel poi 读取已有文件 ,动态插入一列数据
生活随笔
收集整理的這篇文章主要介紹了
Java excel poi 读取已有文件 ,动态插入一列数据
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*** 讀取已有文件 ,動態插入一列數據* @param args*/public static void main(String[] args) {try {//讀取文件File file = new File("D:\\testworkbook.xls");BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));//獲取excelHSSFWorkbook workbook = new HSSFWorkbook(in);//獲取第二個sheetHSSFSheet sheet = workbook.getSheetAt(1);String[] list = {"第一行", "第二行", "第三行"};//動態寫一列數據for (int i = 0; i < list.length; i++) {//第一種寫法
// HSSFRow row = sheet.createRow(0);
// Cell cell = row.createCell(0);
// cell.setCellValue("第一行第一列");//第二種寫法 創建行Row row = sheet.createRow(i);//設置第一列的值row.createCell(0).setCellValue(list[i]);}//寫入文件FileOutputStream fileOut = new FileOutputStream(file);workbook.write(fileOut);fileOut.close();}catch (Exception e){}}
總結
以上是生活随笔為你收集整理的Java excel poi 读取已有文件 ,动态插入一列数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Win10 批量修改文件名
- 下一篇: 安卓实现仿微信点赞好友昵称列表,中间用逗