如何使用Android中的多行JXL将数据写入excel?

时间:2018-09-29 20:07:18

标签: java android excel jxl

我正在将图像上传到Firebase存储中,并尝试将图像URL写入Excel工作表中。在android中的excel中创建新文件后,我无法输入多个行。我的代码仅写在第一行中,我将行用作变量,但仍然不会转到下一行。为什么?

try {
      workbook = Workbook.createWorkbook(file, wbSettings);
      final WritableSheet sheet = workbook.createSheet("sheet1", 1);
                file.createNewFile();

      for (int i=0; i < fileList.length; i++) {
      final File currentFile = fileList[i];
      FirebaseStorage.getInstance().getReference()
      .child("Product Images/" + currentFile.getName() + "." + MimeTypeMap.getFileExtensionFromUrl(currentFile.getPath()))
      .putFile(Uri.fromFile(new File(currentFile.getAbsolutePath())))
      .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
      @Override
      public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
      Log.d("UPLOADCOMPLETED", "onSuccess: " + (currentIterator) +taskSnapshot.getDownloadUrl());
                           createFirstSheet(sheet,currentFile.getName(),taskSnapshot.getDownloadUrl().toString());
                                }
                            });
                }

            } catch (Exception e) {
                Log.d("UPLOADCOMPLETED", "createFirstSheet: "+e.getMessage());
                e.printStackTrace();
            }


void createFirstSheet(WritableSheet sheet, String picName, String picURL) {
        try {

            //Excel sheet name. 0 (number)represents first sheet

            // column and row title
            sheet.addCell(new Label(0, prevValue, picName));
            sheet.addCell(new Label(1, prevValue, picURL));

            prevValue++;

            workbook.write();
            if(prevValue==10){
                workbook.close();
            }
            //workbook.close();

        } catch (Exception e) {
            Log.d("UPLOADCOMPLETED", "createFirstSheet: "+e.getMessage());
            e.printStackTrace();
        }

    }
}

0 个答案:

没有答案