Tôi muốn đọc các giá trị bảng tính excel và lưu trữ các giá trị đó trong một mảng trong Java.Cách đọc các giá trị từ tệp excel và lưu trữ trong Array?
Tôi có mã sẵn sàng để đọc bảng excel nhưng tôi không thể tùy chỉnh nó để lưu trữ các giá trị đó trong Mảng.
Đây là mã của tôi để đọc một tờ excel:
package com.core.testscripts;
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class NewExcel
{
private String inputFile;
public void setInputFile(String inputFile)
{
this.inputFile = inputFile;
}
public void read() throws IOException
{
File inputWorkbook = new File(inputFile);
Workbook w;
try
{
w = Workbook.getWorkbook(inputWorkbook);
// Get the first sheet
Sheet sheet = w.getSheet(0);
// Loop over first 10 column and lines
for (int j = 0; j < sheet.getColumns(); j++)
{
for (int i = 0; i < sheet.getRows(); i++)
{
Cell cell = sheet.getCell(j, i);
System.out.println(cell.getContents());
}
}
}
catch (BiffException e)
{
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException
{
NewExcel test = new NewExcel();
test.setInputFile("D:/hellohowareyou.xls");
test.read();
}
}
Làm thế nào để bạn muốn đọc? Tất cả các ô của tất cả các hàng trong một mảng? Hoặc tất cả các ô trên mỗi hàng trong một mảng hai chiều ?? – Nik