Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8689395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:38:09+00:00 2026-06-12T23:38:09+00:00

In the code below I’m trying to read a xls file and do whatever

  • 0

In the code below I’m trying to read a xls file and do whatever is necessary classes through the JXL api, but when converting to Workbook.getWorkbook (dbInputStream) exception occurs

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import android.content.Context;

public class ReadExcel {

    public static List<ChaveEloCoordenada> read(Context context) {
        List<ChaveEloCoordenada> list = new ArrayList<ChaveEloCoordenada>();
        try {
            InputStream dbInputStream = context.getAssets().open("file.xls", Context.MODE_WORLD_READABLE);

            int cols = 9;
            Cell[] row;

            Cell cell;

            Workbook w;

            ChaveEloCoordenada chave = null;

            w = Workbook.getWorkbook(dbInputStream);//error here

            Sheet sheet = w.getSheet(0);

            for (int r = 1; r < sheet.getRows(); r++) {
                chave = new ChaveEloCoordenada();
                row = sheet.getRow(r);
                if (row != null) {
                    for (int c = 0; c < cols; c++) {
                        cell = sheet.getCell(c, r);
                        if (cell != null) {
                            if (c == 0) {
                                chave.setBarramento(cell.getContents());
                            } else if (c == 1) {
                                chave.setCoordX(cell.getContents());
                            } else if (c == 2) {
                                chave.setCoordY(cell.getContents());
                            } else if (c == 3) {
                                chave.setPlaca(cell.getContents());
                            } else if (c == 4) {
                                chave.setTipo(cell.getContents());
                            } else if (c == 5) {
                                chave.setSe(cell.getContents());
                            } else if (c == 6) {
                                chave.setAlim(cell.getContents());
                            } else if (c == 7) {
                                chave.setElo(cell.getContents());
                            } else if (c == 8) {
                                chave.setTipoElo(cell.getContents());
                            }
                        }
                    }
                    list.add(chave);
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        } catch (BiffException e) {
            e.printStackTrace();
        }
        return list;
    }

}

Any idea how to fix this problem?

Thanks!

Edit

Below is the exception

java.io.IOException
at android.content.res.AssetManager.readAsset(Native Method)
at android.content.res.AssetManager.access$700(AssetManager.java:36)
at android.content.res.AssetManager$AssetInputStream.read(AssetManager.java:571)
at jxl.read.biff.File.<init>(File.java:91)
at jxl.Workbook.getWorkbook(Workbook.java:268)
at jxl.Workbook.getWorkbook(Workbook.java:253)

If I put the above code in a java project works normally!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:38:11+00:00Added an answer on June 12, 2026 at 11:38 pm

    Thanks to everyone who tried to help me!

    The problem was that the file I was trying to read exceeded the size supported by the android. The excel file had 9.4 mb and it seems the android files read only a little more than 1MB in the assets folder.

    So the solution I found that maybe was not the best, manually copy the data from xls file to a txt file, compress this file with gzip and then read the compressed file and then read the txt file and thus save all information I needed (over 50,000 records) in the database!
    Follow the code below:

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
               scriptChaveEloCoordenada(db);        
        }
    
    public void scriptChaveEloCoordenada(SQLiteDatabase db) {
    
            List<ChaveEloCoordenada> list = ReadExcel.read(context);
    
            for (ChaveEloCoordenada chave : list) {
                db.execSQL(insertChaveEloCoordenadas(chave.getBarramento(), chave.getCoordX(),chave.getCoordY(),chave.getPlaca(),
                                                     chave.getTipo(),chave.getSe(),chave.getAlim(),chave.getElo(),chave.getTipoElo()));
            }       
    
        }
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.Reader;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.zip.GZIPInputStream;
    
    import business.coordinate;
    import android.content.Context;
    
        public class ReadExcel {
    
            public static List<ChaveEloCoordenada> read(Context context) {
                List<ChaveEloCoordenada> list = new ArrayList<ChaveEloCoordenada>();
                ChaveEloCoordenada chave = null;
                String line;
                int i = 0;
                String split[] = null;
    
                try {
                    InputStream is = context.getAssets().open("file.zip");
    
                    InputStream gzipStream = new GZIPInputStream(is);
                    Reader decoder = new InputStreamReader(gzipStream, "UTF-8");
                    BufferedReader buffered = new BufferedReader(decoder);
    
                    while((line = buffered.readLine()) != null) {
                        i++;
                        chave = new ChaveEloCoordenada();
                        split = line.split("\t");
                        chave.setBarramento(split[0]);
                        chave.setCoordX(split[1]);
                        chave.setCoordY(split[2]);
                        chave.setPlaca(split[3]);
                        chave.setTipo(split[4]);
                        chave.setSe(split[5]);
                        chave.setAlim(split[6]);
                        if (split.length > 7 ) {
                            chave.setElo(split[7]);
                            chave.setTipoElo(split[8]);
                        }
                        list.add(chave);
                    }
                    buffered.close();
                    System.out.println("TOTAL = " + i);
                }
                catch (final IOException ioe) {
                    System.err.println("Unhandled exception:");
                    ioe.printStackTrace();
                    return list;
                }
    
                return list;
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below sets a select menu with UI selectmenu by $('.anyclass').selectmenu(); but the
The code below will validate required fields within currently visible fieldsets, but only if
The code below works, but the whole main view is replaced for the chart
The code below came as an included file with a beginner puzzle app tutorial
Code below works but what doesn't work properly is delaying process because I don't
The code below works, but I suspect there is be a cleaner. Any alternative
My code below kinda works, it creates the User object and saves but it
The code below scans through the current folder for word documents and then spits
Code below redirects stdout to a file fname & then redirects back to original
Code below works fine in FF, CH etc. but doesn't get centred in IE.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.