我有一个带有一些值的 excel 文件,例如:
**Status Code** **Method Name**
400 createRequest
401 testRequest
402 mdm
403 fileUpload
以及下面的代码来读取和打印数据[稍后我会把它们放在 HashMap 中]
package com.poc.excelfun;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
public class ReadExcelData {
public static void main(String[] args) {
try {
FileInputStream file = new FileInputStream(new File("attachment_status.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_BOOLEAN:
System.out.print(cell.getBooleanCellValue() + "\t\t");
break;
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue() + "\t\t");
break;
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue() + "\t\t");
break;
}
}
System.out.println("");
}
file.close();
/*
* The following code to create a new work book with the value fetched from the given work book
* FileOutputStream out =
new FileOutputStream(new File("attachment_status_new.xls"));
workbook.write(out);
out.close();*/
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
但上面的代码返回以下内容:
Status Code Method Name
400.0 createRequest
401.0 testRequest
402.0 mdm
403.0 fileUpload
如果出现了状态码,.0
但我只想得到400
不带.0
这该怎么做。
我已经用于poi
excel操作。
最好的问候安托