兼容2003和2007的代码
package lilong;
import java.io.FileInputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class HNG_SUB_ITEM_INSERT {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
String filename = "外资代码描述.xlsx";
FileInputStream in = new FileInputStream(filename);
//HSSFWorkbook wb = new HSSFWorkbook(fs);
Workbook wb;
if(filename.endsWith(".xls")) {
wb = new HSSFWorkbook(in);
} else {
wb = new XSSFWorkbook(in);
}
Sheet sheet = wb.getSheetAt(0);
for(int i = 1;i<=sheet.getLastRowNum();++i) {
Row row = sheet.getRow(i);
p(row.getCell(0).getStringCellValue());
p(row.getCell(1).getStringCellValue());
}
}
public static void p(Object o) {
if(o != null) System.out.println(o.toString());
}
}