Navas Navas - 1 year ago 165
Android Question

Pick .xls / .xlsx and read its data

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;

}
}

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download