Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
import java.io.File;
import java.io.File;
import jxl.*;
//use context variable to easily integrate a test in Talend
context.fileHasRequiredSheet = false;
String requiredSheetName="Special";
Workbook workbook = Workbook.getWorkbook(new File("myfile.xls"));
String[] sheetNames = workbook.getSheetNames();
for(int i=0;i<sheetNames.length;i++)
{
if(sheetNames.equals(requiredSheetName))
{
context.fileHasRequiredSheet = true;
break;
}
}
public static String[] getExcelSheetList(String path){
String[]sheetsName = null;
try{
//System.out.println(path.split("."));
if(path.substring(path.indexOf(".")+1, path.length()).equalsIgnoreCase("xls")){
/**
* on recupere la liste des noms des feuilles
*/
int nbrXls = 0;
//Sheet sheet = null;
Workbook workbook = Workbook.getWorkbook(new File(path));
for(int i = 0; i < workbook.getNumberOfSheets(); i++){
nbrXls += workbook.getSheet(i).getRows();
}
// liste des noms de feuilles
sheetsName = workbook.getSheetNames();
for(int j = 0; j < sheetsName.length; j++)
System.out.println(sheetsName<J>);
}
}
catch(ArrayIndexOutOfBoundsException e){e.printStackTrace();} catch (JXLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return sheetsName;
}</J>