将信息插入到Excel文件的指定位置
步骤
创建File和获取文件、建立副本获取表定位到指定位置遍历所有位置
public void insert(String name){
File file =
new File(
"data/aa"+name+
".xls");
try {
Workbook wb = Workbook.getWorkbook(_file);
WritableWorkbook book = Workbook.createWorkbook(_file,wb);
WritableSheet sheet = book.getSheet(
0);
String in_bracket = value_list.substring(
1, value_list.length()-
1);
String []valuelist = in_bracket.split(
",");
WritableCell cell =
null;
int Rows = sheet.getRows();
for(
int i =
0; i < valuelist.length;i++){
cell =
new Label(i, Rows, valuelist[i]);
try {
sheet.addCell(cell);
}
catch (RowsExceededException e) {
e.printStackTrace();
}
catch (WriteException e) {
e.printStackTrace();
}
}
book.write();
try {
book.close();
}
catch (WriteException e) {
e.printStackTrace();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
声明: 本文是作者实践时的心得记录,在特定项目下生效,不具有普适性