Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从android中的资产文件夹读取excel工作表_Android_Sqlite - Fatal编程技术网

从android中的资产文件夹读取excel工作表

从android中的资产文件夹读取excel工作表,android,sqlite,Android,Sqlite,如何读取资产文件夹中excel工作表中的数据并检索数据库? '我有一个excel工作表,其中写入了不同的数据库表,我想读取excel工作表,以便将其存储在数据库中,然后检索数据库 公共类ReadFileAssetActivity扩展了ActionBarActivity { private Button btnReadExcel1; AssetManager assetManager; @Override protected void onCreate(Bundle savedInstanceS

如何读取资产文件夹中excel工作表中的数据并检索数据库? '我有一个excel工作表,其中写入了不同的数据库表,我想读取excel工作表,以便将其存储在数据库中,然后检索数据库

公共类ReadFileAssetActivity扩展了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) {
            // TODO Auto-generated method stub
            if (v.getId() == R.id.btnReadExcel1) 

                readExcelFileFromAssets();
        }
    }); {


    assetManager = getAssets();

    }


}

public void readExcelFileFromAssets() {

    try {
        // Creating Input Stream

         File file = new File( "file:\\assets\\winthrop-mobile-data-test-records.xls");




       FileInputStream myInput = new
          FileInputStream(file)//





      //            InputStream myInput;



        // myInput = assetManager.open("main table.xlsx");



       // Create a POIFSFileSystem object


        POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);

        // Create a workbook using the File System

        HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);

        // Get the first sheet from workbook
        HSSFSheet mySheet = myWorkBook.getSheetAt(0);


           /** We now need something to iterate through the cells. 
   **/
          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());

                // Toast.makeText(getApplicationContext(), "cell Value: 

           " +  // myCell.toString(), Toast.LENGTH_SHORT).show();


            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return;
}'
专用按钮btnReadExcel1;
资产管理人资产管理人;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnReadExcel1=(按钮)findViewById(R.id.btnReadExcel1);
btnReadExcel1.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
if(v.getId()==R.id.btnReadExcel1)
readExcelFileFromAssets();
}
}); {
assetManager=getAssets();
}
}
public void readExcelFileFromAssets(){
试一试{
//创建输入流
File File=新文件(“文件:\\assets\\winthrop mobile data test records.xls”);
FileInputStream myInput=new
FileInputStream(文件)//
//输入流myInput;
//myInput=assetManager.open(“main table.xlsx”);
//创建一个POIFSSystem对象
POIFSFileSystem myFileSystem=新的POIFSFileSystem(myInput);
//使用文件系统创建工作簿
HSSFWorkbook myWorkBook=新的HSSFWorkbook(myFileSystem);
//从工作簿中获取第一张工作表
HSSFSheet mySheet=myWorkBook.getSheetAt(0);
/**我们现在需要一些东西来遍历单元格。
**/
迭代器rowIter=mySheet.rowitter();
while(rowIter.hasNext()){
HSSFRow myRow=(HSSFRow)rowIter.next();
迭代器cellIter=myRow.cellIterator();
while(cellIter.hasNext()){
HSSFCell myCell=(HSSFCell)cellIter.next();
Log.e(“FileUtils”,“单元格值:”+myCell.toString()
+索引:“+myCell.getColumnIndex());
//Toast.makeText(getApplicationContext(),“单元格值:
“+//myCell.toString(),Toast.LENGTH_SHORT).show();
}
}
}捕获(例外e){
e、 printStackTrace();
}
返回;
}'

//myInput=assetManager.open(“main table.xlsx”)
。这就是方法。你为什么尝试不使用它?你没有告诉我问题出在资产中的文件。如果它在文件系统上,你能处理所有问题吗?
将它存储在数据库中,然后想检索数据库
?请详细说明。不,我想在运行它时在日志cat上显示它在logi上没有显示我想在我的项目中使用的数据库的excel文件,然后我必须使用该数据库检索一些数据并在UI上显示