Search in sources :

Example 6 with DataFormat

use of org.apache.poi.ss.usermodel.DataFormat in project sinsim by WilsonHu.

the class MachineOrderController method exportToSaleExcel.

@PostMapping("/exportToSaleExcel")
public Result exportToSaleExcel(Integer id, Integer contract_id, String order_num, String contract_num, String status, String sellman, String customer, String marketGroupName, // 这个是查询创建日期
String query_start_time, // 这个是查询创建日期
String query_finish_time, // 这个是查询审核日期
String queryStartTimeSign, // 这个是查询审核日期
String queryFinishTimeSign, String machine_name, String oderSignCurrentStep, String searchDepartment, @RequestParam(defaultValue = "true") Boolean is_fuzzy) {
    List<MachineOrderDetail> list = machineOrderService.selectOrder(id, contract_id, order_num, contract_num, status, sellman, customer, marketGroupName, query_start_time, query_finish_time, queryStartTimeSign, queryFinishTimeSign, machine_name, oderSignCurrentStep, searchDepartment, is_fuzzy);
    HSSFWorkbook wb = null;
    FileOutputStream out = null;
    String downloadPath = "";
    /*
                返回给docker外部下载
                    */
    String downloadPathForNginx = "";
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
    try {
        // 生成一个空的Excel文件
        wb = new HSSFWorkbook();
        Sheet sheet1 = wb.createSheet("销售报表");
        // 设置标题行格式
        HSSFCellStyle headcellstyle = wb.createCellStyle();
        HSSFFont headfont = wb.createFont();
        headfont.setFontHeightInPoints((short) 10);
        // 粗体显示
        headfont.setBold(true);
        headcellstyle.setFont(headfont);
        Row row;
        // 新创建一行,行号为row+1
        row = sheet1.createRow(0);
        int columnSum = 22;
        for (int c = 0; c < columnSum; c++) {
            // 列头
            // 创建一个单元格,列号为col+1
            row.createCell(c);
            sheet1.setColumnWidth(c, 4500);
            sheet1.getRow(0).getCell(c).setCellStyle(headcellstyle);
        }
        // 第一行为标题
        int columnX = 0;
        sheet1.getRow(0).getCell(columnX++).setCellValue("客户");
        sheet1.getRow(0).getCell(columnX++).setCellValue("国家");
        sheet1.getRow(0).getCell(columnX++).setCellValue("部门");
        sheet1.getRow(0).getCell(columnX++).setCellValue("合同号");
        sheet1.getRow(0).getCell(columnX++).setCellValue("订单号");
        // sheet1.getRow(0).getCell(3).setCellValue("铭牌号");
        sheet1.getRow(0).getCell(columnX++).setCellValue("机器信息");
        sheet1.getRow(0).getCell(columnX++).setCellValue("台数");
        sheet1.getRow(0).getCell(columnX++).setCellValue("单价");
        sheet1.getRow(0).getCell(columnX++).setCellValue("装置");
        sheet1.getRow(0).getCell(columnX++).setCellValue("装置数量");
        sheet1.getRow(0).getCell(columnX++).setCellValue("装置总价");
        sheet1.getRow(0).getCell(columnX++).setCellValue("优惠金额");
        sheet1.getRow(0).getCell(columnX++).setCellValue("订单总金额(美元)");
        sheet1.getRow(0).getCell(columnX++).setCellValue("订单总金额(人民币)");
        sheet1.getRow(0).getCell(columnX++).setCellValue("订单总金额(欧元)");
        // sheet1.getRow(0).getCell(columnX++).setCellValue("币种");
        sheet1.getRow(0).getCell(columnX++).setCellValue("销售员");
        // 销售费
        sheet1.getRow(0).getCell(columnX++).setCellValue("业务费");
        sheet1.getRow(0).getCell(columnX++).setCellValue("付款方式");
        sheet1.getRow(0).getCell(columnX++).setCellValue("毛利");
        sheet1.getRow(0).getCell(columnX++).setCellValue("订单类型");
        sheet1.getRow(0).getCell(columnX++).setCellValue("保修费");
        sheet1.getRow(0).getCell(columnX++).setCellValue("签核完成时间");
        DataFormat dataFormat = wb.createDataFormat();
        CellStyle cellStyle;
        HSSFCellStyle wrapStyle = wb.createCellStyle();
        wrapStyle.setWrapText(true);
        // 第二行开始,填入值
        // 各订单的装置数量-合计
        int allOrdersEquipmentCount = 0;
        // 各订单的装置总价-合计
        int allOrdersEquipemntAmountCount = 0;
        // 各订单的优惠金额-合计
        int allOrdersDiscountCount = 0;
        // 各订单订单总金额(美元)	合计
        int allOrdersTotalPriceCount_USD = 0;
        // 各订单订单总金额(人民币)合计
        int allOrdersTotalPriceCount_RMB = 0;
        // 各订单订单总金额(欧元)合计
        int allOrdersTotalPriceCount_EUR = 0;
        cellStyle = wb.createCellStyle();
        // 金额格式
        cellStyle.setDataFormat(dataFormat.getFormat("#,##0.00"));
        for (int i = 0; i < list.size(); i++) {
            String dateStringSignFinish = "未完成签核";
            int r = i + 1;
            MachineOrderDetail mod = list.get(i);
            // 新创建一行
            row = sheet1.createRow(r);
            for (int c = 0; c < columnSum; c++) {
                // 创建列单元格
                row.createCell(c);
            }
            // 合同的内容也用到
            Contract contract = contractService.findById(list.get(i).getContractId());
            if (contract == null) {
                logger.error("异常,根据合同ID号,查找不到合同");
                return ResultGenerator.genFailResult("异常,根据合同ID号,查找不到合同");
            }
            // 签核也用到:签核完成时间
            List<OrderSign> orderSignList = orderSignService.getOrderSignListByOrderId(mod.getOrderSign().getOrderId());
            OrderSign orderSign = null;
            List<SignContentItem> signContentItemList = null;
            if (orderSignList.size() > 0) {
                // 订单的签核记录只有在新增合同-订单时,才创建订单的签核记录,所以这里 getOrderSignListByOrderId其实只返回一个签核记录
                orderSign = orderSignList.get(orderSignList.size() - 1);
                if (orderSign.getCurrentStep() == null) {
                    logger.warn("异常,orderSign.getCurrentStep()为null, 比如测试数据手动乱改动时可能出现");
                }
                if (orderSign.getCurrentStep() != null && orderSign.getCurrentStep().equals("签核完成")) {
                    // 如果签核完成,取最后一个角色的签核时间
                    signContentItemList = JSON.parseArray(orderSign.getSignContent(), SignContentItem.class);
                    // 注意订单签核没有enable开关
                    if (signContentItemList.get(signContentItemList.size() - 1).getDate() != null) {
                        dateStringSignFinish = formatter.format(signContentItemList.get(signContentItemList.size() - 1).getDate());
                    } else {
                        logger.warn("signContentItemList.get(signContentItemList.size()-1).getDate() 是 null,比如测试数据手动乱改动时可能出现");
                    }
                }
            }
            columnX = 0;
            // 客户
            sheet1.getRow(r).getCell(columnX).setCellValue(mod.getCustomer());
            sheet1.getRow(r).getCell(columnX++).setCellStyle(wrapStyle);
            // 国家
            sheet1.getRow(r).getCell(columnX++).setCellValue(mod.getCountry());
            // 部门
            sheet1.getRow(r).getCell(columnX++).setCellValue(contract.getMarketGroupName());
            // 合同号
            sheet1.getRow(r).getCell(columnX).setCellValue(mod.getContractNum());
            sheet1.getRow(r).getCell(columnX++).setCellStyle(wrapStyle);
            // 
            sheet1.getRow(r).getCell(columnX).setCellValue(mod.getOrderNum());
            sheet1.getRow(r).getCell(columnX++).setCellStyle(wrapStyle);
            // sheet1.getRow(r).getCell(3).setCellValue(mod.getNameplate());//
            MachineType mt = mod.getMachineType();
            if (mt != null) {
                // 机器信息
                String machineInfo = mt.getName() + "/" + mod.getNeedleNum() + "/" + mod.getHeadNum() + "/" + mod.getHeadDistance() + "/" + mod.getxDistance() + "/" + mod.getyDistance() + "/" + mod.getElectricTrim() + "/" + mod.getElectricPc();
                // 
                sheet1.getRow(r).getCell(columnX++).setCellValue(machineInfo);
            }
            // 
            sheet1.getRow(r).getCell(columnX++).setCellValue(mod.getMachineNum());
            // 
            sheet1.getRow(r).getCell(columnX).setCellValue(mod.getMachinePrice());
            sheet1.getRow(r).getCell(columnX++).setCellStyle(cellStyle);
            List<Equipment> epArray = JSON.parseArray(mod.getEquipment(), Equipment.class);
            String strEp = "";
            // 订单内  各种装置数量之和
            int equipmentCount = 0;
            int epPriceAmount = 0;
            for (Equipment itemEquipment : epArray) {
                strEp += itemEquipment.getName() + ":" + itemEquipment.getNumber() + "个" + "\r\n";
                epPriceAmount += itemEquipment.getPrice() * itemEquipment.getNumber();
                equipmentCount += itemEquipment.getNumber();
            }
            allOrdersEquipmentCount += equipmentCount;
            allOrdersEquipemntAmountCount += epPriceAmount;
            // sheet1.getRow(r).getCell(columnX).setCellStyle(wrapStyle);
            // 装置
            sheet1.getRow(r).getCell(columnX++).setCellValue(new HSSFRichTextString(strEp));
            // 装置数量
            sheet1.getRow(r).getCell(columnX++).setCellValue(equipmentCount);
            // 装置总价
            sheet1.getRow(r).getCell(columnX).setCellValue(epPriceAmount);
            sheet1.getRow(r).getCell(columnX++).setCellStyle(cellStyle);
            // 优惠金额
            sheet1.getRow(r).getCell(columnX).setCellValue(mod.getDiscounts());
            allOrdersDiscountCount += Integer.valueOf(mod.getDiscounts());
            Double totalAmount = Double.parseDouble(mod.getMachinePrice()) * mod.getMachineNum() + epPriceAmount * mod.getMachineNum() - // 优惠金额 (需求单总价格优惠金额)
            Double.parseDouble(mod.getOrderTotalDiscounts()) - // 每台的优惠金额
            Double.parseDouble(mod.getDiscounts()) * mod.getMachineNum();
            // - Double.parseDouble(mod.getIntermediaryPrice())*mod.getMachineNum();//每台的居间费用 和总价无关
            sheet1.getRow(r).getCell(columnX++).setCellStyle(cellStyle);
            if (mod.getCurrencyType().equals("美元")) {
                allOrdersTotalPriceCount_USD += totalAmount;
                // 总金额(美元)
                sheet1.getRow(r).getCell(columnX).setCellValue(totalAmount);
                sheet1.getRow(r).getCell(columnX++).setCellStyle(cellStyle);
                columnX++;
                // 
                columnX++;
            }
            if (mod.getCurrencyType().equals("人民币")) {
                allOrdersTotalPriceCount_RMB += totalAmount;
                columnX++;
                // 总金额(人民币)
                sheet1.getRow(r).getCell(columnX).setCellValue(totalAmount);
                sheet1.getRow(r).getCell(columnX++).setCellStyle(cellStyle);
                columnX++;
            }
            if (mod.getCurrencyType().equals("欧元")) {
                allOrdersTotalPriceCount_EUR += totalAmount;
                columnX++;
                columnX++;
                // 总金额(欧元)
                sheet1.getRow(r).getCell(columnX).setCellValue(totalAmount);
                sheet1.getRow(r).getCell(columnX++).setCellStyle(cellStyle);
            }
            // sheet1.getRow(r).getCell(columnX++).setCellValue(mod.getCurrencyType());//币种
            // 销售员
            sheet1.getRow(r).getCell(columnX++).setCellValue(mod.getSellman());
            // 销售费 业务费
            sheet1.getRow(r).getCell(columnX).setCellValue(mod.getBusinessExpense());
            sheet1.getRow(r).getCell(columnX++).setCellStyle(cellStyle);
            // 付款方式
            sheet1.getRow(r).getCell(columnX++).setCellValue(mod.getPayMethod());
            // 毛利率
            sheet1.getRow(r).getCell(columnX++).setCellValue(mod.getGrossProfit());
            // 订单类型
            sheet1.getRow(r).getCell(columnX++).setCellValue(mod.getOrderType());
            // 保修费
            sheet1.getRow(r).getCell(columnX++).setCellValue(mod.getWarrantyFee());
            // 签核完成时间
            sheet1.getRow(r).getCell(columnX++).setCellValue(dateStringSignFinish);
        }
        // 最后一行 汇总
        // 新创建一行
        Row rowSum = sheet1.createRow(list.size() + 1);
        for (int c = 0; c < columnSum; c++) {
            // 创建列单元格
            rowSum.createCell(c);
        }
        // 各订单的装置数量-合计
        rowSum.getCell(9).setCellValue(allOrdersEquipmentCount);
        // 各订单的装置总价 合计
        rowSum.getCell(10).setCellValue(allOrdersEquipemntAmountCount);
        rowSum.getCell(10).setCellStyle(cellStyle);
        // 优惠金额  合计
        rowSum.getCell(11).setCellValue(allOrdersDiscountCount);
        // 订单总金额(美元)	合计
        rowSum.getCell(12).setCellValue(allOrdersTotalPriceCount_USD);
        rowSum.getCell(12).setCellStyle(cellStyle);
        // 订单总金额(人民币)合计
        rowSum.getCell(13).setCellValue(allOrdersTotalPriceCount_RMB);
        rowSum.getCell(13).setCellStyle(cellStyle);
        // 订单总金额(欧元)合计
        rowSum.getCell(14).setCellValue(allOrdersTotalPriceCount_EUR);
        rowSum.getCell(14).setCellStyle(cellStyle);
        downloadPath = reportOutputPath + "销售报表" + ".xls";
        downloadPathForNginx = "/report/" + "销售报表" + ".xls";
        out = new FileOutputStream(downloadPath);
        wb.write(out);
        out.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if ("".equals(downloadPath)) {
        return ResultGenerator.genFailResult("异常导出失败!");
    } else {
        return ResultGenerator.genSuccessResult(downloadPathForNginx);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) MachineOrderDetail(com.eservice.api.model.machine_order.MachineOrderDetail) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) OrderSign(com.eservice.api.model.order_sign.OrderSign) SignContentItem(com.eservice.api.model.contract_sign.SignContentItem) DataFormat(org.apache.poi.ss.usermodel.DataFormat) HSSFFont(org.apache.poi.hssf.usermodel.HSSFFont) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) MachineType(com.eservice.api.model.machine_type.MachineType) IOException(java.io.IOException) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Equipment(com.eservice.api.model.contract.Equipment) FileOutputStream(java.io.FileOutputStream) Row(org.apache.poi.ss.usermodel.Row) HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) CellStyle(org.apache.poi.ss.usermodel.CellStyle) SimpleDateFormat(java.text.SimpleDateFormat) Sheet(org.apache.poi.ss.usermodel.Sheet) Contract(com.eservice.api.model.contract.Contract) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 7 with DataFormat

use of org.apache.poi.ss.usermodel.DataFormat in project jgnash by ccavanaugh.

the class BudgetResultsExport method exportBudgetResultsModel.

/**
 * Exports a {@code BudgetResultsModel} to a spreadsheet.
 *
 * @param file File to save to
 * @param model Results model to export
 * @return Error message
 */
public static String exportBudgetResultsModel(final Path file, final BudgetResultsModel model) {
    String message = null;
    final ResourceBundle rb = ResourceUtils.getBundle();
    final String extension = FileUtils.getFileExtension(file.toString());
    try (final Workbook wb = extension.equals("xlsx") ? new XSSFWorkbook() : new HSSFWorkbook()) {
        final CreationHelper createHelper = wb.getCreationHelper();
        // create a new sheet
        final Sheet s = wb.createSheet(model.getBudget().getName());
        // create header cell styles, override the defaults
        final CellStyle headerStyle = StyleFactory.createHeaderStyle(wb);
        headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        final Font headerFont = StyleFactory.createHeaderFont(wb);
        headerFont.setColor(IndexedColors.BLACK.index);
        headerStyle.setFont(headerFont);
        // Set the other cell style and formatting
        final DataFormat df_header = wb.createDataFormat();
        headerStyle.setDataFormat(df_header.getFormat("text"));
        // create fonts objects
        final Font amountFont = StyleFactory.createDefaultFont(wb);
        int row = 0;
        Row r = s.createRow(row);
        // fill the corner
        Cell corner = r.createCell(0);
        corner.setCellStyle(headerStyle);
        // create period headers
        for (int i = 0; i < model.getDescriptorList().size(); i++) {
            Cell c = r.createCell(i * 3 + 1);
            c.setCellValue(createHelper.createRichTextString(model.getDescriptorList().get(i).getPeriodDescription()));
            c.setCellStyle(headerStyle);
            s.addMergedRegion(new CellRangeAddress(row, row, i * 3 + 1, i * 3 + 3));
        }
        {
            int col = model.getDescriptorList().size() * 3 + 1;
            Cell c = r.createCell(col);
            c.setCellValue(createHelper.createRichTextString(rb.getString("Title.Summary")));
            c.setCellStyle(headerStyle);
            s.addMergedRegion(new CellRangeAddress(row, row, col, col + 2));
        }
        // create results header columns
        row++;
        r = s.createRow(row);
        {
            Cell c = r.createCell(0);
            c.setCellValue(createHelper.createRichTextString(rb.getString("Column.Account")));
            c.setCellStyle(headerStyle);
            for (int i = 0; i <= model.getDescriptorList().size(); i++) {
                c = r.createCell(i * 3 + 1);
                c.setCellValue(createHelper.createRichTextString(rb.getString("Column.Budgeted")));
                c.setCellStyle(headerStyle);
                c = r.createCell(i * 3 + 2);
                c.setCellValue(createHelper.createRichTextString(rb.getString("Column.Actual")));
                c.setCellStyle(headerStyle);
                c = r.createCell(i * 3 + 3);
                c.setCellValue(createHelper.createRichTextString(rb.getString("Column.Remaining")));
                c.setCellStyle(headerStyle);
            }
        }
        // must sort the accounts, otherwise child structure is not correct
        List<Account> accounts = new ArrayList<>(model.getAccounts());
        accounts.sort(Comparators.getAccountByTreePosition(Comparators.getAccountByCode()));
        // create account rows
        for (final Account account : accounts) {
            final CellStyle amountStyle = StyleFactory.createDefaultAmountStyle(wb, account.getCurrencyNode());
            // Sets cell indentation, only impacts display if users changes the cell formatting to be left aligned.
            amountStyle.setIndention((short) (model.getDepth(account) * 2));
            row++;
            int col = 0;
            r = s.createRow(row);
            CellStyle cs = wb.createCellStyle();
            cs.cloneStyleFrom(headerStyle);
            cs.setAlignment(HorizontalAlignment.LEFT);
            cs.setIndention((short) (model.getDepth(account) * 2));
            Cell c = r.createCell(col);
            c.setCellValue(createHelper.createRichTextString(account.getName()));
            c.setCellStyle(cs);
            List<CellReference> budgetedRefList = new ArrayList<>();
            List<CellReference> changeRefList = new ArrayList<>();
            List<CellReference> remainingRefList = new ArrayList<>();
            for (int i = 0; i < model.getDescriptorList().size(); i++) {
                BudgetPeriodResults results = model.getResults(model.getDescriptorList().get(i), account);
                c = r.createCell(++col, CellType.NUMERIC);
                c.setCellValue(results.getBudgeted().doubleValue());
                c.setCellStyle(amountStyle);
                CellReference budgetedRef = new CellReference(row, col);
                budgetedRefList.add(budgetedRef);
                c = r.createCell(++col, CellType.NUMERIC);
                c.setCellValue(results.getChange().doubleValue());
                c.setCellStyle(amountStyle);
                CellReference changeRef = new CellReference(row, col);
                changeRefList.add(changeRef);
                c = r.createCell(++col, CellType.FORMULA);
                c.setCellStyle(amountStyle);
                c.setCellFormula(budgetedRef.formatAsString() + "-" + changeRef.formatAsString());
                CellReference remainingRef = new CellReference(row, col);
                remainingRefList.add(remainingRef);
            }
            // add summary columns
            addSummaryCell(r, ++col, budgetedRefList, amountStyle);
            addSummaryCell(r, ++col, changeRefList, amountStyle);
            addSummaryCell(r, ++col, remainingRefList, amountStyle);
        }
        // add group summary rows
        for (final AccountGroup group : model.getAccountGroupList()) {
            final DataFormat df = wb.createDataFormat();
            // reuse the header style but align right
            final CellStyle amountStyle = StyleFactory.createHeaderStyle(wb);
            amountStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
            amountStyle.setAlignment(HorizontalAlignment.RIGHT);
            amountStyle.setFont(amountFont);
            final DecimalFormat format = (DecimalFormat) NumericFormats.getFullCommodityFormat(model.getBaseCurrency());
            final String pattern = format.toLocalizedPattern().replace("¤", model.getBaseCurrency().getPrefix());
            amountStyle.setDataFormat(df.getFormat(pattern));
            row++;
            int col = 0;
            r = s.createRow(row);
            CellStyle cs = wb.createCellStyle();
            cs.cloneStyleFrom(headerStyle);
            cs.setAlignment(HorizontalAlignment.LEFT);
            Cell c = r.createCell(col);
            c.setCellValue(createHelper.createRichTextString(group.toString()));
            c.setCellStyle(cs);
            List<CellReference> budgetedRefList = new ArrayList<>();
            List<CellReference> changeRefList = new ArrayList<>();
            List<CellReference> remainingRefList = new ArrayList<>();
            for (int i = 0; i < model.getDescriptorList().size(); i++) {
                BudgetPeriodResults results = model.getResults(model.getDescriptorList().get(i), group);
                c = r.createCell(++col, CellType.NUMERIC);
                c.setCellValue(results.getBudgeted().doubleValue());
                c.setCellStyle(amountStyle);
                CellReference budgetedRef = new CellReference(row, col);
                budgetedRefList.add(budgetedRef);
                c = r.createCell(++col, CellType.NUMERIC);
                c.setCellValue(results.getChange().doubleValue());
                c.setCellStyle(amountStyle);
                CellReference changeRef = new CellReference(row, col);
                changeRefList.add(changeRef);
                c = r.createCell(++col, CellType.FORMULA);
                c.setCellStyle(amountStyle);
                c.setCellFormula(budgetedRef.formatAsString() + "-" + changeRef.formatAsString());
                CellReference remainingRef = new CellReference(row, col);
                remainingRefList.add(remainingRef);
            }
            // add summary columns
            addSummaryCell(r, ++col, budgetedRefList, amountStyle);
            addSummaryCell(r, ++col, changeRefList, amountStyle);
            addSummaryCell(r, ++col, remainingRefList, amountStyle);
        }
        // force evaluation
        FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
        evaluator.evaluateAll();
        short columnCount = s.getRow(1).getLastCellNum();
        // autosize all of the columns + 10 pixels
        for (int i = 0; i <= columnCount; i++) {
            s.autoSizeColumn(i);
            s.setColumnWidth(i, s.getColumnWidth(i) + 10);
        }
        Logger.getLogger(BudgetResultsExport.class.getName()).log(Level.INFO, "{0} cell styles were used", wb.getNumCellStyles());
        // Save
        String filename = file.toString();
        if (wb instanceof XSSFWorkbook) {
            filename = FileUtils.stripFileExtension(filename) + ".xlsx";
        } else {
            filename = FileUtils.stripFileExtension(filename) + ".xls";
        }
        try (final OutputStream out = Files.newOutputStream(Paths.get(filename))) {
            wb.write(out);
        } catch (final Exception e) {
            Logger.getLogger(BudgetResultsExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
            message = e.getLocalizedMessage();
        }
    } catch (IOException e) {
        Logger.getLogger(BudgetResultsExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
    return message;
}
Also used : Account(jgnash.engine.Account) DecimalFormat(java.text.DecimalFormat) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) CellReference(org.apache.poi.ss.util.CellReference) Font(org.apache.poi.ss.usermodel.Font) DataFormat(org.apache.poi.ss.usermodel.DataFormat) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Cell(org.apache.poi.ss.usermodel.Cell) CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) BudgetPeriodResults(jgnash.engine.budget.BudgetPeriodResults) IOException(java.io.IOException) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) IOException(java.io.IOException) AccountGroup(jgnash.engine.AccountGroup) ResourceBundle(java.util.ResourceBundle) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Row(org.apache.poi.ss.usermodel.Row) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Sheet(org.apache.poi.ss.usermodel.Sheet) FormulaEvaluator(org.apache.poi.ss.usermodel.FormulaEvaluator)

Example 8 with DataFormat

use of org.apache.poi.ss.usermodel.DataFormat in project jgnash by ccavanaugh.

the class StyleFactory method applyPercentageFormat.

/**
 * Applies a percentage format to a {@code CellStyle}
 *
 * @param wb        the {@code Workbook} the numeric format is being created for
 * @param cellStyle the {@code CellStyle} being updated
 * @return the {@code CellStyle} being updated
 */
static CellStyle applyPercentageFormat(final Workbook wb, final CellStyle cellStyle) {
    final NumberFormat percentageFormat = NumericFormats.getPercentageFormat();
    final DataFormat df = wb.createDataFormat();
    cellStyle.setDataFormat(df.getFormat(((DecimalFormat) percentageFormat).toPattern()));
    cellStyle.setAlignment(HorizontalAlignment.RIGHT);
    return cellStyle;
}
Also used : DecimalFormat(java.text.DecimalFormat) DataFormat(org.apache.poi.ss.usermodel.DataFormat) NumberFormat(java.text.NumberFormat)

Example 9 with DataFormat

use of org.apache.poi.ss.usermodel.DataFormat in project jgnash by ccavanaugh.

the class StyleFactory method applySecurityQuantityFormat.

/**
 * Applies a Security quantity format to a {@code CellStyle}
 *
 * @param wb        the {@code Workbook} the numeric format is being created for
 * @param cellStyle the {@code CellStyle} being updated
 * @return the {@code CellStyle} being updated
 */
static CellStyle applySecurityQuantityFormat(final Workbook wb, final CellStyle cellStyle) {
    final NumberFormat qtyFormat = NumericFormats.getFixedPrecisionFormat(MathConstants.SECURITY_QUANTITY_ACCURACY);
    final DataFormat df = wb.createDataFormat();
    cellStyle.setDataFormat(df.getFormat(((DecimalFormat) qtyFormat).toPattern()));
    cellStyle.setAlignment(HorizontalAlignment.RIGHT);
    return cellStyle;
}
Also used : DecimalFormat(java.text.DecimalFormat) DataFormat(org.apache.poi.ss.usermodel.DataFormat) NumberFormat(java.text.NumberFormat)

Example 10 with DataFormat

use of org.apache.poi.ss.usermodel.DataFormat in project jgnash by ccavanaugh.

the class StyleFactory method applyCurrencyFormat.

/**
 * Applies a currency format to a {@code CellStyle}
 *
 * @param wb           the {@code Workbook} the numeric format is being created for
 * @param currencyNode the {@code CurrencyNode} to extract symbol information from
 * @param cellStyle    the {@code CellStyle} being updated
 * @return the {@code CellStyle} being updated
 */
static CellStyle applyCurrencyFormat(final Workbook wb, final CurrencyNode currencyNode, final CellStyle cellStyle) {
    final DecimalFormat format = (DecimalFormat) NumericFormats.getFullCommodityFormat(currencyNode);
    final String pattern = format.toLocalizedPattern().replace("¤", currencyNode.getPrefix());
    final DataFormat df = wb.createDataFormat();
    cellStyle.setDataFormat(df.getFormat(pattern));
    cellStyle.setAlignment(HorizontalAlignment.RIGHT);
    return cellStyle;
}
Also used : DecimalFormat(java.text.DecimalFormat) DataFormat(org.apache.poi.ss.usermodel.DataFormat)

Aggregations

DataFormat (org.apache.poi.ss.usermodel.DataFormat)19 CellStyle (org.apache.poi.ss.usermodel.CellStyle)14 Row (org.apache.poi.ss.usermodel.Row)10 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)8 Cell (org.apache.poi.ss.usermodel.Cell)8 Sheet (org.apache.poi.ss.usermodel.Sheet)8 Font (org.apache.poi.ss.usermodel.Font)7 DecimalFormat (java.text.DecimalFormat)6 Workbook (org.apache.poi.ss.usermodel.Workbook)6 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)6 FileOutputStream (java.io.FileOutputStream)5 IOException (java.io.IOException)5 OutputStream (java.io.OutputStream)3 SimpleDateFormat (java.text.SimpleDateFormat)3 CreationHelper (org.apache.poi.ss.usermodel.CreationHelper)3 CellReference (org.apache.poi.ss.util.CellReference)3 Equipment (com.eservice.api.model.contract.Equipment)2 MachineOrderDetail (com.eservice.api.model.machine_order.MachineOrderDetail)2 MachineType (com.eservice.api.model.machine_type.MachineType)2 FileNotFoundException (java.io.FileNotFoundException)2