日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國(guó)內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > php開源 > php教程 > java poi 操作excel,xssf 讀excel 2007,將某些單元格為固定值

java poi 操作excel,xssf 讀excel 2007,將某些單元格為固定值

來源:程序員人生   發(fā)布時(shí)間:2015-05-28 09:10:57 閱讀次數(shù):4387次

本來想看1下java IO,NIO,發(fā)現(xiàn)這塊知識(shí)體系還挺大。暫時(shí)寫1個(gè)操作excel的demo。由于時(shí)間關(guān)系,完成了功能,后期繼續(xù)完善。

功能:讀取excel表格(該表格為測(cè)試結(jié)果表格,共10幾列,第1行是標(biāo)題),將第0列標(biāo)記為id(遞增),第9列標(biāo)記為結(jié)果(默許是PASS),第10列標(biāo)記為姓名。

本可使用excel的拖拽功能,但由于excel中的內(nèi)容和樣式常常需要修改,因此致使重復(fù)工作。暫寫這個(gè)小demo,期待完善后功能更詳實(shí)。

import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; //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.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io.*; /** * Created by n on 2015/4/29. */ public class InsertInfoToExcel { //該方法判斷excel版本 static Workbook openWorkbook(InputStream in, String filename) throws IOException { Workbook wb = null; if (filename.endsWith(".xlsx")) { wb = new XSSFWorkbook(in);//Excel 2007 } else { wb = (Workbook) new HSSFWorkbook(in);//Excel 2003 } return wb; } //該方法處理excel的數(shù)據(jù),把第1列標(biāo)記為id(遞增),第9列標(biāo)記為結(jié)果(默許是PASS),第10列標(biāo)記為姓名 public static void setExcelData(String fileName) throws Exception { InputStream in = new FileInputStream(fileName); //創(chuàng)建輸入流 Workbook wb = openWorkbook(in, fileName);// 獲得Excel文件對(duì)象 Sheet sheet = wb.getSheetAt(0);// 獲得文件的指定工作表m 默許的第1個(gè)Row row = null; int totalRows = sheet.getLastRowNum(); // 總行數(shù) int totalCells = sheet.getRow(0).getLastCellNum();//總列數(shù),根據(jù)第1行得來的 System.out.println("列數(shù):" + totalCells + " 行數(shù):" + totalRows); //順次獲得每行 for (int i = 1; i <= sheet.getLastRowNum(); i++) { XSSFRow row = (XSSFRow) sheet.getRow(i);// 獲得行對(duì)象 if (row == null) {// 如果為空,不處理 continue; } //將第0列的標(biāo)記為id,遞增。遇到空的先不管,跳過 if (row.getCell(0) != null) { Cell cellIndex = row.getCell(0); System.out.print(cellIndex.getNumericCellValue()); cellIndex.setCellValue(i); } else { XSSFCell cellIndex = row.createCell(0); cellIndex.setCellValue(i); } //將第9列標(biāo)記為測(cè)試結(jié)果,遇到空的就標(biāo)記為PASS,非空的不管。 if (row.getCell(9) == null) { XSSFCell cellResult = row.createCell(9); System.out.print(cellResult.getStringCellValue()); cellResult.setCellValue("PASS"); } //將第10列的標(biāo)記為測(cè)試人員的名字。不論是不是空都標(biāo)記為名字。 if (row.getCell(10) != null) { XSSFCell cellName = row.getCell(10); // System.out.print(cellName.getStringCellValue()); cellName.setCellValue("aashen"); } else { XSSFCell cellName = row.createCell(10); cellName.setCellValue("aashen"); } } //寫入數(shù)據(jù),關(guān)閉 OutputStream out = new FileOutputStream(fileName); wb.write(out); in.close(); out.close(); } public static void main(String[] args) throws Exception { // String fileName="E:"+ File.separator+"hello.txt"; String fileName = "E://hi.xlsx"; setExcelData(fileName); // File f=new File(fileName); // if(f.exists()) // System.out.println("new file successfully"); // Writer out =new FileWriter(f); // String str="hello"; // out.write(str); // out.close(); } }

生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 婷婷丁香社区 | 亚洲免费一区 | 午夜国产福利 | 日韩精品 电影一区 亚洲 | 天天综合一区 | 精品欧美乱码久久久久久1区2区 | 国产精品xxxx | 欧美国产激情 | 麻豆国产在线 | 麻豆国产一区二区三区四区 | 久久久久国产一区 | 成人精品久久 | 免费av高清| 日本欧美一区二区三区 | 99久久精品国产一区二区三区 | 久久视频一区二区 | 717影视三级理论电影在线播放 | 国产成人精品av在线 | 日韩小视频 | 成人在线免费观看 | 日韩电影免费在线 | 国产精品免费观看 | 天天操人人干 | 男女黄色网 | 国产一区二区视频在线播放 | 欧美二区三区 | 久久精品免费电影 | 伊人99| 99精品在线视频观看 | 亚洲精品九九 | 婷婷av在线 | 精品久久久久久久久久久 | 一区二区三区四区国产精品 | 91精品婷婷国产综合久久性色 | 91视频你懂的 | 国产一级久久 | 99九九久久| 国产一区二区在线免费观看 | 国产又爽又黄免费视频 | 精品国产精品 | 欧美爱爱网 |