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. html5和Flash对抗是什么情况?2. javascript 开发百度地图3. python socket 如何接收tcp/ip byte 格式的数据?4. python小白 问关于递归的问题5. python - 为什么用time.strftime格式化会用默认值?6. python - 为什么match匹配出来的结果是<_sre.SRE_Match object; span=(0, 54), match=’’>7. python - 如何在dataframe中删除某行当某列值为nan时?8. python - 这句是什么错误?9. python3.5 urllib.parse.unquote 乱码10. 【小白问题】这行python命令行程序是什么意思?
