I have a program where i am calling a method which reads xls file and fetches 2nd column.
public static String readExcel(String FileName) throws BiffException,
IOException, java.text.ParseException, InterruptedException {
String ss = null;
FileInputStream fs = new FileInputStream(FileName);
HSSFWorkbook workbook = null;
workbook = new HSSFWorkbook(fs);
// TO get the access to the sheet
HSSFSheet sh = workbook.getSheet("data");
int rowCount = sh.getLastRowNum() - sh.getFirstRowNum();
DataFormatter formatter = new DataFormatter(Locale.US);
for (int i = 0; i < rowCount; i++) {
Row row = sh.getRow(i);
// Create a loop to print cell values in a row
for (int j = 1; j < 2; j++) {
Cell alpha = row.getCell(j);
String Beta = formatter.formatCellValue(alpha);
String leftRemoved = Beta.substring(0);
String GammaRemove = leftRemoved.trim();
dateStringList.add(GammaRemove);
// System.out.println(dateStringList);
}
}
System.out.println("The String contains" + dateStringList);
ArrayList<String> Beta = dateStringList;
String[] s1 = new String[256];
for (int k = 1; k < dateStringList.size(); k++) {
String gamma = Beta.get(k);
StringBuilder sb = new StringBuilder(gamma);
sb.deleteCharAt(0);
System.out.println("The New String is" + sb);
// String ss1=sb.toString();
// System.out.println("The String SS is" + ss);
ss = sb.toString();
System.out.println("The String SS is" + ss);
}
fs.close();
return ss;
}
I am trying to use stringBuilder to remove the leading space of the 2nd column string values. But i want to fetch all these stringbuilder values from this method and store them in string array. which i am not able to do as it is throwing type mismatch error.
Please suggest how i can get all the string values from this StringBuilder and store it in string array.
Thanks