You are on page 1of 2

package com.example.exportar; import java.io.File; import java.io.

IOException; import import import import import import import import import import jxl.Workbook; jxl.write.Label; jxl.write.WritableSheet; jxl.write.WritableWorkbook; jxl.write.WriteException; jxl.write.biff.RowsExceededException; android.os.Bundle; android.os.Environment; android.app.Activity; android.view.Menu;

public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Grava(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void Grava(){ File file = new File(Environment.getExternalStorageDirectory() + File.separator + "MeuArquivoXLS.xls"); WritableWorkbook wb = null;{ try { wb = Workbook.createWorkbook(file); } catch (IOException e) { e.printStackTrace(); } wb.createSheet("Planilha", 0); WritableSheet plan = wb.getSheet(0); Label label = new Label(0,0,"Primeira clula"); // Como o mtodo pode levantar exceo // iremos coloca-lo dentro de um try/catch try { plan.addCell(label); } catch (RowsExceededException e11) { e11.printStackTrace(); } catch (WriteException e1) { e1.printStackTrace(); } try { wb.write();

} catch (IOException e) { e.printStackTrace(); } try { wb.close(); } catch (WriteException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } }