如何使用 Jxl 将 Excel sheet 转换为 Vector

How to convert Excel sheet into a Vector using Jxl

所以我有这个变量 PV1,它存储 Excel 文件的第一行。但我想要一个将整行存储在一个向量中的变量。

我用System.out.println()只是为了看看能不能走好栏目

String PV1;
for(int col = 0;col < columns;col++) 
 {
   for(int row = 1;row < rows;row++) 
    {
      PV1 = sheet.getCell(1, row).getContents();
      System.out.println(Double.parseDouble(PV1)); 
    }  
 }

我正在使用 jxl 访问 Excel 文件。

如有任何帮助,我们将不胜感激!

Edit: This is the table 我需要在 PV1 中存储所有行。

这对你有帮助

    String PV1;
    Object[] data = Object[columns]
    for(int col = 0;col < columns;col++) 
     {
       for(int row = 1;row < rows;row++) 
      {
         PV1 = sheet.getCell(1, row).getContents();
         data[col] = PV1;
         System.out.println(Double.parseDouble(PV1)); 
      }  
     }

如果我理解正确的话,您需要一个向量来包含第一行中的所有列。

如果是这样,你可以这样做:

Vector<Double> firstRow = new Vector<>();
if(rows > 0){
    for(int col = 0;col < columns;col++){
        String pv = sheet.getCell(1, col).getContents();
        firstRow.add(Double.parseDouble(pv)); 
    } 
}

您可能应该考虑使用 List 而不是 Vector

从您的评论来看,您似乎想要从所有行中检索特定列。你可以这样做:

int pv1ColumnIndex = 1;
List<Double> pv1Columns = new ArrayList<>();
for(int row = 1;row < rows;row++){// row = 1 to skip the header
    String pv1 = sheet.getCell(pv1ColumnIndex, row).getContents();
    pv1Columns.add(Double.parseDouble(pv1)); 
}