0

在此处输入图像描述

在多个 Arraylist 中,仅显示第一行数据

Arraylist 的值类似于:

 ArrayListHeaderCall: [Date, Latex Received (In Liter), Residual Scrap (In Kg) :, No Of Tray :, Sent To Factory  :]

ArrayListExcelCall: [[2017-08-11, 334, 34, 11, Yes], [2017-08-10, 25, 54, 69, Yes]]

Excel代码如下:

ArrayList<List<String>> modelArrayList;
    ArrayList<String>pdfArrayListHeader;

 File file = new File(directory + timeStamp + ".xls");
            WorkbookSettings wbSettings = new WorkbookSettings();
            wbSettings.setLocale(new Locale("en", "EN"));
            WritableWorkbook workbook;
            workbook = Workbook.createWorkbook(file, wbSettings);
            //Excel sheet name. 0 represents first sheet
            WritableSheet sheet = workbook.createSheet("userList", 0);
            // column and row


            for (int x=0;x<pdfArrayListHeader.size();x++){
                for (int y=x;y<pdfArrayListHeader.size();y++) {
                    sheet.addCell(new Label(y, 0, pdfArrayListHeader.get(y)));
                }
                Log.v("ArrayListHeader",pdfArrayListHeader.get(x));
            }

            int count=1;
            for(List<String> arrayList1 : modelArrayList){
                Log.v("arrayList1",arrayList1.toString());
               for (int i=0;i<arrayList1.size();i++){
                   for (int j=0;j<arrayList1.size();j++){
                       sheet.addCell(new Label(j, count, arrayList1.get(j)));
                       Log.v("countInside", String.valueOf(count));
                   }
                   Log.v("ArrayListLoop",arrayList1.get(i));
                   workbook.write();
               }
               count++;
                Log.v("count", String.valueOf(count));
            }

这是所有代码请给我一个解决方案

4

1 回答 1

0

编写 workbook.write(); 循环外

for(List<String> arrayList1 : modelArrayList){
                Log.v("arrayList1",arrayList1.toString());
               for (int i=0;i<arrayList1.size();i++){
                   for (int j=0;j<arrayList1.size();j++){
                       sheet.addCell(new Label(j, count, arrayList1.get(j)));
                       Log.v("countInside", String.valueOf(count));
                   }
                   Log.v("ArrayListLoop",arrayList1.get(i));
               }
               count++;
               **workbook.write();**
                Log.v("count", String.valueOf(count));
            }
于 2017-08-21T06:30:10.797 回答