0

我正在使用 jexcel 将值从 excel 表存储到 java 数组。但我只得到空值。你能告诉我我做错了什么吗?

package com.tcs.urls;

import java.io.File;

import jxl.Sheet;
import jxl.Workbook;

public class ReadExcel {


    void readExcelSheet(String destfile) {
        File excelSheet=null;

        try {
              excelSheet= new File(destfile);
              Workbook wb=Workbook.getWorkbook(excelSheet);
              int s=wb.getNumberOfSheets();
              Sheet sh=wb.getSheet(0);
              int r=sh.getRows();
              String video_url[][]=new String[r][s];
              String image_url[][]=new String[r][s];
              for(int sheetNo=0;sheetNo<s;sheetNo++)
              {
                  Sheet sheet=wb.getSheet(sheetNo);
                  int columns=sheet.getColumns();
                  int rows=sheet.getRows();

                  String data1,data2;
                  if(columns==2) {
                     for(int row=0;row<rows;row++)
                  {   String x=sheet.getCell(0, row).getContents();
                      if(x!="")
                      {   data1=sheet.getCell(1, row).getContents();
                          data2=sheet.getCell(2, row).getContents();
                          video_url[row][sheetNo]=data1;
                          image_url[row][sheetNo]=data2;
                      }
                  } }

              }
              for(int i=0;i<s;i++) {
                  for(int j=0;j<r;j++) {
                      System.out.print(video_url[j][i]+"\t");
                      System.out.print(image_url[j][i]+"\n");
                  }
                  System.out.println("\n");
              }

        }catch(Exception ioe) {
            ioe.printStackTrace();
        }
    }
}
4

0 回答 0