Created
October 1, 2020 05:41
-
-
Save mistergamarra/469dcddf390f4a268a6455c0600bf6d2 to your computer and use it in GitHub Desktop.
Useful to create and transform WorkBooks in to byte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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