返回目录:excel表格制作
使用poi能解决你的e69da5e6ba90e799bee5baa6e79fa5e98193361问题
或者是
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import static java.lang.System.out;
public class FileTest {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
String string = "";
File file = new File("c:" + File.separator + "xxx.xls");
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String str;
while((str = br.readLine()) != null) {
string += str;
}
out.println(string);
}
}
在Java中读取Excel文件的内容
在这里,我使用的是一个叫Java Excel API的东西,类似的还有jakarta的POI,不过感觉那个
太复杂了点儿。而且jxl对中文的支持相当的好,至少我在用的过e68a84e8a2ad7a64363程中一点问题没出。
一、下载地址
http:///jexcelapi/
二、特性
可以读取Excel 95, 97, 2000文件
可以读或写Excel 97及其以后版本的的公式(不过我发现好像有bug)
生成Excel 97格式的电子表格
支持字体、数字和日期格式化
支持单元格的颜色和阴影
可以编辑现有的文件
三、读文件
//声明一下,记得后面要关闭哦。。
Workbook workbook = null;
try {
workbook = Workbook.getWorkbook(new File("d:\\temp\\TestRead.xls"));
} catch (Exception e) {
throw new Exception("file to import not found!");
}
Sheet sheet = workbook.getSheet(0);
Cell cell = null;
int columnCount=3;
int rowCount=sheet.getRows();
for (int i = 0; i<rowcount; p="" {
for (int j = 0; j<columncount; p="" {
//注意,这里的两个参数,第一个是表示列的,第二才表示行
cell=sheet.getCell(j, i);
//要根据单元格的类型分别做处理,否则格式化过的内容可能会不正确
if(cell.getType()==CellType.NUMBER){
System.out.print(((NumberCell)cell).getValue());
}
else if(cell.getType()==CellType.DATE){
System.out.print(((DateCell)cell).getDate());
}
else{
System.out.print(cell.getContents());
}
//System.out.print(cell.getContents());
System.out.print("\t");
}
System.out.print("\n");
}
//关闭它,否则会有内存泄露
workbook.close();