How to read data in excel-sheet in assets folder and retrieve database? "I have an excel sheet where my different database tables are written, and I want to read the excel sheet to save it in the database, and then I want to get the database
public class ReadFileAssetsActivity extends ActionBarActivity {
private Button btnReadExcel1;
AssetManager assetManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnReadExcel1 = (Button) findViewById(R.id.btnReadExcel1);
btnReadExcel1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v.getId() == R.id.btnReadExcel1)
readExcelFileFromAssets();
}
}); {
assetManager = getAssets();
}
}
public void readExcelFileFromAssets() {
try {
File file = new File( "file:\\assets\\winthrop-mobile-data-test-records.xls");
FileInputStream myInput = new
FileInputStream(file)
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
HSSFSheet mySheet = myWorkBook.getSheetAt(0);
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.e("FileUtils", "Cell Value: " + myCell.toString()
+ " Index :" + myCell.getColumnIndex());
" + // myCell.toString(), Toast.LENGTH_SHORT).show();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return;
}'
source
share