Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用java创建可附加的Excel工作表_Java_Excel_Apache Poi_Jxl - Fatal编程技术网

如何使用java创建可附加的Excel工作表

如何使用java创建可附加的Excel工作表,java,excel,apache-poi,jxl,Java,Excel,Apache Poi,Jxl,我想创建一个可追加的excel工作表。 我有四列stream1 stream2 stream3 stream4 第一次仅在第一列插入数据(stream1) 在那之后,我想一个接一个地填满其他列 这是我正在使用的代码: public void createFile(Jqueue stream1, Jqueue stream2, Jqueue stream3, Jqueue stream4) { try { String filename = "path";

我想创建一个可追加的excel工作表。 我有四列stream1 stream2 stream3 stream4

第一次仅在第一列插入数据(stream1) 在那之后,我想一个接一个地填满其他列

这是我正在使用的代码:

 public void createFile(Jqueue stream1, Jqueue stream2, Jqueue stream3, Jqueue stream4) {
    try {

        String filename = "path";
        boolean alreadyExists = (new File(filename)).exists();

        HSSFRow rowhead = sheet1.createRow((short) 0);
        rowhead.createCell((short) 0).setCellValue("Stream 1");
        rowhead.createCell((short) 1).setCellValue("Stream 2");
        rowhead.createCell((short) 2).setCellValue("Stream 3");
        rowhead.createCell((short) 3).setCellValue("Stream 4");


        int i = 1;
        while (!stream1.isEmpty()) {
            String urlstream1 = "";
            String urlstream2 = "";
            String urlstream3 = "";
            String urlstream4 = "";
            HSSFRow row = sheet1.createRow((short) i);
            try {
                if (stream1.size() > 0) {
                    urlstream1 = stream1.dequeue().toString();
                }
            } catch (Exception ex) {
            }
            try {
                if (stream2.size() > 0) {
                    urlstream2 = stream2.dequeue().toString();
                }
            } catch (Exception ex) {
            }
            try {
                if (stream3.size() > 0) {
                    urlstream3 = stream3.dequeue().toString();
                }
            } catch (Exception ex) {
            }
            try {
                if (stream4.size() > 0) {
                    urlstream4 = stream4.dequeue().toString();
                }
            } catch (Exception ex) {
            }
            row.createCell((short) 0).setCellValue(urlstream1);
            row.createCell((short) 1).setCellValue(urlstream2);
            row.createCell((short) 2).setCellValue(urlstream3);
            row.createCell((short) 3).setCellValue(urlstream4);
            i++;
        }

        FileOutputStream fileOut = new FileOutputStream(filename);
        hwb.write(fileOut);
        fileOut.close();
但这不是可追加的代码。它是一行一行地插入数据


高级thx。

我想您的代码只要稍加修改就可以了

试着替换

int i=1

以下是:

int i=sheet1.getLastRowNum()+1

您还需要更改一下读写文件的实现