java - Can't compare sheetname with string value -
what need compare or search string in sheet name..
i mean, excel file might have more 1 sheet, sheets specific string let said
only sheets named "formato sive 04" going processed...
i'm debugging crazy , i'm getting confused... code it's this
workbook eworkbook = workbookfactory.create(archivo); int totalsheet = eworkbook.getnumberofsheets(); system.out.println("fuerawhile"+totalsheet); sheetname=new string[totalsheet]; //string nombrehoja = eworkbook.getsheetname(0).tostring(); //system.out.println(nombrehoja); sheet sheet = null; while(i<totalsheet){ sheetname[i] = eworkbook.getsheetname(i); system.out.println("antes if :" + sheetname[i]); formato = sheetname[i]; if(formato == "formato sive 04"){ flag = true; } if(flag){ system.out.println("dentroif : " + sheetname[i]); sheet = eworkbook.getsheet(sheetname[i].tostring()); system.out.println("exito"); } else if (!flag){ system.out.println("error"); } system.out.println("dentrowhile : " + sheetname[i]); i++; }
but doesnt give me true :(
does has idea?
i think easy i'm having lot of time in , think i'm right :(
thanks in advance
in java, string
s should never compared using ==
(unless want test intern logic, maybe). prefer:
if( "formato sive 04".equals(formato) ) { ....
if sure formato
never null
, can use more legible form:
if( formato.equals("formato sive 04") ) {
Comments
Post a Comment