[英]How to convert Excel sheet into a Vector using Jxl
So I have this variable PV1 who stores from an Excel file the first row. 因此,我有一个变量PV1,该变量从Excel文件存储第一行。 But I want a variable that stores the entire row in a vector.
但是我想要一个将整个行存储在向量中的变量。
I use System.out.println()
just to see if it takes the good column. 我使用
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));
}
}
I am using jxl to access the Excel file. 我正在使用jxl访问Excel文件。
Any help would be much appreciated! 任何帮助将非常感激!
Edit: This is the table and i need to store in PV1 all the rows. 编辑:这是表 ,我需要在PV1中存储所有行。
This will help you 这对你有帮助
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));
}
}
If I understand correctly you need a vector that should hold all the columns in the first row. 如果我理解正确,则需要一个向量,该向量应包含第一行中的所有列。
If that is the case, you can do something like this: 在这种情况下,您可以执行以下操作:
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));
}
}
You should probably consider using a List
instead of a Vector
. 您可能应该考虑使用
List
而不是Vector
。
From your comment it seems that you want to retrieve a specific column from all the rows. 从您的评论看来,您想要从所有行中检索特定的列。 You can do that like this:
您可以这样做:
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));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.