Skip to content

Instantly share code, notes, and snippets.

@mistergamarra
Created October 1, 2020 05:41
Show Gist options
  • Save mistergamarra/469dcddf390f4a268a6455c0600bf6d2 to your computer and use it in GitHub Desktop.
Save mistergamarra/469dcddf390f4a268a6455c0600bf6d2 to your computer and use it in GitHub Desktop.
Useful to create and transform WorkBooks in to byte
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Component;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@Component
public class FileCreator {
public XSSFSheet aperturarWorkbook(String nombreHoja) {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet(nombreHoja);
return sheet;
}
public byte[] crearExcel(XSSFWorkbook workbook) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
workbook.write(bos);
} catch (IOException e) {
System.err.println("");
} finally {
try {
bos.close();
workbook.close();
} catch (IOException e) {
System.err.println("");
}
}
return bos.toByteArray();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment