/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package planilha;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
/**
*
* @author Usuario
*/
public class Planilha {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
FileInputStream imp =null;
FileOutputStream arquivo=null;
Workbook work=null;
try{
imp = new FileInputStream("C:\\Users\\Usuario\\Documents\\Meus arquivos recebidos\\teste.xlsx");
work = WorkbookFactory.create(imp);
Sheet sheet= work.getSheet("Sheet1");
Row row= sheet.createRow(0);
Cell cell= row.createCell(0);
cell.setCellValue("Olá");
Cell cell1=row.createCell(1);
cell1.setCellValue("2");
arquivo=new FileOutputStream("C:\\Users\\Usuario\\Documents\\Meus arquivos recebidos\\teste.xlsx");
work.write(arquivo);
}
catch(Exception e){
System.out.println("error");
}
finally{
imp.close();
arquivo.close();
}
}
}
Exception in thread "main" java.lang.NullPointerException
at planilha.Planilha.main(Planilha.java:53)
Java Result: 1
CONSTRUÍDO COM SUCESSO (tempo total: 6 segundos)