Java。HSSF。Apache-poi。如何修改代碼
如果我很清楚,您只想過濾您的第一列字符串,然后單獨休息。
為什么不為此使用一個簡單的計數器:
while(rowIterator.hasNext()) { Row row = rowIterator.next(); String RowContent = null; Iterator<Cell> cellIterator = row.cellIterator(); while(cellIterator.hasNext()) {Cell cell = cellIterator.next();RowContent=RowContent+cell.toString(); } //Code for saving RowContent or printing or whatever you want for text in complete row}
RowContent將在每次迭代中串聯單個行的每個單元格。
解決方法我的數據以以下格式存儲(向下看):[-]表示空白單元格,右邊可能只有10列(空格后)。像這樣的東西: [string0] [-] [string1] [string2] [string3] .. [string10] [-]
如何為以下代碼更改此代碼:
1)僅獲取[string0]
2)僅獲取[string1] [string2] [string3] .. [string10] [-]
try { FileInputStream file = new FileInputStream('C:Usersstudent3'+sfilename+'.xls'); //Get the workbook instance for XLS file HSSFWorkbook workbook = new HSSFWorkbook(file); //Get first sheet from the workbook HSSFSheet sheet = workbook.getSheetAt(0); //Iterate through each rows from first sheet Iterator<Row> rowIterator = sheet.iterator(); while(rowIterator.hasNext()) {Row row = rowIterator.next();//For each row,iterate through each columnsIterator<Cell> cellIterator = row.cellIterator();while(cellIterator.hasNext()) { Cell cell = cellIterator.next(); switch(cell.getCellType()) {case Cell.CELL_TYPE_STRING: System.out.print(cell.getStringCellValue() + 'tt'); list1.add(cell.getStringCellValue()); break; }}System.out.println(''); } file.close(); FileOutputStream out = new FileOutputStream('C:Usersstudent3'+sfilename+'.xls'); workbook.write(out); out.close();
我不知道如何停止Iterator。他吸收了所有..
相關文章:
1. android - weex 項目createInstanceReferenceError: Vue is not defined2. PHPExcel表格導入數據庫怎么導入3. android - 哪位大神知道java后臺的api接口的對象傳到前端后輸入日期報錯,是什么情況?求大神指點4. pdo 寫入到數據庫的內容為中文的時候寫入亂碼5. javascript - 如圖,百度首頁,查看源代碼為什么什么都沒有?6. vue2.0+webpack 如何使用bootstrap?7. PHP類封裝的插入數據,總是插入不成功,返回false;8. mac連接阿里云docker集群,已經卡了2天了,求問?9. javascript - 前端開發框架express,在他的模板引擎下怎么給按鈕添加綁定事件?10. 請問PHPstudy中的數據庫如何創建索引
