2

I am trying to develop an application where I want to pick only .xls/.xlsx file and I want to read the data from it..how should I achieve it?

I wrote code below ..but it allows me to pick up all type of data.`

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btnpurchase=(Button)findViewById(R.id.btnpurchase);
    btnsales=(Button)findViewById(R.id.btnsales);


    btnpurchase.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("application/xlsx");
            startActivityForResult(intent, 7);
        }
    });

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub

    switch(requestCode){

        case 7:

            if(resultCode==RESULT_OK){

                String PathHolder = data.getData().getPath();

                Toast.makeText(MainActivity.this, PathHolder , Toast.LENGTH_LONG).show();

            }
            break;

    }
}
Aditi Parikh
  • 1,522
  • 3
  • 13
  • 34
Navas
  • 61
  • 11

1 Answers1

2

You can refer a list of Microsoft Office MIME from here https://stackoverflow.com/a/4212908/3283376

.xls file

application/vnd.ms-excel

.xlsx file

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

I think they are that what you want.

Vinh Nguyen
  • 610
  • 7
  • 16
  • after using application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet now i can choose only xlsx..how can i read data from it? – Navas Oct 02 '17 at 11:04