package testingtest;
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
class excelarrayclass {
static String[][] getexceldatainArray;
public static void main(String[] args) throws IOException, BiffException {
// Create an array based on data in excel file
excelarrayclass tc = new excelarrayclass();
getexceldatainArray = tc.CreateArrayfromExcel("D:\\Testing.xls",
"testing");
}
public String[][] CreateArrayfromExcel(String WorkbookName, String SheetName)
throws BiffException, IOException {
String[][] arrTestDta;
Workbook workbk = Workbook.getWorkbook(new File(WorkbookName));
Sheet wrkSheet = workbk.getSheet(SheetName);
arrTestDta = new String[wrkSheet.getRows()][wrkSheet.getColumn()]
for (int i = 0; i < wrkSheet.getRows(); i++) {
for (int j = 0; j < wrkSheet.getColumns(); j++) {
Cell cell = wrkSheet.getCell(j, i);
if (cell.getContents() != null) {
arrTestDta[i][j] = cell.getContents();
System.out.println(cell.getContents());
}
}
}
return arrTestDta;
}
}
No comments:
Post a Comment