怎么用java语言将word excel txt文件输出到控制台,而且还要编写代码往定制的txt excel,word中填写内容?
1个回答
展开全部
JXL的Jar包,用着挺方便的.
给你写一个写入Excel文件的代码片断:
void writeExcel(String [] strArray) {
try {
WritableWorkbook writebook = Workbook.createWorkbook(new File(fileName));
WritableSheet writeSheet = writebook.createSheet("一个Sheet页", 2);
int i=0;
for(String s:strArray){
Label label = new Label(0,i,s);
i++;
try {
writeSheet.addCell(label);
} catch (RowsExceededException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
writebook.write();
try {
writebook.close();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
将你要写入Excel内容以一个数组形式传过来就可以了!
给你写一个写入Excel文件的代码片断:
void writeExcel(String [] strArray) {
try {
WritableWorkbook writebook = Workbook.createWorkbook(new File(fileName));
WritableSheet writeSheet = writebook.createSheet("一个Sheet页", 2);
int i=0;
for(String s:strArray){
Label label = new Label(0,i,s);
i++;
try {
writeSheet.addCell(label);
} catch (RowsExceededException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
writebook.write();
try {
writebook.close();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
将你要写入Excel内容以一个数组形式传过来就可以了!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询