public static void writexls() {//把读取的文件写入到excel文件中
int i = 0;
try {
file file = new file("d:/cn.csv");
if (file.isfile() && file.exists()) {
inputstreamreader read = new inputstreamreader(
new fileinputstream(file));
bufferedreader bufferreader = new bufferedreader(read);
string linetxt = null;
string[] arg = null;
getconnection();
list<string[]> list = new arraylist<string[]>() ;
linetxt = bufferreader.readline();
try {
string tempdate;
while (linetxt != null && !linetxt.trim().equals("")) {
i++;
arg = linetxt.split(",");
list.add(arg) ;
linetxt = bufferreader.readline();
}
for(string[] args:list){
system.out.println(args[0]+" "+args[1]+" "+args[2]+" "+args[3]);
operateexl(list) ;
} catch (exception e) {
e.printstacktrace();
}
} else {
system.out.println("文件路径不正确!");
}
} catch (exception e) {
system.out.println("文件错误!");
} finally {
system.out.println(i);
}
}
public static void operateexl(list<string[]> list) {
writableworkbook wb = workbook.createworkbook(new file("d:/test.xls")) ;
writablesheet sheet = wb.createsheet("第一页", 0) ;
for(int i=0;i<list.size();i++){
string arg[] = list.get(i) ;
for(int j=0;j<arg.length;j++){
sheet.addcell(new label(j,i,arg[j])) ;
wb.write() ;
wb.close() ;
} catch (exception e) {
// todo: handle exception
e.printstacktrace() ;
public static void main(string[] args) {
writexls();