在Excel文件中附加数据 [英] Appending data in an Excel file

查看:178
本文介绍了在Excel文件中附加数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个将数据附加到Excel文件的程序。我找到了以下代码。但是它会重写Excel文件中的内容,而不是附加它。请帮我完成这个。

I am trying to write a program that will append data to an Excel file in Java. I got up to the following code. But it rewrites the contents in the Excel file, not appending to it. Please help me to complete this.

public class jExcel
{
    static WritableWorkbook workbook;
    public static void main(String args[])throws Exception
    {
        workbook = Workbook.createWorkbook((new File("D:\\0077\\my2.xls")));
        WritableSheet sheet = workbook.createSheet("First Sheett",1);
        Label label = new Label(5,2,"ssssssssss");
        sheet.addCell(label);
        workbook.write();
        workbook.close();
    }
}


推荐答案

/ WRITE IN XLS

//WRITE IN XLS

    WritableWorkbook workbook = Workbook.createWorkbook(new File("D:\\output.xls"));
    WritableSheet sheet = workbook.createSheet("First Sheet", 0);
    Label label = new Label(0, 2, "A label record"); 
    sheet.addCell(label);
    workbook.write(); 
    workbook.close();

    //MODIFY XLS

    Workbook workbook1 = Workbook.getWorkbook(new File("D:\\output.xls"));
    WritableWorkbook copy = Workbook.createWorkbook(new File("D:\\output.xls"), workbook1);
    WritableSheet sheet2 = copy.getSheet(0); 
    //WritableCell cell = sheet2.getWritableCell(5, 2); 

    copy.write();
    copy.close();

这篇关于在Excel文件中附加数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆