Example usage for org.apache.poi.hssf.usermodel HSSFFont setFontName

List of usage examples for org.apache.poi.hssf.usermodel HSSFFont setFontName

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFFont setFontName.

Prototype


public void setFontName(String name) 

Source Link

Document

set the name for the font (i.e.

Usage

From source file:tw.edu.chit.struts.action.secretary.ReportPrintAction.java

/**
 * ????//w  w  w . j  a v a 2  s .  com
 * 
 * @param mapping org.apache.struts.action.ActionMapping object
 * @param form org.apache.struts.action.ActionForm object
 * @param request request javax.servlet.http.HttpServletRequest object
 * @param response response javax.servlet.http.HttpServletResponse object
 * @param sterm 
 */
@SuppressWarnings("unchecked")
private void printOpinionDetailList(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

    HttpSession session = request.getSession(false);
    AdminManager am = (AdminManager) getBean(IConstants.ADMIN_MANAGER_BEAN_NAME);
    MemberManager mm = (MemberManager) getBean(IConstants.MEMBER_MANAGER_BEAN_NAME);
    DynaActionForm aForm = (DynaActionForm) form;
    ServletContext context = request.getSession().getServletContext();

    String year = aForm.getStrings("year")[0];
    String term = aForm.getString("sterm");
    String deptCode = request.getParameter("odc");

    List<StdOpinionSuggestion> ret = null;
    if (StringUtils.isNotBlank(deptCode)) {
        String hql = "FROM StdOpinionSuggestion s " + "WHERE s.schoolYear = ? AND s.schoolTerm = ? "
                + "AND s.target = ? ORDER BY s.lastModified";
        ret = (List<StdOpinionSuggestion>) am.find(hql, new Object[] { year, term, deptCode });
    } else {
        String hql = "FROM StdOpinionSuggestion s " + "WHERE s.schoolYear = ? AND s.schoolTerm = ? "
                + "ORDER BY s.lastModified";
        ret = (List<StdOpinionSuggestion>) am.find(hql, new Object[] { year, term });
    }

    if (!ret.isEmpty()) {

        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("???");
        sheet.setColumnWidth(0, 2500);
        sheet.setColumnWidth(1, 2500);
        sheet.setColumnWidth(2, 5000);
        sheet.setColumnWidth(3, 3000);
        sheet.setColumnWidth(4, 6000);
        sheet.setColumnWidth(5, 6000);
        sheet.setColumnWidth(6, 3000);
        sheet.setColumnWidth(7, 3000);
        sheet.setColumnWidth(8, 12000);
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 8));

        HSSFFont fontSize16 = workbook.createFont();
        fontSize16.setFontHeightInPoints((short) 16);
        fontSize16.setFontName("Arial Unicode MS");

        HSSFFont fontSize10 = workbook.createFont();
        fontSize10.setFontHeightInPoints((short) 10);
        fontSize10.setFontName("Arial Unicode MS");

        // Header
        Toolket.setCellValue(workbook, sheet, 0, 0, "???", fontSize16,
                HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null);

        // Column Header
        Toolket.setCellValue(workbook, sheet, 1, 0, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
                null);
        Toolket.setCellValue(workbook, sheet, 1, 1, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
                null);
        Toolket.setCellValue(workbook, sheet, 1, 2, "???", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 3, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 4, "Email", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
                null);
        Toolket.setCellValue(workbook, sheet, 1, 5, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 6, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 7, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 8, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        int index = 2;
        Student student = null;
        DateFormat df = new SimpleDateFormat("yyyy/MM/dd hh:mm");

        for (StdOpinionSuggestion s : ret) {

            Toolket.setCellValue(workbook, sheet, index, 0, year, fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
                    null);
            Toolket.setCellValue(workbook, sheet, index, 1, term, fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
                    null);
            Toolket.setCellValue(workbook, sheet, index, 2, Toolket.getOpinionDeptName(s.getTarget()),
                    fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);

            student = mm.findStudentByOid(s.getStudentOid());
            Toolket.setCellValue(workbook, sheet, index, 3, student == null ? "" : student.getStudentName(),
                    fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 4, s.getEmail(), fontSize10, HSSFCellStyle.ALIGN_LEFT,
                    true, null);
            Toolket.setCellValue(workbook, sheet, index, 5, s.getTopic(), fontSize10, HSSFCellStyle.ALIGN_LEFT,
                    true, null);
            Toolket.setCellValue(workbook, sheet, index, 6, s.getPlace(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 7, df.format(s.getLastModified()), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index++, 8, s.getContent(), fontSize10,
                    HSSFCellStyle.ALIGN_LEFT, true, null);
        }

        File tempDir = new File(
                context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno()
                        + (new SimpleDateFormat("yyyyMMdd").format(new Date()))));
        if (!tempDir.exists())
            tempDir.mkdirs();

        File output = new File(tempDir, "OpinionDetailList.xls");
        FileOutputStream fos = new FileOutputStream(output);
        workbook.write(fos);
        fos.close();

        JasperReportUtils.printXlsToFrontEnd(response, output);
        output.delete();
        tempDir.delete();
    }
}

From source file:utilesBD.servidoresDatos.JServerServidorDatosExcel.java

public static void guardar(JListDatos poList, File poFile, boolean pbCabezera) throws Throwable {

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet(poList.msTabla);
    int lHoja = 1;
    HSSFCellStyle style = workbook.createCellStyle();
    //        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    style.setWrapText(true);/*from   w  w  w .j  a v a  2s . c  om*/
    HSSFFont font = workbook.createFont();
    font.setFontHeightInPoints((short) 10);
    font.setFontName("Courier New");
    font.setItalic(true);
    // font.setStrikeout(true);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    //font.setColor(Short.parseShort("#ffffff"));
    style.setFont(font);

    int lFila = 0;
    if (pbCabezera) {
        lFila++;
        crearCabecera(poList, sheet, style, lFila);
    }
    if (poList.moveFirst()) {
        do {
            lFila++;
            toExcel(poList, workbook, lFila, sheet);
            if (lFila > 65524) {
                lFila = 0;
                if (pbCabezera) {
                    lFila++;
                    crearCabecera(poList, sheet, style, lFila);
                }
                lHoja++;
                sheet = workbook.createSheet(poList.msTabla + String.valueOf(lHoja));
            }
        } while (poList.moveNext());

    }

    // Escribir el fichero.
    OutputStream fileOut = new FileOutputStream(poFile);
    try {
        workbook.write(fileOut);
    } finally {
        fileOut.close();
    }
}

From source file:xx.tream.chengxin.ms.action.TrainReportAction.java

@RequestMapping({ "/toExport" })
public String toExport(ModelMap modelMap, HttpServletRequest request, HttpServletResponse response,
        FormMap formMap, Integer currentPage, Integer pageSize) throws IOException {
    Map<String, Object> qm = formMap.getFormMap();
    List<Map<String, Object>> list = this.trainService.queryForParam(qm);
    //Map<String, Object> statisticsMap = this.trainService.statistics(qm);
    String trainIds = this.getTrainIds(list);
    List<Map<String, Object>> payingList = this.payingService.queryByTrainIds(trainIds);
    List<Map<String, Object>> incomeList = this.incomeService.queryByTrainIds(trainIds);
    List<Map<String, Object>> payoutList = this.payoutService.queryByTrainIds(trainIds);
    Map<Long, List<Map<String, Object>>> payingMap = converList(payingList);
    Map<Long, List<Map<String, Object>>> incomeMap = converList(incomeList);
    Map<Long, List<Map<String, Object>>> payoutMap = converList(payoutList);

    OutputStream os = response.getOutputStream();
    response.reset();/*from   ww w .ja  v  a  2  s  .  co m*/
    response.setCharacterEncoding("UTF-8");
    String title = "?" + getDateFile() + ".xls";
    response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(title, "UTF-8"));
    response.setContentType("application/vnd.ms-excel");
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("?");
    HSSFRow headrow = sheet.createRow(0);
    HSSFCellStyle headcell = workbook.createCellStyle();

    HSSFFont font = workbook.createFont();
    font.setFontName("");
    font.setFontHeightInPoints((short) 10);
    headcell.setFont(font);
    headrow.setRowStyle(headcell);
    String payingValue[] = { "", "paying", "createUserName", "createTime", "createTime", "", "auditUserName",
            "auditTime", "auditTime" };
    String incomeValue[] = { "type", "income", "createUserName", "createTime", "createTime", "note",
            "auditUserName", "auditTime", "auditTime" };
    String payoutValue[] = { "type", "payout", "createUserName", "createTime", "createTime", "",
            "auditUserName", "auditTime", "auditTime" };
    String[] heads = { "", "?", "?", "??", "??", "",
            "", "", "", "", "/", "/?", "C1/C2",
            "", "", "", "", "", "?", "?",
            "?", "?", "", "", "", "" };
    String[] values = { "", "id", "autumnNumber", "name", "idcard", "pay", "allpaying", "count_all", "allip",
            "canpay", "newOrOld", "type", "licenseTag", "createUserName", "createTime", "createTime", "note" };
    HSSFCellStyle headStyle = ExcelUtil.headCell(workbook);
    HSSFCell cell = null;
    //
    int cr = 0;
    for (int i = 0; i < heads.length; i++) {
        cell = headrow.createCell(cr);
        cell.setCellValue(heads[i]);
        cell.setCellStyle(headStyle);
        sheet.setColumnWidth(cr, 5000);
        cr++;
    }
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm");
    HSSFCellStyle rowStyle = ExcelUtil.leftCell(workbook);
    HSSFCellStyle paleBlueStyle = ExcelUtil.paleBlueForgroundCell(workbook);
    //HSSFCellStyle redFontStyle = ExcelUtil.leftFontRedCell(workbook);
    //HSSFCellStyle redFontForegroudStyle = ExcelUtil.leftFontRedForegroudCell(workbook);
    HSSFCellStyle rightStyle = ExcelUtil.rightCell(workbook);
    HSSFCellStyle rightForegroudStyle = ExcelUtil.rightPaleBlueForgroundCell(workbook);
    HSSFCellStyle rightredFontStyle = ExcelUtil.rightFontRedCell(workbook);
    HSSFCellStyle rightredFontForegroudStyle = ExcelUtil.rightFontRedForegroudCell(workbook);
    double ac[] = new double[5];

    //
    int rn = 1;
    HSSFRow row = null;
    //??
    for (int i = 0; i < list.size(); i++) {
        int a = 0;
        //
        int pb = 0;
        //
        cr = 0;
        row = sheet.createRow(rn++);
        Map<String, Object> trainMap = (Map<String, Object>) list.get(i);
        List<Map<String, Object>> payL = (List<Map<String, Object>>) payingMap.get((Long) trainMap.get("id"));
        List<Map<String, Object>> incomeL = (List<Map<String, Object>>) incomeMap
                .get((Long) trainMap.get("id"));
        List<Map<String, Object>> payoutL = (List<Map<String, Object>>) payoutMap
                .get((Long) trainMap.get("id"));
        for (int v = 0; v < values.length; v++) {
            cell = row.createCell(cr++);
            if (trainMap.get(values[v]) != null) {
                if (v == 14) {
                    cell.setCellValue(sdf.format((Date) trainMap.get(values[v])));
                } else if (v == 15) {
                    cell.setCellValue(sdf2.format((Date) trainMap.get(values[v])));
                } else if (v == 5 || v == 6 || v == 7 || v == 8 || v == 9) {
                    Double d = trainMap.get(values[v]) == null ? 0 : (Double) trainMap.get(values[v]);
                    ac[a] += d;
                    a++;
                    cell.setCellValue((Double) trainMap.get(values[v]));
                } else if (v == 1) {
                    cell.setCellValue((Long) trainMap.get(values[v]));
                } else {
                    cell.setCellValue((String) trainMap.get(values[v]));
                }
            } else {
                if (v == 0) {
                    cell.setCellValue(i + 1);
                } else {
                    cell.setCellValue("");
                }
            }
            if (v == 5 || v == 6 || v == 7 || v == 8 || v == 9) {//?
                cell.setCellStyle(rightForegroudStyle);
            } else {
                cell.setCellStyle(paleBlueStyle);
            }

        }

        //
        if (payL != null && payL.size() > 0) {
            for (int p = 0; p < payL.size(); p++) {
                Map<String, Object> pMap = payL.get(p);
                cr = values.length;
                for (int v = 0; v < payingValue.length; v++) {
                    cell = row.createCell(cr++);
                    if (v == 0) {
                        cell.setCellValue("" + (p + 1));
                    } else {
                        if (pMap.get(payingValue[v]) != null) {
                            if (v == 3 || v == 7) {
                                cell.setCellValue(sdf.format((Date) pMap.get(payingValue[v])));
                            } else if (v == 4 || v == 8) {
                                cell.setCellValue(sdf2.format((Date) pMap.get(payingValue[v])));
                            } else if (v == 1) {
                                Double nv = (Double) pMap.get(payingValue[v]);
                                cell.setCellValue(nv);
                            } else {
                                cell.setCellValue((String) pMap.get(payingValue[v]));
                            }
                        } else {
                            cell.setCellValue("");
                        }
                    }
                    if (v == 1) {//?
                        if (pb == 0) {
                            cell.setCellStyle(rightForegroudStyle);
                        } else {
                            cell.setCellStyle(rightStyle);
                        }
                    } else {
                        if (pb == 0) {
                            cell.setCellStyle(paleBlueStyle);

                        } else {
                            cell.setCellStyle(rowStyle);
                        }
                    }
                }
                pb++;
                row = sheet.createRow(rn++);

            }

        }
        //
        if (incomeL != null && incomeL.size() > 0) {
            for (int p = 0; p < incomeL.size(); p++) {
                Map<String, Object> iMap = incomeL.get(p);
                cr = values.length;
                for (int v = 0; v < incomeValue.length; v++) {
                    cell = row.createCell(cr++);
                    if (v == 0) {
                        cell.setCellValue(iMap.get(incomeValue[v]) + "()");
                    } else {
                        if (iMap.get(incomeValue[v]) != null) {
                            if (v == 3 || v == 7) {
                                cell.setCellValue(sdf.format((Date) iMap.get(incomeValue[v])));
                            } else if (v == 4 || v == 8) {
                                cell.setCellValue(sdf2.format((Date) iMap.get(incomeValue[v])));
                            } else if (v == 1) {
                                cell.setCellValue((Double) iMap.get(incomeValue[v]));
                            } else {
                                cell.setCellValue((String) iMap.get(incomeValue[v]));
                            }
                        } else {
                            cell.setCellValue("");
                        }
                    }
                    if (v == 1) {//?
                        if (pb == 0) {
                            cell.setCellStyle(rightForegroudStyle);
                        } else {
                            cell.setCellStyle(rightStyle);
                        }
                    } else {
                        if (pb == 0) {
                            cell.setCellStyle(paleBlueStyle);

                        } else {
                            cell.setCellStyle(rowStyle);
                        }
                    }
                }
                pb++;
                row = sheet.createRow(rn++);
            }
        }
        boolean flag = false;
        //
        if (payoutL != null && payoutL.size() > 0) {
            for (int p = 0; p < payoutL.size(); p++) {
                Map<String, Object> pMap = payoutL.get(p);
                cr = values.length;
                for (int v = 0; v < payoutValue.length; v++) {
                    cell = row.createCell(cr++);
                    if (v == 0) {
                        cell.setCellValue(pMap.get(payoutValue[v]) + "()");
                    } else {
                        if (pMap.get(payoutValue[v]) != null) {
                            if (v == 3 || v == 7) {
                                cell.setCellValue(sdf.format((Date) pMap.get(payoutValue[v])));
                            } else if (v == 4 || v == 8) {
                                cell.setCellValue(sdf2.format((Date) pMap.get(payoutValue[v])));
                            } else if (v == 1) {
                                flag = true;
                                cell.setCellValue(0 - (Double) pMap.get(payoutValue[v]));
                            } else {
                                cell.setCellValue((String) pMap.get(payoutValue[v]));
                            }
                        } else {
                            cell.setCellValue("");
                        }
                    }
                    if (pb == 0 && flag) {
                        flag = false;
                        cell.setCellStyle(rightredFontForegroudStyle);
                    } else if (flag) {
                        flag = false;
                        cell.setCellStyle(rightredFontStyle);
                    } else if (pb == 0) {
                        cell.setCellStyle(paleBlueStyle);
                    } else {
                        cell.setCellStyle(rowStyle);
                    }
                }
                pb++;
                if (p != payoutL.size() - 1) {
                    row = sheet.createRow(rn++);
                }
            }
        }
    }
    if (list != null && list.size() > 0) {
        row = sheet.createRow(rn++);
        cell = row.createCell(0);
        cell.setCellValue("?");
        cell.setCellStyle(headStyle);
        for (int i = 0; i < ac.length; i++) {
            cell = row.createCell(5 + i);
            cell.setCellValue(ac[i]);
            cell.setCellStyle(rightStyle);
        }
    }

    workbook.write(os);
    os.flush();
    os.close();
    return null;
}