日期:2014-05-20  浏览次数:20827 次

将班级所有学生信息(Excel表中)写入TXT文件,并读取输出
关于IO流的问题。。。求代码

------解决方案--------------------
也太伸手党了。
怎么读excel见:
http://bbs.csdn.net/topics/390360927
写入txt就不说了
------解决方案--------------------

HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(new File("D:\\workbook.xls")));
FileOutputStream fos = new FileOutputStream(new File("D:\\test.txt"));
HSSFSheet sheet = workbook.getSheetAt(0);
int rows = sheet.getLastRowNum();
for(int i = 0 ;i <= rows ; i++){
HSSFRow row = sheet.getRow(i);
int cells = row.getLastCellNum();
for(int j = 0 ; j < cells ; j++){
HSSFCell cell = row.getCell(j);
String str = cell.getStringCellValue();
fos.write(str.getBytes());
fos.write("  ".getBytes());
}
fos.write("\r\n".getBytes());
}
fos.close();

使用POI读取excel到txt
自己改改吧!