1

I am using this code in my project. I need to read .xls which i have placed in my raw folder. ReadExcel test = new ReadExcel();

 test.setInputFile(BitmapFactory.decodeStream(getClass().getResourceAsStream(("/SPPDashProject/res/raw/aging_busket_key.xls"))).toString()); try { test.read(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); 

}

public class ReadExcel { private String inputFile; public void setInputFile(String inputFile) { this.inputFile = inputFile; } public void read() throws IOException { File inputWorkbook = new File(inputFile); Workbook w; try { w = Workbook.getWorkbook(inputWorkbook); // Get the first sheet Sheet sheet = w.getSheet(0); // Loop over first 10 column and lines for (int j = 0; j < sheet.getColumns(); j++) { for (int i = 0; i < sheet.getRows(); i++) { Cell cell = sheet.getCell(j, i); CellType type = cell.getType(); if (cell.getType() == CellType.LABEL) { System.out.println("I got a label: " + cell.getContents()); } if (cell.getType() == CellType.NUMBER) { System.out.println("I got a number " + cell.getContents()); } } } } catch (BiffException e) { e.printStackTrace(); } } } 

what path should i give as my main read class takes path in string format.Plz suggest

2 Answers 2

1

You can use the following code:

 Uri uri=Uri.parse("android.resource://com.mypackage.myapp" + R.raw.MyXLS); String filePath=uri.getPath(); 
Sign up to request clarification or add additional context in comments.

1 Comment

com.mypackage.myapp is the package name defined in menifest or some thing addition i need to add
1

You should use the following code to open file in the /res/raw
getResources().openRawResource(R.raw.yourfilename)
You can put your file in the assets folder and use AssetManager to acess it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.