Friday, 15 May 2015

sqlite - reading excel sheet from assets folder in android -


How to read the data in Excel sheet in each folder and database to retrieve? "I want to have an excel sheet that says your individual tables of the database and I want to read in the Excel sheet to be stored in the database and then the database

Public Square ReadFileAssetsActivity Extends ActionBarActivity {

  Personal Button btnReadExcel1; Asset Manager Property Manager; @ Override Protected Zero (Bundle Saved Instantstate) {Super. NET (Saved Instantstate); SetContentView (R.layout.main); BtnReadExcel1 = (button) Find ViewById (R.id.btnReadExcel1); btnReadExcel1.setOnClickListener (New View.OnClickListener () {@Override see public void onClick (v) {// TODO Auto-generated method stub if (v.getId () == R.id.btnReadExcel1) readExcelFileFromAssets ();}} ); {AssetManager = getAssets (); }} Public void readExcelFileFromAssets () {try {// input stream file = new File ( "file: \\ home \\ Winthrop- mobile-data-test records.xls") is being made; FileInputStream myInput = New FileInputStream (file) // // InputStream myInput; // myInput = assetManager.open ("Main Table .xlsx"); // Create a POIFSFileSystem objectPOIFSFileSystem myFileSystem = new POIFSFileSystem (myInput); // File System HSSFWorkbook myWorkBook = Create a workbook using the new HSSFWorkbook (myFileSystem); // Get the first sheet from the workbook HSSFSheet mySheet = myWorkBook.getSheetAt (0); / ** We now need something to do through the cells again. ** / Iterator & lieutenant; Row & gt; Line writer = mySheet.rowIterator (); While (rowIter.hasNext ()) {HSSFRow myRow = (HSSFRow) rowEter.next (); Iterator & LT; Cell & gt; Cellir = myRow.cellIterator (); While (celleter. HasNext ()) {HSSFCell myCell = (HSSFCell) cellIter.next (); Log.e ( "FileUtils", "Cell value:" + myCell.toString () + "Index:" + myCell.getColumnIndex ()); // Toast.makeText (getApplicationContext (), "Cell value:" + // myCell.toString (), Toast.LENGTH_SHORT) .show (); }}} Hold (exception e) {e.printStackTrace (); } Return; } ''  


No comments:

Post a Comment