//for loop for traversing rows
for (int i = 1 ; i < roorws.getCount() ; i++)
{ // for loop for traversing columns
for (int j = 1 ;j<tcols ; j++)
{ //if column is 5
if(j==5)
//printing values of cell 5
System.out.print(cells.get(i,j).getValue().toString().substring(0, 26).length()+ "\t");
String cell1=cells.get(i,j).getValue().toString().substring(0, 26);
cell=cells.get("F2");
cell.putValue(cell1);
}
System.out.println("");
}
Asked
Active
Viewed 60 times
-2
-
2Looks like you string is shorten than 26 charachters: substring(0, 26). – Jens Feb 08 '16 at 07:15
-
I think the lines where the printing are done. I am sure there is a string value in the cell that is not up to 26 characters of length. – cdaiga Feb 08 '16 at 07:17
1 Answers
0
Apparently the length of the string is not (at least) 26 characters. Change:
System.out.print(cells.get(i,j).getValue().toString().substring(0, 26).length()+ "\t");
to:
System.out.print(cells.get(i,j).getValue().toString().length()+ "\t");
to print the length of the string.
You can use Apache Commons StringUtils substring() method to get sub string in a safe way (so it takes only at most n
characters):
String cell1= StringUtils.substring(cells.get(i,j).getValue().toString(), 0, 26);

Zbynek Vyskovsky - kvr000
- 18,186
- 3
- 35
- 43