Reputation: 267
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
Upvotes: 1
Views: 813
Reputation: 197
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.
Upvotes: 1
Reputation: 72321
You can use the following code:
Uri uri=Uri.parse("android.resource://com.mypackage.myapp" + R.raw.MyXLS);
String filePath=uri.getPath();
Upvotes: 1