poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nan Lei <nanlei1...@gmail.com>
Subject Re: Encoding Issue - POI 3.6
Date Fri, 17 Dec 2010 15:26:04 GMT
Hi,

I am a Chinese developer, I use UTF-8 as the charset for the coding and
database(MySQL InnoDB engine). So there is no problem for the Chinese
character.

For the coding, from workbook,sheet,row to cell, read the cell value as
Boolean, Number and String.

For example,
public static List<Student> readFromXLSX2007(String filePath) {
File excelFile = null;
InputStream is = null;
String cellStr = null;
List<Student> studentList = new ArrayList<Student>();
Student student = null;
try {
excelFile = new File(filePath);
is = new FileInputStream(excelFile);
XSSFWorkbook workbook2007 = new XSSFWorkbook(is);
XSSFSheet sheet = workbook2007.getSheetAt(0);
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
student = new Student();
XSSFRow row = sheet.getRow(i);
if (row == null) {
continue;
}
for (int j = 0; j < row.getLastCellNum(); j++) {
XSSFCell cell = row.getCell(j);
if (cell == null) {
cellStr = "";
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN) {
cellStr = String.valueOf(cell.getBooleanCellValue());
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
cellStr = cell.getNumericCellValue() + "";
} else {
cellStr = cell.getStringCellValue();
}
if (j == 0) {
student.setName(cellStr);
} else if (j == 1) {
student.setGender(cellStr);
} else if (j == 2) {
student.setAge(new Double(cellStr).intValue());
} else if (j == 3) {
student.setSclass(cellStr);
} else {
student.setScore(new Double(cellStr).intValue());
}
}
studentList.add(student);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return studentList;
}

I think UTF-8 is good choice.

Best Wishes!
Nan Lei

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message