我的數據是以一種格式存儲的(向下看):[ - ]表示一個空白單元格,右邊可能是 後面只有10個空格。事情是這樣的:
[string0] [ - ] [字符串1] [字符串2] [STRING3] .. [string10] [ - ]Java。 HSSF。 Apache的POI。如何修改代碼
如何更改此代碼:
1)僅獲得[string0]
2)只獲得[字符串1] [字符串2] [STRING3] .. [string10] [ - ]
try {
FileInputStream file = new FileInputStream("C:\\Users\\student3\\"+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 columns
Iterator<Cell> cellIterator = row.cellIterator();
while(cellIterator.hasNext()) {
Cell cell = cellIterator.next();
switch(cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue() + "\t\t");
list1.add(cell.getStringCellValue());
break;
}
}
System.out.println("");
}
file.close();
FileOutputStream out =
new FileOutputStream("C:\\Users\\student3\\"+sfilename+".xls");
workbook.write(out);
out.close();
我不知道如何停止迭代。他吸收所有..
你知道如何在列中實現concat列,然後將每行的行轉換爲字符串 –
所以你想連接任何行的所有列的權利? – Sankumarsingh
是的,並保存每行 –