Search in sources :

Example 21 with XSSFFont

use of org.apache.poi.xssf.usermodel.XSSFFont in project dhis2-core by dhis2.

the class ExcelNodeSerializer method startSerialize.

@Override
protected void startSerialize(RootNode rootNode, OutputStream outputStream) throws Exception {
    workbook = new XSSFWorkbook();
    sheet = workbook.createSheet("Sheet1");
    XSSFFont boldFont = workbook.createFont();
    boldFont.setBold(true);
    XSSFCellStyle boldCellStyle = workbook.createCellStyle();
    boldCellStyle.setFont(boldFont);
    // build schema
    for (Node child : rootNode.getChildren()) {
        if (child.isCollection()) {
            if (!child.getChildren().isEmpty()) {
                Node node = child.getChildren().get(0);
                XSSFRow row = sheet.createRow(0);
                int cellIdx = 0;
                for (Node property : node.getChildren()) {
                    if (property.isSimple()) {
                        XSSFCell cell = row.createCell(cellIdx++);
                        cell.setCellValue(property.getName());
                        cell.setCellStyle(boldCellStyle);
                    }
                }
            }
        }
    }
}
Also used : XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) CollectionNode(org.hisp.dhis.node.types.CollectionNode) Node(org.hisp.dhis.node.Node) SimpleNode(org.hisp.dhis.node.types.SimpleNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) RootNode(org.hisp.dhis.node.types.RootNode) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell)

Example 22 with XSSFFont

use of org.apache.poi.xssf.usermodel.XSSFFont in project translationstudio8 by heartsome.

the class ExportQAResult method beginExport.

public void beginExport(List<QAResultBean> dataList, List<String> fileLCList, IProgressMonitor monitor) {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    // 分成十份,其中解析文件 1 份,其余 9 份
    monitor.beginTask("", 10);
    monitor.setTaskName(Messages.getString("qa.export.ExportQAResult.monitor.title"));
    // 将 fileLCList 转换成相对路径
    List<File> fileList = new ArrayList<File>();
    for (String fileLC : fileLCList) {
        fileList.add(new File(fileLC));
    }
    for (IFile iFile : ResourceUtils.filesToIFiles(fileList)) {
        filePathList.add(iFile.getFullPath().toOSString());
    }
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    monitor.worked(1);
    // UNDO 这里按文件排序给注释了。。。。
    //		// 先按文件排序
    //		sort(dataList);
    // 工作簿
    XSSFWorkbook workbook = new XSSFWorkbook();
    // 创建sheet页
    XSSFSheet sheet = workbook.createSheet();
    // 设置sheet名称
    workbook.setSheetName(0, Messages.getString("qa.export.ExportQAResult.sheet.title"));
    sheet.setColumnWidth(0, 255 * 6);
    sheet.setColumnWidth(1, 255 * 20);
    sheet.setColumnWidth(2, 255 * 30);
    sheet.setColumnWidth(3, 255 * 60);
    sheet.setColumnWidth(4, 255 * 60);
    XSSFFont titleFont = workbook.createFont();
    titleFont.setColor(IndexedColors.GREY_80_PERCENT.getIndex());
    titleFont.setBold(true);
    titleFont.setFontHeight(20);
    XSSFFont headerFont = workbook.createFont();
    headerFont.setBold(true);
    headerFont.setFontHeight(14);
    XSSFFont errorFont = workbook.createFont();
    errorFont.setColor(IndexedColors.RED.getIndex());
    XSSFCellStyle titleStyle = workbook.createCellStyle();
    titleStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
    titleStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
    titleStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
    titleStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
    titleStyle.setAlignment(HorizontalAlignment.CENTER);
    titleStyle.setFont(titleFont);
    XSSFCellStyle headerStyle = workbook.createCellStyle();
    headerStyle.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
    headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    headerStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
    headerStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
    headerStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
    headerStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
    headerStyle.setFont(headerFont);
    XSSFCellStyle cellStyle = workbook.createCellStyle();
    cellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
    cellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
    cellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
    cellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
    cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
    cellStyle.setWrapText(true);
    XSSFCellStyle errorCellStyle = workbook.createCellStyle();
    errorCellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
    errorCellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
    errorCellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
    errorCellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
    errorCellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
    errorCellStyle.setWrapText(true);
    errorCellStyle.setFont(errorFont);
    // 生成标题行
    XSSFRow row = sheet.createRow(0);
    XSSFCell cell = row.createCell(0);
    cell.setCellStyle(titleStyle);
    cell.setCellValue(Messages.getString("qa.export.ExportQAResult.titleCell"));
    String[] headers = new String[] { // 级别
    Messages.getString("qa.export.ExportQAResult.header.errorLeavel"), // 类型
    Messages.getString("qa.export.ExportQAResult.header.qaType"), // 位置
    Messages.getString("qa.export.ExportQAResult.header.location"), // 源文
    Messages.getString("qa.export.ExportQAResult.header.srcText"), //  译文
    Messages.getString("qa.export.ExportQAResult.header.tgtText") };
    // 产生表格标题行
    row = sheet.createRow(1);
    for (short i = 0; i < headers.length; i++) {
        cell = row.createCell(i);
        cell.setCellStyle(headerStyle);
        cell.setCellValue(headers[i]);
    }
    // 开始生成数据
    int index = 1;
    String rowId = null;
    // 先处理品质检查结果数据为空的情况
    if (dataList.size() <= 0) {
        if (isMultiFile) {
            String multiFileStr = getMultiResouce();
            index++;
            row = sheet.createRow(index);
            for (int i = 0; i < headers.length; i++) {
                cell = row.createCell(i);
                cell.setCellStyle(cellStyle);
                if (i == headers.length - 1) {
                    cell.setCellValue(multiFileStr);
                }
            }
        } else {
            for (String filePath : this.filePathList) {
                index++;
                row = sheet.createRow(index);
                for (int i = 0; i < headers.length; i++) {
                    cell = row.createCell(i);
                    cell.setCellStyle(cellStyle);
                    if (i == headers.length - 1) {
                        cell.setCellValue(filePath);
                    }
                }
            }
        }
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));
    } else {
        int interval = 1;
        if (dataList.size() > 9) {
            interval = dataList.size() / 9;
        }
        int startMergeRow = -1;
        int endMergeRow = -1;
        for (int i = 0; i < dataList.size(); i++) {
            QAResultBean bean = dataList.get(i);
            index++;
            System.out.println(index);
            if (index % interval == 0) {
                if (monitor.isCanceled()) {
                    throw new OperationCanceledException();
                }
                monitor.worked(1);
            }
            row = sheet.createRow(index);
            // 处理合并 级别 与 类型 两列的行
            mergeIF: if (bean.getMergeId() != null) {
                if (mergedIdSet.contains(bean.getMergeId())) {
                    break mergeIF;
                }
                startMergeRow = index;
                mergeFor: for (int j = i + 1; j < dataList.size(); j++) {
                    if (dataList.get(j).getMergeId() != null && dataList.get(j).getMergeId().equals(bean.getMergeId())) {
                        mergedIdSet.add(bean.getMergeId());
                        endMergeRow = index + (j - i);
                    } else {
                        break mergeFor;
                    }
                }
                if (startMergeRow >= 0 && endMergeRow >= 0) {
                    sheet.addMergedRegion(new CellRangeAddress(startMergeRow, endMergeRow, 0, 0));
                    sheet.addMergedRegion(new CellRangeAddress(startMergeRow, endMergeRow, 1, 1));
                    startMergeRow = -1;
                    endMergeRow = -1;
                }
            }
            // 循环当前行的每一列
            for (int h = 0; h < headers.length; h++) {
                cell = row.createCell(h);
                cell.setCellStyle(cellStyle);
                String text = null;
                switch(h) {
                    case 0:
                        if (bean.getLevel() == 0) {
                            text = Messages.getString("qa.export.ExportQAResult.errorLeavel.error");
                            cell.setCellStyle(errorCellStyle);
                        } else if (bean.getLevel() == 1) {
                            text = Messages.getString("qa.export.ExportQAResult.errorLeavel.warning");
                        }
                        cell.setCellValue(text);
                        break;
                    case 1:
                        text = bean.getQaTypeText();
                        cell.setCellValue(text);
                        break;
                    case 2:
                        text = bean.getFileName() + " [" + bean.getLineNumber() + "]";
                        cell.setCellValue(text);
                        break;
                    case 3:
                        text = bean.getSrcContent();
                        cell.setCellValue(getDisplayText(text));
                        break;
                    case 4:
                        text = bean.getTgtContent();
                        cell.setCellValue(getDisplayText(text));
                        break;
                    default:
                        break;
                }
            }
        }
        //	            // 这是合并 文件路径
        //	            if (isMultiFile) {
        //	            	sheet.addMergedRegion(new CellRangeAddress(resourceIndex, index, 6, 6));
        //	    		}else {
        //	    			sheet.addMergedRegion(new CellRangeAddress(resourceIndex, index, 6, 6));
        //	    		}
        //	            sheet.addMergedRegion(new CellRangeAddress(rowidIndex, index, 1, 1));
        //	    		sheet.addMergedRegion(new CellRangeAddress(rowidIndex, index, 4, 4));
        //	    		sheet.addMergedRegion(new CellRangeAddress(rowidIndex, index, 5, 5));
        // 标题行合并(处理未合并完的部份)
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));
    }
    try {
        FileOutputStream fileoutputstream = new FileOutputStream(exportFilePath);
        workbook.write(fileoutputstream);
        fileoutputstream.close();
        Display.getDefault().syncExec(new Runnable() {

            public void run() {
                MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.getString("qa.all.dialog.info"), Messages.getString("qa.export.ExportQAResult.MSG.exportSuccess"));
            }
        });
    } catch (Exception e) {
        Display.getDefault().syncExec(new Runnable() {

            public void run() {
                MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.getString("qa.all.dialog.info"), Messages.getString("qa.export.ExportQAResult.MSG.exportFail"));
            }
        });
        LOGGER.error(Messages.getString("qa.export.ExportQAResult.LOG.exportError"), e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) QAResultBean(net.heartsome.cat.ts.ui.qa.model.QAResultBean) ArrayList(java.util.ArrayList) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) FileOutputStream(java.io.FileOutputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 23 with XSSFFont

use of org.apache.poi.xssf.usermodel.XSSFFont in project bamboobsc by billchen198318.

the class KpiReportExcelCommand method createHead.

private int createHead(XSSFWorkbook wb, XSSFSheet sh, int row, VisionVO vision) throws Exception {
    Row headRow = sh.createRow(row);
    headRow.setHeight((short) 700);
    int cell = 0;
    XSSFColor bgColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor(vision.getBgColor()));
    XSSFColor fnColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor(vision.getFontColor()));
    XSSFCellStyle cellHeadStyle = wb.createCellStyle();
    cellHeadStyle.setFillForegroundColor(bgColor);
    cellHeadStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    XSSFFont cellHeadFont = wb.createFont();
    cellHeadFont.setBold(true);
    cellHeadFont.setColor(fnColor);
    cellHeadStyle.setFont(cellHeadFont);
    cellHeadStyle.setBorderBottom(BorderStyle.THIN);
    cellHeadStyle.setBorderTop(BorderStyle.THIN);
    cellHeadStyle.setBorderRight(BorderStyle.THIN);
    cellHeadStyle.setBorderLeft(BorderStyle.THIN);
    cellHeadStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    cellHeadStyle.setAlignment(HorizontalAlignment.CENTER);
    cellHeadStyle.setWrapText(true);
    int cols = 12;
    for (int i = 0; i < cols; i++) {
        sh.setColumnWidth(i, 4000);
        Cell headCell1 = headRow.createCell(cell++);
        headCell1.setCellValue(vision.getTitle() + "\nscore: " + BscReportSupportUtils.parse2(vision.getScore()));
        headCell1.setCellStyle(cellHeadStyle);
    }
    sh.addMergedRegion(new CellRangeAddress(row, row, 0, cols - 1));
    // ------------------------------------------------------------------------
    bgColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor(BscReportPropertyUtils.getBackgroundColor()));
    fnColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor(BscReportPropertyUtils.getFontColor()));
    cellHeadStyle = wb.createCellStyle();
    cellHeadStyle.setFillForegroundColor(bgColor);
    cellHeadStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    cellHeadFont = wb.createFont();
    cellHeadFont.setBold(true);
    cellHeadFont.setColor(fnColor);
    cellHeadStyle.setFont(cellHeadFont);
    cellHeadStyle.setBorderBottom(BorderStyle.THIN);
    cellHeadStyle.setBorderTop(BorderStyle.THIN);
    cellHeadStyle.setBorderRight(BorderStyle.THIN);
    cellHeadStyle.setBorderLeft(BorderStyle.THIN);
    cellHeadStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    cellHeadStyle.setAlignment(HorizontalAlignment.CENTER);
    cellHeadStyle.setWrapText(true);
    row++;
    headRow = sh.createRow(row);
    cell = 0;
    int titleCols = 4;
    for (int i = 0; i < titleCols; i++) {
        Cell headCell1 = headRow.createCell(cell++);
        headCell1.setCellValue(BscReportPropertyUtils.getPerspectiveTitle());
        headCell1.setCellStyle(cellHeadStyle);
    }
    for (int i = 0; i < titleCols; i++) {
        Cell headCell1 = headRow.createCell(cell++);
        headCell1.setCellValue(BscReportPropertyUtils.getObjectiveTitle());
        headCell1.setCellStyle(cellHeadStyle);
    }
    for (int i = 0; i < titleCols; i++) {
        Cell headCell1 = headRow.createCell(cell++);
        headCell1.setCellValue(BscReportPropertyUtils.getKpiTitle());
        headCell1.setCellStyle(cellHeadStyle);
    }
    sh.addMergedRegion(new CellRangeAddress(row, row, 0, 3));
    sh.addMergedRegion(new CellRangeAddress(row, row, 4, 7));
    sh.addMergedRegion(new CellRangeAddress(row, row, 8, 11));
    return 2;
}
Also used : XSSFColor(org.apache.poi.xssf.usermodel.XSSFColor) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) Row(org.apache.poi.ss.usermodel.Row) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Cell(org.apache.poi.ss.usermodel.Cell)

Example 24 with XSSFFont

use of org.apache.poi.xssf.usermodel.XSSFFont in project bamboobsc by billchen198318.

the class ObjectivesDashboardExcelCommand method putCharts.

@SuppressWarnings("unchecked")
private int putCharts(XSSFWorkbook wb, XSSFSheet sh, Context context) throws Exception {
    String barBase64Content = SimpleUtils.getPNGBase64Content((String) context.get("barChartsData"));
    BufferedImage barImage = SimpleUtils.decodeToImage(barBase64Content);
    ByteArrayOutputStream barBos = new ByteArrayOutputStream();
    ImageIO.write(barImage, "png", barBos);
    barBos.flush();
    SimpleUtils.setCellPicture(wb, sh, barBos.toByteArray(), 0, 0);
    int row = 28;
    List<Map<String, Object>> chartDatas = (List<Map<String, Object>>) context.get("chartDatas");
    String year = (String) context.get("year");
    XSSFCellStyle cellHeadStyle = wb.createCellStyle();
    cellHeadStyle.setFillForegroundColor(new XSSFColor(SimpleUtils.getColorRGB4POIColor("#f5f5f5")));
    cellHeadStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    XSSFFont cellHeadFont = wb.createFont();
    cellHeadFont.setBold(true);
    cellHeadStyle.setFont(cellHeadFont);
    int titleCellSize = 14;
    Row headRow = sh.createRow(row);
    for (int i = 0; i < titleCellSize; i++) {
        Cell headCell = headRow.createCell(i);
        headCell.setCellStyle(cellHeadStyle);
        headCell.setCellValue("Objectives metrics gauge ( " + year + " )");
    }
    sh.addMergedRegion(new CellRangeAddress(row, row, 0, titleCellSize - 1));
    row = row + 1;
    int cellLeft = 10;
    int rowSpace = 17;
    for (Map<String, Object> data : chartDatas) {
        Map<String, Object> nodeData = (Map<String, Object>) ((List<Object>) data.get("datas")).get(0);
        String pngImageData = SimpleUtils.getPNGBase64Content((String) nodeData.get("outerHTML"));
        BufferedImage imageData = SimpleUtils.decodeToImage(pngImageData);
        ByteArrayOutputStream imgBos = new ByteArrayOutputStream();
        ImageIO.write(imageData, "png", imgBos);
        imgBos.flush();
        SimpleUtils.setCellPicture(wb, sh, imgBos.toByteArray(), row, 0);
        XSSFColor bgColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor((String) nodeData.get("bgColor")));
        XSSFColor fnColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor((String) nodeData.get("fontColor")));
        XSSFCellStyle cellStyle = wb.createCellStyle();
        cellStyle.setFillForegroundColor(bgColor);
        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        XSSFFont cellFont = wb.createFont();
        cellFont.setBold(true);
        cellFont.setColor(fnColor);
        cellStyle.setFont(cellFont);
        int perTitleCellSize = 4;
        Row nowRow = sh.createRow(row);
        for (int i = 0; i < perTitleCellSize; i++) {
            Cell cell1 = nowRow.createCell(cellLeft);
            cell1.setCellStyle(cellStyle);
            cell1.setCellValue((String) nodeData.get("name"));
        }
        sh.addMergedRegion(new CellRangeAddress(row, row, cellLeft, cellLeft + perTitleCellSize - 1));
        nowRow = sh.createRow(row + 1);
        Cell cell2 = nowRow.createCell(cellLeft);
        cell2.setCellValue("Target: " + String.valueOf(nodeData.get("target")));
        nowRow = sh.createRow(row + 2);
        Cell cell3 = nowRow.createCell(cellLeft);
        cell3.setCellValue("Min: " + String.valueOf(nodeData.get("min")));
        nowRow = sh.createRow(row + 3);
        Cell cell4 = nowRow.createCell(cellLeft);
        cell4.setCellValue("Score: " + String.valueOf(nodeData.get("score")));
        row += rowSpace;
    }
    return row;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage) XSSFColor(org.apache.poi.xssf.usermodel.XSSFColor) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) List(java.util.List) Row(org.apache.poi.ss.usermodel.Row) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Map(java.util.Map) Cell(org.apache.poi.ss.usermodel.Cell)

Example 25 with XSSFFont

use of org.apache.poi.xssf.usermodel.XSSFFont in project bamboobsc by billchen198318.

the class TimeSeriesAnalysisExcelCommand method putTables.

private void putTables(XSSFWorkbook wb, XSSFSheet sh, Context context) throws Exception {
    TsaVO tsa = (TsaVO) context.get("tsa");
    @SuppressWarnings("unchecked") List<BbTsaMaCoefficients> coefficients = (List<BbTsaMaCoefficients>) context.get("coefficients");
    @SuppressWarnings("unchecked") List<TimeSeriesAnalysisResult> tsaResults = (List<TimeSeriesAnalysisResult>) context.get("tsaResults");
    XSSFFont cellHeadFont = wb.createFont();
    cellHeadFont.setBold(true);
    XSSFCellStyle cellHeadStyle = wb.createCellStyle();
    cellHeadStyle.setFillForegroundColor(new XSSFColor(SimpleUtils.getColorRGB4POIColor("#f5f5f5")));
    cellHeadStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    cellHeadStyle.setBorderBottom(BorderStyle.THIN);
    cellHeadStyle.setBorderTop(BorderStyle.THIN);
    cellHeadStyle.setBorderRight(BorderStyle.THIN);
    cellHeadStyle.setBorderLeft(BorderStyle.THIN);
    cellHeadStyle.setFont(cellHeadFont);
    XSSFCellStyle cellHeadStyleBlank = wb.createCellStyle();
    cellHeadStyleBlank.setFillForegroundColor(new XSSFColor(SimpleUtils.getColorRGB4POIColor("#ffffff")));
    cellHeadStyleBlank.setFont(cellHeadFont);
    XSSFCellStyle cellHeadStyle2 = wb.createCellStyle();
    cellHeadStyle2.setFillForegroundColor(new XSSFColor(SimpleUtils.getColorRGB4POIColor("#ffffff")));
    cellHeadStyle2.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    cellHeadStyle2.setBorderBottom(BorderStyle.THIN);
    cellHeadStyle2.setBorderTop(BorderStyle.THIN);
    cellHeadStyle2.setBorderRight(BorderStyle.THIN);
    cellHeadStyle2.setBorderLeft(BorderStyle.THIN);
    sh.setColumnWidth(0, 12000);
    int row = 0;
    // ==============================================================
    Row nowRow = sh.createRow(row);
    Cell cellTitle = nowRow.createCell(0);
    cellTitle.setCellStyle(cellHeadStyleBlank);
    cellTitle.setCellValue("Forecast analysis - " + context.get("visionName"));
    row++;
    // ==============================================================
    nowRow = sh.createRow(row);
    Cell cell0a = nowRow.createCell(0);
    cell0a.setCellStyle(cellHeadStyleBlank);
    cell0a.setCellValue("Frequency: " + context.get("frequencyName") + " , Date range: " + context.get("date1") + " - " + context.get("date2") + " , " + "Measure data type for: " + context.get("dataFor") + " , " + context.get("organizationName") + context.get("employeeName"));
    row++;
    // ==============================================================
    nowRow = sh.createRow(row);
    Cell cell0b = nowRow.createCell(0);
    cell0b.setCellStyle(cellHeadStyleBlank);
    cell0b.setCellValue("");
    row++;
    // ==============================================================
    nowRow = sh.createRow(row);
    Cell cell1 = nowRow.createCell(0);
    cell1.setCellStyle(cellHeadStyleBlank);
    cell1.setCellValue("Param infornation");
    row++;
    // ==============================================================
    nowRow = sh.createRow(row);
    Cell cell2_a = nowRow.createCell(0);
    cell2_a.setCellStyle(cellHeadStyle);
    cell2_a.setCellValue("Item");
    Cell cell2_b = nowRow.createCell(1);
    cell2_b.setCellStyle(cellHeadStyle);
    cell2_b.setCellValue("Value");
    row++;
    // ==============================================================	
    nowRow = sh.createRow(row);
    Cell cell3_a = nowRow.createCell(0);
    cell3_a.setCellStyle(cellHeadStyle2);
    cell3_a.setCellValue("Param name");
    Cell cell3_b = nowRow.createCell(1);
    cell3_b.setCellStyle(cellHeadStyle2);
    cell3_b.setCellValue(tsa.getName());
    row++;
    // ==============================================================	
    nowRow = sh.createRow(row);
    Cell cell4_a = nowRow.createCell(0);
    cell4_a.setCellStyle(cellHeadStyle2);
    cell4_a.setCellValue("Integration order");
    Cell cell4_b = nowRow.createCell(1);
    cell4_b.setCellStyle(cellHeadStyle2);
    cell4_b.setCellValue(tsa.getIntegrationOrder());
    row++;
    // ==============================================================	
    nowRow = sh.createRow(row);
    Cell cell5_a = nowRow.createCell(0);
    cell5_a.setCellStyle(cellHeadStyle2);
    cell5_a.setCellValue("Forecast next");
    Cell cell5_b = nowRow.createCell(1);
    cell5_b.setCellStyle(cellHeadStyle2);
    cell5_b.setCellValue(tsa.getForecastNext());
    row++;
    // ==============================================================	
    nowRow = sh.createRow(row);
    Cell cell6_a = nowRow.createCell(0);
    cell6_a.setCellStyle(cellHeadStyle2);
    cell6_a.setCellValue("Description");
    Cell cell6_b = nowRow.createCell(1);
    cell6_b.setCellStyle(cellHeadStyle2);
    cell6_b.setCellValue(StringUtils.defaultString(tsa.getDescription()).trim());
    row++;
    // ==============================================================
    for (int i = 0; coefficients != null && i < coefficients.size(); i++) {
        BbTsaMaCoefficients coefficient = coefficients.get(i);
        nowRow = sh.createRow(row);
        Cell cell7x_a = nowRow.createCell(0);
        cell7x_a.setCellStyle(cellHeadStyle2);
        cell7x_a.setCellValue("Coefficient (" + (i + 1) + ")");
        Cell cell7x_b = nowRow.createCell(1);
        cell7x_b.setCellStyle(cellHeadStyle2);
        cell7x_b.setCellValue(String.valueOf(coefficient.getSeqValue()));
        row++;
    }
    // ==============================================================
    nowRow = sh.createRow(row);
    Cell cellTitle3a = nowRow.createCell(0);
    cellTitle3a.setCellStyle(cellHeadStyleBlank);
    cellTitle3a.setCellValue("");
    row++;
    // 填寫標題
    nowRow = sh.createRow(row);
    Cell cellTitle2a = nowRow.createCell(0);
    cellTitle2a.setCellStyle(cellHeadStyle);
    cellTitle2a.setCellValue("KPIs");
    int j = 1;
    TimeSeriesAnalysisResult firstResult = tsaResults.get(0);
    for (int i = 0; i < firstResult.getKpi().getDateRangeScores().size(); i++) {
        DateRangeScoreVO dateRangeScore = firstResult.getKpi().getDateRangeScores().get(i);
        Cell cellTitle2a_dateRange = nowRow.createCell(j);
        j++;
        cellTitle2a_dateRange.setCellStyle(cellHeadStyle);
        cellTitle2a_dateRange.setCellValue(dateRangeScore.getDate());
    }
    for (int i = 0; i < firstResult.getForecastNext().size(); i++) {
        Cell cellTitle2a_dateRange = nowRow.createCell(j);
        j++;
        cellTitle2a_dateRange.setCellStyle(cellHeadStyle);
        cellTitle2a_dateRange.setCellValue("next(" + (i + 1) + ")");
    }
    row++;
    // 填寫 Date Range score 與 Forecast next score
    for (int i = 0; i < tsaResults.size(); i++) {
        nowRow = sh.createRow(row);
        j = 0;
        TimeSeriesAnalysisResult resultModel = tsaResults.get(i);
        Cell cell_kpi = nowRow.createCell(j);
        cell_kpi.setCellStyle(cellHeadStyle);
        cell_kpi.setCellValue(resultModel.getKpi().getName());
        j++;
        for (int n = 0; n < resultModel.getKpi().getDateRangeScores().size(); n++) {
            DateRangeScoreVO dateRangeScore = resultModel.getKpi().getDateRangeScores().get(n);
            Cell cell_dateRangeScore = nowRow.createCell(j);
            cell_dateRangeScore.setCellStyle(cellHeadStyle2);
            cell_dateRangeScore.setCellValue(dateRangeScore.getScore());
            j++;
        }
        for (int n = 0; n < resultModel.getForecastNext().size(); n++) {
            double forecastScore = resultModel.getForecastNext().get(n);
            Cell cell_forecastScore = nowRow.createCell(j);
            cell_forecastScore.setCellStyle(cellHeadStyle2);
            cell_forecastScore.setCellValue(forecastScore);
            j++;
        }
        row++;
    }
}
Also used : DateRangeScoreVO(com.netsteadfast.greenstep.vo.DateRangeScoreVO) TsaVO(com.netsteadfast.greenstep.vo.TsaVO) BbTsaMaCoefficients(com.netsteadfast.greenstep.po.hbm.BbTsaMaCoefficients) TimeSeriesAnalysisResult(com.netsteadfast.greenstep.bsc.model.TimeSeriesAnalysisResult) XSSFColor(org.apache.poi.xssf.usermodel.XSSFColor) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) List(java.util.List) Row(org.apache.poi.ss.usermodel.Row) Cell(org.apache.poi.ss.usermodel.Cell)

Aggregations

XSSFFont (org.apache.poi.xssf.usermodel.XSSFFont)27 XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)22 Cell (org.apache.poi.ss.usermodel.Cell)17 Row (org.apache.poi.ss.usermodel.Row)17 XSSFColor (org.apache.poi.xssf.usermodel.XSSFColor)17 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)13 List (java.util.List)6 KpiVO (com.netsteadfast.greenstep.vo.KpiVO)5 DateRangeScoreVO (com.netsteadfast.greenstep.vo.DateRangeScoreVO)4 ObjectiveVO (com.netsteadfast.greenstep.vo.ObjectiveVO)4 PerspectiveVO (com.netsteadfast.greenstep.vo.PerspectiveVO)4 Map (java.util.Map)4 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)4 BufferedImage (java.awt.image.BufferedImage)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 HashMap (java.util.HashMap)3 XSSFCell (org.apache.poi.xssf.usermodel.XSSFCell)3 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)3 XSSFCellBorder (org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder)3 XSSFCellFill (org.apache.poi.xssf.usermodel.extensions.XSSFCellFill)3