Example usage for org.apache.poi.ss.usermodel Workbook createCellStyle

List of usage examples for org.apache.poi.ss.usermodel Workbook createCellStyle

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Workbook createCellStyle.

Prototype

CellStyle createCellStyle();

Source Link

Document

Create a new Cell style and add it to the workbook's style table

Usage

From source file:com.hp.idc.resm.util.ExcelUtil.java

License:Open Source License

/**
 * , Excel//  w  w  w.j  av a  2s  .c o m
 * 
 * @param modelId
 *            Id
 * @return Excel
 */
public String getResouceDataToExcel(String modelId) {
    Model m = ServiceManager.getModelService().getModelById(modelId);

    List<ResourceObject> l = ServiceManager.getResourceService().getResourcesByModelId(modelId, 1);

    List<ModelAttribute> mas = m.getAttributes();
    Workbook wb = new HSSFWorkbook();
    CellStyle style = wb.createCellStyle();
    Font font = wb.createFont();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    font.setFontHeightInPoints((short) 12);
    font.setFontName("");
    style.setFont(font);
    Sheet sheet = wb.createSheet(modelId);
    Row row = sheet.createRow(0);
    int i = 0;
    HSSFRichTextString textString;
    for (ModelAttribute ma : mas) {
        Cell cell = row.createCell(i);
        textString = new HSSFRichTextString(ma.getDefine().getName());
        cell.setCellStyle(style);
        cell.setCellValue(textString);
        i++;
    }
    i = 1;
    for (ResourceObject ro : l) {
        row = sheet.createRow(i);
        int j = 0;
        for (ModelAttribute ma : mas) {
            textString = new HSSFRichTextString(ro.getAttributeValue(ma.getAttrId()));
            row.createCell(j).setCellValue(textString);
            j++;
        }
        i++;
    }

    for (int k = 0; k < mas.size(); k++) {
        sheet.autoSizeColumn(k);
    }

    // Write the output to a file
    FileOutputStream fileOut;
    String file;
    try {
        file = System.getProperty("user.dir") + "/../temp/" + modelId + new Random().nextLong() + "_data.xls";
        fileOut = new FileOutputStream(file);
        wb.write(fileOut);
        fileOut.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return "";
    } catch (IOException e) {
        e.printStackTrace();
        return "";
    }
    return file;
}

From source file:com.ideaspymes.proyecttemplate.stock.web.ProductoConsultaBean.java

@Override
public Workbook getWorkBook() {
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = wb.createSheet("My Sample Excel");
    List<CatalogoProductos> lista = (List<CatalogoProductos>) getDetalles();

    sheet.setDefaultRowHeight((short) (sheet.getDefaultRowHeight() * new Short("6")));

    org.apache.poi.ss.usermodel.Font fontTitulo = wb.createFont();
    fontTitulo.setFontHeightInPoints((short) 12);
    fontTitulo.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD);

    org.apache.poi.ss.usermodel.Font fontTituloPricipal = wb.createFont();
    fontTituloPricipal.setFontHeightInPoints((short) 22);
    fontTituloPricipal.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD);

    DataFormat format = wb.createDataFormat();

    CellStyle styleTituloPrincipal = wb.createCellStyle();
    styleTituloPrincipal.setFont(fontTituloPricipal);
    styleTituloPrincipal.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    styleTituloPrincipal.setAlignment(CellStyle.ALIGN_CENTER);

    CellStyle styleTitulo = wb.createCellStyle();
    styleTitulo.setFont(fontTitulo);//from  w ww .j a v a  2s .c  om
    styleTitulo.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    styleTitulo.setFillForegroundColor(IndexedColors.BLUE_GREY.getIndex());
    styleTitulo.setFillPattern(CellStyle.SOLID_FOREGROUND);
    styleTitulo.setWrapText(true);

    CellStyle styleNumero = wb.createCellStyle();
    styleNumero.setDataFormat(format.getFormat("#,##0"));
    styleNumero.setWrapText(true);
    styleNumero.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    styleNumero.setAlignment(CellStyle.ALIGN_CENTER);

    CellStyle styleFecha = wb.createCellStyle();
    styleFecha.setDataFormat(format.getFormat("dd/MM/yyyy"));
    styleFecha.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    styleFecha.setAlignment(CellStyle.ALIGN_CENTER);

    CellStyle style = wb.createCellStyle();
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setWrapText(true);

    CellStyle styleCenter = wb.createCellStyle();
    styleCenter.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    styleCenter.setAlignment(CellStyle.ALIGN_CENTER);
    styleCenter.setWrapText(true);

    Row rowTitle = sheet.createRow(0);
    Cell cellTitle = rowTitle.createCell(1);
    cellTitle.setCellStyle(styleTituloPrincipal);

    sheet.addMergedRegion(new CellRangeAddress(0, //first row (0-based)
            1, //last row  (0-based)
            1, //first column (0-based)
            11 //last column  (0-based)
    ));

    cellTitle.setCellValue("Listado de Activos");

    int i = 2;

    Row row0 = sheet.createRow(i);
    row0.setHeight((short) 500);

    Cell cell1 = row0.createCell(1);
    cell1.setCellValue("Foto");
    cell1.setCellStyle(styleTitulo);

    Cell cellFecha = row0.createCell(3);
    cellFecha.setCellValue("Fecha Ingreso");
    cellFecha.setCellStyle(styleTitulo);

    Cell cellFechaCarga = row0.createCell(4);
    cellFechaCarga.setCellValue("Fecha Carga");
    cellFechaCarga.setCellStyle(styleTitulo);

    Cell cell3 = row0.createCell(5);
    cell3.setCellValue("Nombre");
    cell3.setCellStyle(styleTitulo);

    Cell cell4 = row0.createCell(6);
    cell4.setCellValue("Cdigo");
    cell4.setCellStyle(styleTitulo);

    Cell cell5 = row0.createCell(7);
    cell5.setCellValue("Descripcin");
    cell5.setCellStyle(styleTitulo);

    Cell cell6 = row0.createCell(8);
    cell6.setCellValue("Es Regalo?");
    cell6.setCellStyle(styleTitulo);

    Cell cell7 = row0.createCell(9);
    cell7.setCellValue("Familia");
    cell7.setCellStyle(styleTitulo);

    Cell cell8 = row0.createCell(10);
    cell8.setCellValue("Ubicaciones");
    cell8.setCellStyle(styleTitulo);

    Cell cell9 = row0.createCell(11);
    cell9.setCellValue("Stock");
    cell9.setCellStyle(styleTitulo);

    for (CatalogoProductos cp : lista) {

        int indexFila = i + 1;
        if (cp.getImagen() != null) {
            int pictureIdx = wb.addPicture(cp.getImagen(), Workbook.PICTURE_TYPE_PNG);
            CreationHelper helper = wb.getCreationHelper();

            //Creates the top-level drawing patriarch.
            Drawing drawing = sheet.createDrawingPatriarch();

            //Create an anchor that is attached to the worksheet
            ClientAnchor anchor = helper.createClientAnchor();
            //set top-left corner for the image
            anchor.setCol1(1);
            anchor.setRow1(indexFila);

            //Creates a picture
            Picture pict = drawing.createPicture(anchor, pictureIdx);
            //Reset the image to the original size
            pict.resize(0.4);
        }
        Row row1 = sheet.createRow(indexFila);
        row1.setHeightInPoints(80f);

        Cell cellColFecha = row1.createCell(3);

        if (cp.getFecha() != null) {
            cellColFecha.setCellValue(cp.getFecha());
            cellColFecha.setCellStyle(styleFecha);

        } else {
            cellColFecha.setCellValue("");
            cellColFecha.setCellStyle(styleFecha);
        }

        Cell cellColFechaCarga = row1.createCell(4);

        if (cp.getFechaCarga() != null) {
            cellColFechaCarga.setCellValue(cp.getFechaCarga());
            cellColFechaCarga.setCellStyle(styleFecha);

        } else {
            cellColFechaCarga.setCellValue("");
            cellColFechaCarga.setCellStyle(styleFecha);
        }

        Cell cellCol1 = row1.createCell(5);
        cellCol1.setCellValue(cp.getProducto());
        cellCol1.setCellStyle(style);

        Cell cellCol2 = row1.createCell(6);
        cellCol2.setCellValue(cp.getCodigo());
        cellCol2.setCellStyle(styleNumero);

        Cell cellCol3 = row1.createCell(7);
        cellCol3.setCellValue(cp.getDescripcion());
        cellCol3.setCellStyle(style);

        Cell cellCol4 = row1.createCell(8);
        cellCol4.setCellValue(cp.isEsRegalo() ? "SI" : "NO");
        cellCol4.setCellStyle(styleCenter);

        Cell cellCol5 = row1.createCell(9);
        cellCol5.setCellValue(cp.getFamilia());
        cellCol5.setCellStyle(style);

        Cell cellCol6 = row1.createCell(10);
        cellCol6.setCellValue(cp.getUbicaciones());
        cellCol6.setCellStyle(style);

        Cell cellCol7 = row1.createCell(11);
        cellCol7.setCellValue(cp.getStock());
        cellCol7.setCellStyle(styleNumero);

        i++;

    }

    sheet.setColumnWidth(1, 4000);
    sheet.setColumnWidth(2, 0);
    sheet.setColumnWidth(3, 4000);
    sheet.setColumnWidth(4, 4000);
    sheet.setColumnWidth(5, 10000);
    sheet.setColumnWidth(6, 3000);
    sheet.setColumnWidth(7, 10000);
    sheet.setColumnWidth(8, 3500);
    sheet.setColumnWidth(9, 6000);
    sheet.setColumnWidth(10, 10000);
    sheet.setColumnWidth(11, 2000);

    return wb;
}

From source file:com.inet.web.service.spi.download.ExportEmailWriterSpiService.java

License:Open Source License

/**
 * Export email of domain//from   ww w .j  ava 2  s.  co m
 * 
 * @param contacts
 * @return
 * @throws WebOSException
 */
private byte[] exportDomain(AccountExport accountExport) throws WebOSException {
    try {

        Workbook workbook = new HSSFWorkbook();
        // style
        CellStyle style = workbook.createCellStyle();
        style.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index);

        // sheet config
        Sheet sheet = workbook.createSheet("Email list");
        PrintSetup printSetup = sheet.getPrintSetup();
        printSetup.setLandscape(true);
        sheet.setFitToPage(true);
        sheet.setHorizontallyCenter(true);

        writeHeaderEmail(sheet);

        Map<LdapGroup, List<AccountExportInfo>> map = accountExport.getMap();
        for (LdapGroup group : map.keySet()) {
            writeGroup(sheet, group, accountExport.getDomain(), map.get(group), style);
        }

        ByteArrayOutputStream output = new ByteArrayOutputStream();
        workbook.write(output);
        output.close();

        return output.toByteArray();
    } catch (Exception e) {
        e.printStackTrace();
        throw new WebOSException(e.getMessage(), e);
    }
}

From source file:com.jeans.iservlet.controller.impl.ExportController.java

/**
 * ?????//w ww .  j a  va2s .c om
 * 
 * @param storedOnly
 *            ???
 * @return
 * @throws IOException
 */
@RequestMapping(method = RequestMethod.POST, value = "/accessories")
public ResponseEntity<byte[]> exportAccessories(@RequestParam boolean storedOnly) throws IOException {
    StringBuilder fn = new StringBuilder(getCurrentCompany().getName());
    Date n = new Date();
    String today = (new SimpleDateFormat("yyyyMMdd")).format(n);
    String now = (new SimpleDateFormat("yyyy-MM-dd HHmmss")).format(n);
    Workbook wb = new XSSFWorkbook();
    fn.append(" - ???(").append(today).append(").xlsx");
    Sheet sheet = wb.createSheet(now);
    // 
    // ?10??
    Font font = wb.createFont();
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setFontName("");
    font.setFontHeightInPoints((short) 10);
    // ?????????
    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
    cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cellStyle.setFont(font);
    cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    cellStyle.setWrapText(false);
    // 20
    Row row = sheet.createRow(0);
    row.setHeightInPoints(20);
    Cell cell = null;
    for (int i = 0; i < 7; i++) {
        cell = row.createCell(i, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(ACS_HEADERS[i]);
        sheet.setColumnWidth(i, ACS_HEADERS_WIDTH[i] * 256);
    }
    List<Accessory> acs = acsService.listAccessories(getCurrentCompany(), storedOnly);
    Collections.sort(acs, new Comparator<Accessory>() {

        @Override
        public int compare(Accessory o1, Accessory o2) {
            int ret = o1.getType().compareTo(o2.getType());
            if (ret == 0) {
                ret = Collator.getInstance(java.util.Locale.CHINA).compare(o1.getName(), o2.getName());
                if (ret == 0) {
                    ret = Collator.getInstance(java.util.Locale.CHINA).compare(o1.getBrand(), o2.getBrand());
                    if (ret == 0) {
                        ret = Collator.getInstance(java.util.Locale.CHINA).compare(o1.getModel(),
                                o2.getModel());
                    }
                }
            }
            return ret;
        }

    });
    // 
    DataFormat df = wb.createDataFormat();
    // ?10?
    Font dFont = wb.createFont();
    dFont.setFontName("");
    dFont.setFontHeightInPoints((short) 10);
    // ?1???????
    CellStyle cellStyleString = wb.createCellStyle();
    cellStyleString.setAlignment(CellStyle.ALIGN_CENTER);
    cellStyleString.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cellStyleString.setFont(dFont);
    cellStyleString.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    cellStyleString.setWrapText(false);
    // ?2??????(#)???
    CellStyle cellStyleQuantity = sheet.getWorkbook().createCellStyle();
    cellStyleQuantity.setAlignment(CellStyle.ALIGN_RIGHT);
    cellStyleQuantity.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    cellStyleQuantity.setFont(dFont);
    cellStyleQuantity.setDataFormat(df.getFormat("#"));
    cellStyleQuantity.setWrapText(false);
    int rowNumber = 1;
    for (Accessory ac : acs) {
        // 20
        Row dRow = sheet.createRow(rowNumber);
        dRow.setHeightInPoints(20);
        Cell dCell = null;
        dCell = dRow.createCell(0, Cell.CELL_TYPE_STRING);
        dCell.setCellStyle(cellStyleString);
        dCell.setCellValue(ac.getType().getTitle());

        dCell = dRow.createCell(1, Cell.CELL_TYPE_STRING);
        dCell.setCellStyle(cellStyleString);
        dCell.setCellValue(ac.getName());

        dCell = dRow.createCell(2, Cell.CELL_TYPE_STRING);
        dCell.setCellStyle(cellStyleString);
        dCell.setCellValue(ac.getBrand());

        dCell = dRow.createCell(3, Cell.CELL_TYPE_STRING);
        dCell.setCellStyle(cellStyleString);
        dCell.setCellValue(ac.getModel());

        dCell = dRow.createCell(4, Cell.CELL_TYPE_NUMERIC);
        dCell.setCellStyle(cellStyleQuantity);
        dCell.setCellValue(null == ac.getStorage() ? 0 : ac.getStorage().getQuantity());

        dCell = dRow.createCell(5, Cell.CELL_TYPE_STRING);
        dCell.setCellStyle(cellStyleString);
        dCell.setCellValue(ac.getUnit());

        dCell = dRow.createCell(6, Cell.CELL_TYPE_STRING);
        dCell.setCellStyle(cellStyleString);
        dCell.setCellValue(ac.getDescription());

        rowNumber++;
    }
    String filename = null;
    if (isIE()) {
        filename = URLEncoder.encode(fn.toString(), "UTF-8").replaceAll("\\+", "%20");
    } else {
        filename = new String(fn.toString().getBytes("UTF-8"), "iso8859-1");
    }
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    response.setHeader("Content-disposition", "attachment; filename=" + filename);
    BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream(), 4096);
    wb.write(out);
    wb.close();
    out.close();

    return null;
}

From source file:com.jeans.iservlet.controller.impl.ExportController.java

/**
 * ????/*w ww.  j ava2 s .  c o  m*/
 * 
 * @param ids
 *            ???(AccessoryEntryInvoice.id)?
 * @return
 * @throws IOException
 */
private void exportAccessoryEntries(List<Long> idList) throws IOException {
    StringBuilder fn = new StringBuilder(getCurrentCompany().getName());
    fn.append(" - ????.xlsx");
    Workbook wb = new XSSFWorkbook();
    DataFormat df = wb.createDataFormat();
    // ?10??
    Font bFont = wb.createFont();
    bFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    bFont.setFontName("");
    bFont.setFontHeightInPoints((short) 10);
    // ?10?
    Font nFont = wb.createFont();
    nFont.setFontName("");
    nFont.setFontHeightInPoints((short) 10);
    // ??1???????
    CellStyle csLeftTextBold = wb.createCellStyle();
    csLeftTextBold.setAlignment(CellStyle.ALIGN_LEFT);
    csLeftTextBold.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csLeftTextBold.setFont(bFont);
    csLeftTextBold.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    csLeftTextBold.setWrapText(false);
    // ??2???????
    CellStyle csLeftText = wb.createCellStyle();
    csLeftText.setAlignment(CellStyle.ALIGN_LEFT);
    csLeftText.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csLeftText.setFont(nFont);
    csLeftText.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    csLeftText.setWrapText(false);
    // ??3???????
    CellStyle csLeftTime = wb.createCellStyle();
    csLeftTime.setAlignment(CellStyle.ALIGN_LEFT);
    csLeftTime.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csLeftTime.setFont(nFont);
    csLeftTime.setDataFormat(df.getFormat("yyyy-MM-dd HH:mm"));
    csLeftTime.setWrapText(false);
    // ??4???????
    CellStyle csCenterTextBold = wb.createCellStyle();
    csCenterTextBold.setAlignment(CellStyle.ALIGN_CENTER);
    csCenterTextBold.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csCenterTextBold.setFont(bFont);
    csCenterTextBold.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    csCenterTextBold.setWrapText(false);
    // ??5???????
    CellStyle csCenterText = wb.createCellStyle();
    csCenterText.setAlignment(CellStyle.ALIGN_CENTER);
    csCenterText.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csCenterText.setFont(nFont);
    csCenterText.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    csCenterText.setWrapText(false);
    // ??6???????
    CellStyle csCenterNumber = wb.createCellStyle();
    csCenterNumber.setAlignment(CellStyle.ALIGN_CENTER);
    csCenterNumber.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csCenterNumber.setFont(nFont);
    csCenterNumber.setDataFormat(df.getFormat("#"));
    csCenterNumber.setWrapText(false);
    // ??7????8????
    CellStyle csLeftId = wb.createCellStyle();
    csLeftId.setAlignment(CellStyle.ALIGN_LEFT);
    csLeftId.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csLeftId.setFont(nFont);
    csLeftId.setDataFormat(df.getFormat("#00000000"));
    csLeftId.setWrapText(false);
    // ??8???????
    CellStyle csCenterNumberBold = wb.createCellStyle();
    csCenterNumberBold.setAlignment(CellStyle.ALIGN_CENTER);
    csCenterNumberBold.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csCenterNumberBold.setFont(bFont);
    csCenterNumberBold.setDataFormat(df.getFormat("#"));
    csCenterNumberBold.setWrapText(false);
    // ???sheet
    for (long id : idList) {
        AccessoryEntryInvoice invoice = arService.loadEntryInvoice(id);
        if (null == invoice) {
            continue;
        }
        Sheet sheet = wb.createSheet("?#" + id);
        // ??xxxxxx
        Row row = sheet.createRow(0);
        row.setHeightInPoints(20);
        Cell cell = row.createCell(0, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(csLeftTextBold);
        cell.setCellValue("??");
        cell = row.createCell(1, Cell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(csLeftId);
        cell.setCellValue(id);
        // yyyy-MM-dd HH:mm
        row = sheet.createRow(1);
        row.setHeightInPoints(20);
        cell = row.createCell(0, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(csLeftTextBold);
        cell.setCellValue("");
        cell = row.createCell(1, Cell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(csLeftTime);
        cell.setCellValue(invoice.getTime());
        // xxx
        row = sheet.createRow(2);
        row.setHeightInPoints(20);
        cell = row.createCell(0, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(csLeftTextBold);
        cell.setCellValue("");
        cell = row.createCell(1, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(csLeftText);
        cell.setCellValue(invoice.getOperator().getName());
        // 
        row = sheet.createRow(3);
        row.setHeightInPoints(20);
        for (int i = 0; i < 8; i++) {
            cell = row.createCell(i, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csCenterTextBold);
            cell.setCellValue(ENT_HEADERS[i]);
            sheet.setColumnWidth(i, ENT_HEADERS_WIDTH[i] * 256);
        }
        // 
        List<AccessoryEntry> entries = invoice.getEntries();
        int rowNumber = 4;
        int totalQuantity = 0;
        int totalRemained = 0;
        for (AccessoryEntry entry : entries) {
            Accessory acs = entry.getAccessory();
            row = sheet.createRow(rowNumber);
            row.setHeightInPoints(20);
            cell = row.createCell(0, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csCenterText);
            cell.setCellValue(acs.getType().getTitle());
            cell = row.createCell(1, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csCenterText);
            cell.setCellValue(acs.getName());
            cell = row.createCell(2, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csCenterText);
            cell.setCellValue(acs.getBrand());
            cell = row.createCell(3, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csCenterText);
            cell.setCellValue(acs.getModel());
            cell = row.createCell(4, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csCenterText);
            cell.setCellValue(acs.getDescription());
            cell = row.createCell(5, Cell.CELL_TYPE_NUMERIC);
            cell.setCellStyle(csCenterNumber);
            cell.setCellValue(entry.getQuantity());
            totalQuantity += entry.getQuantity();
            cell = row.createCell(6, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csCenterText);
            cell.setCellValue(acs.getUnit());
            cell = row.createCell(7, Cell.CELL_TYPE_NUMERIC);
            cell.setCellStyle(csCenterNumber);
            cell.setCellValue(entry.getRemained());
            totalRemained += entry.getRemained();
            rowNumber++;
        }
        // ?
        row = sheet.createRow(rowNumber);
        row.setHeightInPoints(20);
        cell = row.createCell(0, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(csCenterTextBold);
        cell.setCellValue("?");
        cell = row.createCell(1, Cell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(csCenterNumberBold);
        cell.setCellValue(entries.size());
        cell = row.createCell(5, Cell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(csCenterNumberBold);
        cell.setCellValue(totalQuantity);
        cell = row.createCell(7, Cell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(csCenterNumberBold);
        cell.setCellValue(totalRemained);
    }

    String filename = null;
    if (isIE()) {
        filename = URLEncoder.encode(fn.toString(), "UTF-8").replaceAll("\\+", "%20");
    } else {
        filename = new String(fn.toString().getBytes("UTF-8"), "iso8859-1");
    }
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    response.setHeader("Content-disposition", "attachment; filename=" + filename);
    BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream(), 4096);
    wb.write(out);
    wb.close();
    out.close();
}

From source file:com.jeans.iservlet.controller.impl.ExportController.java

/**
 * ????/*from  w w  w  . j a  va 2  s .co  m*/
 * 
 * @param ids
 *            ???(AccessoryDischargeInvoice.id)?
 * @return
 * @throws IOException
 */
private void exportAccessoryDischarges(List<Long> idList) throws IOException {
    StringBuilder fn = new StringBuilder(getCurrentCompany().getName());
    fn.append(" - ????.xlsx");
    Workbook wb = new XSSFWorkbook();
    DataFormat df = wb.createDataFormat();
    // ?10??
    Font bFont = wb.createFont();
    bFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    bFont.setFontName("");
    bFont.setFontHeightInPoints((short) 10);
    // ?10?
    Font nFont = wb.createFont();
    nFont.setFontName("");
    nFont.setFontHeightInPoints((short) 10);
    // ??1???????
    CellStyle csLeftTextBold = wb.createCellStyle();
    csLeftTextBold.setAlignment(CellStyle.ALIGN_LEFT);
    csLeftTextBold.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csLeftTextBold.setFont(bFont);
    csLeftTextBold.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    csLeftTextBold.setWrapText(false);
    // ??2???????
    CellStyle csLeftText = wb.createCellStyle();
    csLeftText.setAlignment(CellStyle.ALIGN_LEFT);
    csLeftText.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csLeftText.setFont(nFont);
    csLeftText.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    csLeftText.setWrapText(false);
    // ??3???????
    CellStyle csLeftTime = wb.createCellStyle();
    csLeftTime.setAlignment(CellStyle.ALIGN_LEFT);
    csLeftTime.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csLeftTime.setFont(nFont);
    csLeftTime.setDataFormat(df.getFormat("yyyy-MM-dd HH:mm"));
    csLeftTime.setWrapText(false);
    // ??4???????
    CellStyle csCenterTextBold = wb.createCellStyle();
    csCenterTextBold.setAlignment(CellStyle.ALIGN_CENTER);
    csCenterTextBold.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csCenterTextBold.setFont(bFont);
    csCenterTextBold.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    csCenterTextBold.setWrapText(false);
    // ??5???????
    CellStyle csCenterText = wb.createCellStyle();
    csCenterText.setAlignment(CellStyle.ALIGN_CENTER);
    csCenterText.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csCenterText.setFont(nFont);
    csCenterText.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    csCenterText.setWrapText(false);
    // ??6???????
    CellStyle csCenterNumber = wb.createCellStyle();
    csCenterNumber.setAlignment(CellStyle.ALIGN_CENTER);
    csCenterNumber.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csCenterNumber.setFont(nFont);
    csCenterNumber.setDataFormat(df.getFormat("#"));
    csCenterNumber.setWrapText(false);
    // ??7????8????
    CellStyle csLeftId = wb.createCellStyle();
    csLeftId.setAlignment(CellStyle.ALIGN_LEFT);
    csLeftId.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csLeftId.setFont(nFont);
    csLeftId.setDataFormat(df.getFormat("#00000000"));
    csLeftId.setWrapText(false);
    // ??8???????
    CellStyle csCenterNumberBold = wb.createCellStyle();
    csCenterNumberBold.setAlignment(CellStyle.ALIGN_CENTER);
    csCenterNumberBold.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csCenterNumberBold.setFont(bFont);
    csCenterNumberBold.setDataFormat(df.getFormat("#"));
    csCenterNumberBold.setWrapText(false);
    // ???sheet
    for (long id : idList) {
        AccessoryDischargeInvoice invoice = arService.loadDischargeInvoice(id);
        if (null == invoice) {
            continue;
        }
        Sheet sheet = wb.createSheet("?#" + id);
        // ??xxxxxx
        Row row = sheet.createRow(0);
        row.setHeightInPoints(20);
        Cell cell = row.createCell(0, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(csLeftTextBold);
        cell.setCellValue("??");
        cell = row.createCell(1, Cell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(csLeftId);
        cell.setCellValue(id);
        // yyyy-MM-dd HH:mm
        row = sheet.createRow(1);
        row.setHeightInPoints(20);
        cell = row.createCell(0, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(csLeftTextBold);
        cell.setCellValue("");
        cell = row.createCell(1, Cell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(csLeftTime);
        cell.setCellValue(invoice.getTime());
        // xxx
        row = sheet.createRow(2);
        row.setHeightInPoints(20);
        cell = row.createCell(0, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(csLeftTextBold);
        cell.setCellValue("");
        cell = row.createCell(1, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(csLeftText);
        cell.setCellValue(invoice.getApplicant().getName());
        // xxx
        row = sheet.createRow(3);
        row.setHeightInPoints(20);
        cell = row.createCell(0, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(csLeftTextBold);
        cell.setCellValue("");
        cell = row.createCell(1, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(csLeftText);
        cell.setCellValue(invoice.getOperator().getName());
        // 
        row = sheet.createRow(4);
        row.setHeightInPoints(20);
        for (int i = 0; i < 7; i++) {
            cell = row.createCell(i, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csCenterTextBold);
            cell.setCellValue(DIS_HEADERS[i]);
            sheet.setColumnWidth(i, DIS_HEADERS_WIDTH[i] * 256);
        }
        // 
        List<AccessoryDischarge> discharges = invoice.getDischarges();
        int rowNumber = 5;
        int totalQuantity = 0;
        for (AccessoryDischarge discharge : discharges) {
            Accessory acs = discharge.getAccessory();
            row = sheet.createRow(rowNumber);
            row.setHeightInPoints(20);
            cell = row.createCell(0, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csCenterText);
            cell.setCellValue(acs.getType().getTitle());
            cell = row.createCell(1, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csCenterText);
            cell.setCellValue(acs.getName());
            cell = row.createCell(2, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csCenterText);
            cell.setCellValue(acs.getBrand());
            cell = row.createCell(3, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csCenterText);
            cell.setCellValue(acs.getModel());
            cell = row.createCell(4, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csCenterText);
            cell.setCellValue(acs.getDescription());
            cell = row.createCell(5, Cell.CELL_TYPE_NUMERIC);
            cell.setCellStyle(csCenterNumber);
            cell.setCellValue(discharge.getQuantity());
            totalQuantity += discharge.getQuantity();
            cell = row.createCell(6, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csCenterText);
            cell.setCellValue(acs.getUnit());
            rowNumber++;
        }
        // ?
        row = sheet.createRow(rowNumber);
        row.setHeightInPoints(20);
        cell = row.createCell(0, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(csCenterTextBold);
        cell.setCellValue("?");
        cell = row.createCell(1, Cell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(csCenterNumberBold);
        cell.setCellValue(discharges.size());
        cell = row.createCell(5, Cell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(csCenterNumberBold);
        cell.setCellValue(totalQuantity);
    }

    String filename = null;
    if (isIE()) {
        filename = URLEncoder.encode(fn.toString(), "UTF-8").replaceAll("\\+", "%20");
    } else {
        filename = new String(fn.toString().getBytes("UTF-8"), "iso8859-1");
    }
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    response.setHeader("Content-disposition", "attachment; filename=" + filename);
    BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream(), 4096);
    wb.write(out);
    wb.close();
    out.close();
}

From source file:com.jeans.iservlet.controller.impl.ExportController.java

/**
 * ?????// ww  w.j a va2 s  . com
 * 
 * @param ids
 *            ??(AccessoryInvoiceDetail.id)?
 * @return
 * @throws IOException
 */
private void exportAccessoryRegistries(List<Long> idList) throws IOException {
    StringBuilder fn = new StringBuilder(getCurrentCompany().getName());
    fn.append(" - ???.xlsx");
    Workbook wb = new XSSFWorkbook();
    DataFormat df = wb.createDataFormat();
    // ?10??
    Font bFont = wb.createFont();
    bFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    bFont.setFontName("");
    bFont.setFontHeightInPoints((short) 10);
    // ?10?
    Font nFont = wb.createFont();
    nFont.setFontName("");
    nFont.setFontHeightInPoints((short) 10);
    // ??1???????
    CellStyle csLeftTextBold = wb.createCellStyle();
    csLeftTextBold.setAlignment(CellStyle.ALIGN_LEFT);
    csLeftTextBold.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csLeftTextBold.setFont(bFont);
    csLeftTextBold.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    csLeftTextBold.setWrapText(false);
    // ??2???????
    CellStyle csLeftText = wb.createCellStyle();
    csLeftText.setAlignment(CellStyle.ALIGN_LEFT);
    csLeftText.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csLeftText.setFont(nFont);
    csLeftText.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    csLeftText.setWrapText(false);
    // ??3???????
    CellStyle csCenterTime = wb.createCellStyle();
    csCenterTime.setAlignment(CellStyle.ALIGN_CENTER);
    csCenterTime.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csCenterTime.setFont(nFont);
    csCenterTime.setDataFormat(df.getFormat("yyyy-MM-dd HH:mm"));
    csCenterTime.setWrapText(false);
    // ??4???????
    CellStyle csCenterTextBold = wb.createCellStyle();
    csCenterTextBold.setAlignment(CellStyle.ALIGN_CENTER);
    csCenterTextBold.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csCenterTextBold.setFont(bFont);
    csCenterTextBold.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    csCenterTextBold.setWrapText(false);
    // ??5???????
    CellStyle csCenterText = wb.createCellStyle();
    csCenterText.setAlignment(CellStyle.ALIGN_CENTER);
    csCenterText.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csCenterText.setFont(nFont);
    csCenterText.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    csCenterText.setWrapText(false);
    // ??6???????
    CellStyle csCenterNumber = wb.createCellStyle();
    csCenterNumber.setAlignment(CellStyle.ALIGN_CENTER);
    csCenterNumber.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csCenterNumber.setFont(nFont);
    csCenterNumber.setDataFormat(df.getFormat("#"));
    csCenterNumber.setWrapText(false);
    // ??7????8????
    CellStyle csLeftId = wb.createCellStyle();
    csLeftId.setAlignment(CellStyle.ALIGN_LEFT);
    csLeftId.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csLeftId.setFont(nFont);
    csLeftId.setDataFormat(df.getFormat("#00000000"));
    csLeftId.setWrapText(false);
    // ??8????8????
    CellStyle csCenterId = wb.createCellStyle();
    csCenterId.setAlignment(CellStyle.ALIGN_CENTER);
    csCenterId.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csCenterId.setFont(nFont);
    csCenterId.setDataFormat(df.getFormat("#00000000"));
    csCenterId.setWrapText(false);
    // ??9???????
    CellStyle csCenterNumberBold = wb.createCellStyle();
    csCenterNumberBold.setAlignment(CellStyle.ALIGN_CENTER);
    csCenterNumberBold.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    csCenterNumberBold.setFont(bFont);
    csCenterNumberBold.setDataFormat(df.getFormat("#"));
    csCenterNumberBold.setWrapText(false);
    // ????sheet
    long currAcsId = 0;
    Sheet sheet = null;
    int rowNumber = 0, totalIn = 0, totalOut = 0;
    for (long id : idList) {
        AccessoryInvoiceDetail registry = arService.loadRegistry(id);
        if (null == registry) {
            continue;
        }
        Accessory acs = registry.getAccessory();
        if (acs.getId() != currAcsId) {
            // ???sheet??
            if (null != sheet) {
                Row row = sheet.createRow(rowNumber);
                row.setHeightInPoints(20);
                Cell cell = row.createCell(0, Cell.CELL_TYPE_STRING);
                cell.setCellStyle(csCenterTextBold);
                cell.setCellValue("?");
                cell = row.createCell(3, Cell.CELL_TYPE_NUMERIC);
                cell.setCellStyle(csCenterNumberBold);
                cell.setCellValue(totalIn);
                cell = row.createCell(4, Cell.CELL_TYPE_NUMERIC);
                cell.setCellStyle(csCenterNumberBold);
                cell.setCellValue(totalOut);
            }
            // ?sheet?
            currAcsId = acs.getId();
            sheet = wb.createSheet("???#" + currAcsId);
            // ??xxxxxx
            Row row = sheet.createRow(0);
            row.setHeightInPoints(20);
            Cell cell = row.createCell(1, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csLeftTextBold);
            cell.setCellValue("??");
            cell = row.createCell(2, Cell.CELL_TYPE_NUMERIC);
            cell.setCellStyle(csLeftId);
            cell.setCellValue(currAcsId);
            // xxxxxx
            row = sheet.createRow(1);
            row.setHeightInPoints(20);
            cell = row.createCell(1, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csLeftTextBold);
            cell.setCellValue("");
            cell = row.createCell(2, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csLeftText);
            cell.setCellValue(acs.getType().getTitle());
            // ??xxxxxx
            row = sheet.createRow(2);
            row.setHeightInPoints(20);
            cell = row.createCell(1, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csLeftTextBold);
            cell.setCellValue("??");
            cell = row.createCell(2, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csLeftText);
            cell.setCellValue(acs.getName());
            // ?xxxxxx
            row = sheet.createRow(3);
            row.setHeightInPoints(20);
            cell = row.createCell(1, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csLeftTextBold);
            cell.setCellValue("?");
            cell = row.createCell(2, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csLeftText);
            cell.setCellValue(acs.getBrand());
            // ?xxxxxx
            row = sheet.createRow(4);
            row.setHeightInPoints(20);
            cell = row.createCell(1, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csLeftTextBold);
            cell.setCellValue("?");
            cell = row.createCell(2, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csLeftText);
            cell.setCellValue(acs.getModel());
            // ??xxxxxx
            row = sheet.createRow(5);
            row.setHeightInPoints(20);
            cell = row.createCell(1, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csLeftTextBold);
            cell.setCellValue("???");
            cell = row.createCell(2, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csLeftText);
            cell.setCellValue(acs.getDescription());
            // ???xxxxxx
            row = sheet.createRow(6);
            row.setHeightInPoints(20);
            cell = row.createCell(1, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csLeftTextBold);
            cell.setCellValue("???");
            cell = row.createCell(2, Cell.CELL_TYPE_STRING);
            cell.setCellStyle(csLeftText);
            cell.setCellValue(acs.getUnit());
            // 
            row = sheet.createRow(7);
            row.setHeightInPoints(20);
            for (int i = 0; i < 6; i++) {
                cell = row.createCell(i, Cell.CELL_TYPE_STRING);
                cell.setCellStyle(csCenterTextBold);
                cell.setCellValue(REG_HEADERS[i]);
                sheet.setColumnWidth(i, REG_HEADERS_WIDTH[i] * 256);
            }
            rowNumber = 8;
            totalIn = 0;
            totalOut = 0;
        }
        // ?
        Row row = sheet.createRow(rowNumber);
        row.setHeightInPoints(20);
        Cell cell = row.createCell(0, Cell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(csCenterNumber);
        cell.setCellValue(rowNumber - 7);
        cell = row.createCell(1, Cell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(csCenterTime);
        cell.setCellValue(registry.getInvoice().getTime());
        cell = row.createCell(2, Cell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(csCenterId);
        cell.setCellValue(registry.getInvoice().getId());
        cell = row.createCell(3, Cell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(csCenterNumber);
        cell.setCellValue(id > 0 ? registry.getQuantity() : 0);
        cell = row.createCell(4, Cell.CELL_TYPE_NUMERIC);
        cell.setCellStyle(csCenterNumber);
        cell.setCellValue(id < 0 ? registry.getQuantity() : 0);
        cell = row.createCell(5, Cell.CELL_TYPE_STRING);
        cell.setCellStyle(csCenterText);
        cell.setCellValue(
                id < 0 ? ((AccessoryDischargeInvoice) registry.getInvoice()).getApplicant().getName() : "");
        if (id > 0) {
            totalIn += registry.getQuantity();
        } else {
            totalOut += registry.getQuantity();
        }
        rowNumber++;
    }

    String filename = null;
    if (isIE()) {
        filename = URLEncoder.encode(fn.toString(), "UTF-8").replaceAll("\\+", "%20");
    } else {
        filename = new String(fn.toString().getBytes("UTF-8"), "iso8859-1");
    }
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    response.setHeader("Content-disposition", "attachment; filename=" + filename);
    BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream(), 4096);
    wb.write(out);
    wb.close();
    out.close();
}

From source file:com.jslsolucoes.tagria.lib.grid.exporter.impl.ExcelExporter.java

License:Apache License

private void header(Sheet sheet, Workbook workbook) {
    Row sheetRow = sheet.createRow(0);/*from w w  w. ja va 2s .co m*/
    int cell = 0;
    for (Header header : table.getHeaders()) {
        Cell sheetCel = sheetRow.createCell(cell);
        sheetCel.setCellValue(header.getContent());

        CellStyle cellStyle = workbook.createCellStyle();
        if ("center".equals(header.getAlign()))
            cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
        else if ("left".equals(header.getAlign()))
            cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
        else if ("right".equals(header.getAlign()))
            cellStyle.setAlignment(CellStyle.ALIGN_RIGHT);
        sheetCel.setCellStyle(cellStyle);

        cell++;
    }

}

From source file:com.jslsolucoes.tagria.lib.grid.exporter.impl.ExcelExporter.java

License:Apache License

private void body(Sheet sheet, Workbook workbook) {
    int line = 1;
    for (com.jslsolucoes.tagria.lib.grid.exporter.model.Row row : table.getRows()) {
        Row sheetRow = sheet.createRow(line);
        int cell = 0;
        for (Column column : row.getColumns()) {
            Cell sheetCel = sheetRow.createCell(cell);
            sheetCel.setCellValue(column.getContent());

            CellStyle cellStyle = workbook.createCellStyle();
            if ("center".equals(column.getAlign()))
                cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
            else if ("left".equals(column.getAlign()))
                cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
            else if ("right".equals(column.getAlign()))
                cellStyle.setAlignment(CellStyle.ALIGN_RIGHT);
            sheetCel.setCellStyle(cellStyle);
            cell++;//from w  w w.j  av a 2s . co  m
        }
        line++;
    }

}

From source file:com.liferay.dynamic.data.lists.internal.exporter.DDLXLSExporter.java

License:Open Source License

protected CellStyle createCellStyle(Workbook workbook, boolean bold, String fontName, short heightInPoints) {

    Font font = workbook.createFont();

    font.setBold(bold);/*from ww  w  .  ja  va 2  s.c  om*/
    font.setFontHeightInPoints(heightInPoints);
    font.setFontName(fontName);

    CellStyle style = workbook.createCellStyle();

    style.setFont(font);

    return style;
}