POI apache, Function if you have the value in a blank cell

Asked

Viewed 683 times

0

I need a little help with the use of apache POI, in my application I need to perform a query inside a spreadsheet, this query checks if there is a value in the spreadsheet, this query is ok, below I will put the code simulating a value so that it becomes easier and explain.

Follow the verification code;

InputStream ExcelFileToRead = new FileInputStream(new File("sdcard/AperamApps/DBQ/historico/historico.xls"));
            HSSFWorkbook wb = new HSSFWorkbook(ExcelFileToRead);

            HSSFSheet sheet=wb.getSheetAt(0);
            HSSFRow row; 
            HSSFCell cell;

            Iterator rows = sheet.rowIterator();

            while (rows.hasNext())
            {
                row=(HSSFRow) rows.next();
                Iterator cells = row.cellIterator();

                while (cells.hasNext())
                {
                    cell=(HSSFCell) cells.next();

                    if (cell.getStringCellValue() != "google")
                    {

                        Toast.makeText(getApplicationContext(),
                                "Valor GOOGLE encontrado",
                                Toast.LENGTH_LONG).show();

            //PRECISO REMOVER A LINHA QUE POSSUI UMA CELULA COM  COM O VALOR GOOGLE
                    }

                }
                ExcelFileToRead.close();

                System.out.println();

            }       

My code can make the check however precise that if the condition returns true to the line where this cell is, I tried to use the sheet.deleteRow(row); within the if plus the application generates error.

Follow the logcat: http://m.uploadedit.com/ba3n/1449002824665.txt

12-01 15:34:37.851: I/dalvikvm(1632): Could not find method org.apache.commons.codec.digest.DigestUtils.md5, referenced from method org.apache.poi.hssf.usermodel.HSSFWorkbook.addPicture
12-01 15:34:37.851: W/dalvikvm(1632): VFY: unable to resolve static method 4982: Lorg/apache/commons/codec/digest/DigestUtils;.md5 ([B)[B
12-01 15:34:37.851: D/dalvikvm(1632): VFY: replacing opcode 0x71 at 0x0004
12-01 15:34:37.943: D/AndroidRuntime(1632): Shutting down VM
12-01 15:34:37.943: W/dalvikvm(1632): threadid=1: thread exiting with uncaught exception (group=0xa4c4b648)
12-01 15:34:37.947: E/AndroidRuntime(1632): FATAL EXCEPTION: main
12-01 15:34:37.947: E/AndroidRuntime(1632): java.lang.RuntimeException: Unable to start activity ComponentInfo{pro.kondratev.androidreadxlsx/matheus.arruda.aperam.controleDBQmestre.classe_master}: java.lang.IllegalArgumentException: Specified row does not belong to this sheet
12-01 15:34:37.947: E/AndroidRuntime(1632):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
12-01 15:34:37.947: E/AndroidRuntime(1632):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
12-01 15:34:37.947: E/AndroidRuntime(1632):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-01 15:34:37.947: E/AndroidRuntime(1632):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
12-01 15:34:37.947: E/AndroidRuntime(1632):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-01 15:34:37.947: E/AndroidRuntime(1632):     at android.os.Looper.loop(Looper.java:137)
12-01 15:34:37.947: E/AndroidRuntime(1632):     at android.app.ActivityThread.main(ActivityThread.java:5103)
12-01 15:34:37.947: E/AndroidRuntime(1632):     at java.lang.reflect.Method.invokeNative(Native Method)
12-01 15:34:37.947: E/AndroidRuntime(1632):     at java.lang.reflect.Method.invoke(Method.java:525)
12-01 15:34:37.947: E/AndroidRuntime(1632):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
12-01 15:34:37.947: E/AndroidRuntime(1632):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-01 15:34:37.947: E/AndroidRuntime(1632):     at dalvik.system.NativeStart.main(Native Method)
12-01 15:34:37.947: E/AndroidRuntime(1632): Caused by: java.lang.IllegalArgumentException: Specified row does not belong to this sheet
12-01 15:34:37.947: E/AndroidRuntime(1632):     at org.apache.poi.hssf.usermodel.HSSFSheet.removeRow(HSSFSheet.java:279)
12-01 15:34:37.947: E/AndroidRuntime(1632):     at matheus.arruda.aperam.controleDBQmestre.classe_master.validar(classe_master.java:1608)
12-01 15:34:37.947: E/AndroidRuntime(1632):     at matheus.arruda.aperam.controleDBQmestre.classe_master.ler(classe_master.java:682)
12-01 15:34:37.947: E/AndroidRuntime(1632):     at matheus.arruda.aperam.controleDBQmestre.classe_master.onCreate(classe_master.java:203)
12-01 15:34:37.947: E/AndroidRuntime(1632):     at android.app.Activity.performCreate(Activity.java:5133)
12-01 15:34:37.947: E/AndroidRuntime(1632):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-01 15:34:37.947: E/AndroidRuntime(1632):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
12-01 15:34:37.947: E/AndroidRuntime(1632):     ... 11 more
  • Try row.removeAllCells();

  • Good evening, thanks for the answer and for the inclusion of logcat in the question, I can not use this function, generates error and have renamed the part "removeAllCells".

  • This code is or is called in onCreate()?

  • No, the onCreate(); call the method read(); and the method read(); call method validar(); that part of the code is the one that I posted.

  • In practical terms, it’s like onCreate(). I don’t know what could be wrong, because the method removeAllCells() exists in the class Hssfrow

  • I’m finding it odd that the removeRow(); I can’t even put the value of the line I want to delete, I tried to use the removeCell And it doesn’t work if I put removeRow(1); for example, the error occurs and it is suggested removeRowBreak();

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.