Afficher une feuille excel à partir d'une ligne spécifique
Salut à tous,
Comme l'intitulé le dit : je voudrai pouvoir commencer la lecture d'une feuille Excel selon la première qui à le mot "abs".
J'ai essayer de le faire de cette façon :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
public JTable createJTableWithExcel(Sheet sheet) {
// Create new table
JTable table = new JTable();
// Reading the excel file
// Count the line number
int nbRows = sheet.getLastRowNum();
// Count the column number
int nbColumns = numberMaxColumn(sheet);
/*
* System.out.println("In the sheet " + sheet.getSheetName() +
* " there are " + nbRows + " lines and " + nbColumns + " columns");
*/
// Create new object array
Object[][] obj = new Object[nbRows][nbColumns];
// Array header
String[] title = new String[nbColumns];
// Browsing the sheet and retrieves the lines one by one
for (int rowContent = 0; rowContent < nbRows; rowContent++) {
row = sheet.getRow(rowContent);
// Browsing the line and retrieves the columns
if (row != null) {
for (int columnContent = 0; columnContent < nbColumns; columnContent++) {
// Retrieves the cell and this value but begging at "abs"
cell = row.getCell((short) columnContent);
if (cell.getStringCellValue() == "abs") {
//for hide the first column begin in the second column, so index 1
columnContent = 1;
//begin in row index
rowContent = cell.getRowIndex();
Object value = contentCell(cell);
obj[rowContent][columnContent] = value;
// the title
title[columnContent] = (String) obj[0][columnContent];
}
}
}
}
table.setModel(new DefaultTableModel(obj, title));
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
return table;
} |
Apparemment on ne peux pas utiliser cell.getStringCellValue() dans mon cas car il est null.
► Merci pour vos aides :) :)