He separado el código como me has sugerido, y tengo el mismo problema, pego el código completo:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void share(View v) throws WriteException, IOException{
createXLS();
startActivity(Intent.createChooser((new Intent(Intent.ACTION_SEND).setType("application/excel")
.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(getFilesDir(),"ejemplo.xls")))),"Compartir via:"));
}
public void createXLS() throws RowsExceededException,WriteException, IOException{
FileOutputStream file=openFileOutput("ejemplo.xls",Context.MODE_WORLD_WRITEABLE);
WorkbookSettings wbSettings=new WorkbookSettings();
wbSettings.setLocale(new Locale("es","ES"));
WritableWorkbook wb=Workbook.createWorkbook(file,wbSettings);
wb.createSheet("cuentas",0);
WritableSheet sheet=wb.getSheet(0);
WritableCellFormat times=new WritableCellFormat(new WritableFont(WritableFont.TIMES,20));
times.setWrap(true);
WritableCellFormat timesBoldUnderline=new WritableCellFormat(new WritableFont(WritableFont.TIMES,20,WritableFont.BOLD,false,UnderlineStyle.SINGLE));
timesBoldUnderline.setWrap(true);
sheet.addCell(new Label(0,0,"ID",timesBoldUnderline));
sheet.addCell(new Label(1,0,"Concepto",timesBoldUnderline));
sheet.addCell(new Label(2,0,"Fecha",timesBoldUnderline));
sheet.addCell(new Label(3,0,"Seccion",timesBoldUnderline));
sheet.addCell(new Label(4,0,"Importe",timesBoldUnderline));
wb.write();
wb.close();
file.close();
}
}
la libreria para crear el xls se llama jxl.jar
la captura que adjunto es para que veas los permisos del archivo creado a ver si están correctos.
Muchas gracias por la ayuda y el tiempo prestado, de verdad.