Issue while reading an excel file in android -


i trying read excel file. file kept in work space in folder called rocom_db , file name rocom.xlsx .

i trying read file using following code :

public string readcomplexexcelfile(context context){         try{            // creating input stream             file file = new file(environment.getexternalstoragedirectory()                    + "/android/data/" + getapplicationcontext().getpackagename()                    + "/rocom_db/", "rocom.xlsx");             fileinputstream myinput = new fileinputstream(file);             // create poifsfilesystem object             poifsfilesystem myfilesystem = new poifsfilesystem(myinput);             // create workbook using file system             hssfworkbook myworkbook = new hssfworkbook(myfilesystem);             // first sheet workbook             hssfsheet mysheet = myworkbook.getsheetat(0);             /** need iterate through cells.**/            iterator<row> rowiter = mysheet.rowiterator();             while(rowiter.hasnext()){                hssfrow myrow = (hssfrow) rowiter.next();                iterator<cell> celliter = myrow.celliterator();                while(celliter.hasnext()){                    hssfcell mycell = (hssfcell) celliter.next();                    log.d("", "cell value: " +  mycell.tostring());                    toast.maketext(context, "cell value: " + mycell.tostring(), toast.length_short).show();                }            }        }catch (exception e){            e.printstacktrace();           }        return "";    } 

the problem every time try read file, file not found exception . have used necessary poi-3.7.jar 1 , kept piece of code in manifest.xml :

<uses-permission         android:name="android.permission.write_external_storage"/> 

i don't want use excel assets directory supports excel upto 1 mb , file has potential increase in size .

can tell me doing wrong ? appreciated . .

i got 1 work in quite strange way. .

1> first of got rid of poi.jar , instead used jxl.jar. again excel work book in format of xslx becuase in ms excel 2007, converted xls i.e. excel(97-2003) format.

2> pushed excel sdcard using following commands :

  • a> first give cmd in run(for windows)

    b> navigate adb.exe present.(it inside android-->sdk-->platform tools)

    c> copy xls folder adb.exe kept.

    d> run adb shell. open unix shell. go : cd /mnt , change permission of sd card using : chmod 777 /sdcard

    e> return batch prompt using : exit command , type : adb push file.xls /mnt/sdcard/

    f> go inside /mnt/sdcard/ using cd , change permission file using : chmod 777 file.xls

3> important things done , wrote following piece of code work out :

   public string readcomplexexcelfile(context context, string userinput){        string requiredcontents = "";        try{             file inputworkbook = new file(environment.getexternalstoragedirectory()+"/myfile.xls");            workbook w;             // create workbook using file system            w = workbook.getworkbook(inputworkbook);             // first sheet workbook             sheet sheet = w.getsheet(0);             /** need iterate through cells.**/            (int j = 0; j < sheet.getcolumns(); j++) {                (int = 0; < sheet.getrows(); i++) {                  cell cell = sheet.getcell(j, i);                  if(cell.getcontents().equalsignorecase(userinput)){                      cell cellcorrespond = sheet.getcell(j+1, i);                      requiredcontents = cellcorrespond.getcontents();                      break;                  }                 }              }          }catch (exception e){            e.printstacktrace();           }        return requiredcontents;    } 

hopefully, people stuck without luck while going through same process. cheers !


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -