Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ExcelCreator {
- private static String[] columns = { "Nom du produit", "Prix de produit", "Quantite",
- "Prix de la commande" };
- public static FileOutputStream ExcelGen(List<Produit_Panier> pp) throws IOException {
- Workbook workbook = new XSSFWorkbook();
- Sheet sheet = workbook.createSheet("Report");
- Font headerFont = workbook.createFont();
- headerFont.setBold(true);
- headerFont.setFontHeightInPoints((short) 14);
- headerFont.setColor(IndexedColors.RED.getIndex());
- CellStyle headerCellStyle = workbook.createCellStyle();
- headerCellStyle.setFont(headerFont);
- // Create a Row
- Row headerRow = sheet.createRow(0);
- for (int i = 0; i < columns.length; i++) {
- Cell cell = headerRow.createCell(i);
- cell.setCellValue(columns[i]);
- cell.setCellStyle(headerCellStyle);
- }
- // Create Other rows and cells with contacts data
- int rowNum = 1;
- for (Produit_Panier p : pp) {
- Row row = sheet.createRow(rowNum++);
- row.createCell(0).setCellValue(p.getProduit().getNomProduit());
- row.createCell(1).setCellValue(p.getProduit().getPrix());
- row.createCell(2).setCellValue(p.getQte());
- row.createCell(3).setCellValue(p.getQte()*p.getProduit().getPrix());
- }
- // Resize all columns to fit the content size
- for (int i = 0; i < columns.length; i++) {
- sheet.autoSizeColumn(i);
- }
- // Write the output to a file
- FileOutputStream fileOut = new FileOutputStream("ReportPanier.xlsx");
- workbook.write(fileOut);
- fileOut.close();
- return fileOut;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement