Example usage for org.apache.poi.ss.usermodel Sheet setDefaultColumnWidth

List of usage examples for org.apache.poi.ss.usermodel Sheet setDefaultColumnWidth

Introduction

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

Prototype

void setDefaultColumnWidth(int width);

Source Link

Document

Set the default column width for the sheet (if the columns do not define their own width) in characters

Usage

From source file:com.griffinslogistics.excel.BDLGenerator.java

public static void generateAll(OutputStream outputStream,
        Map<String, List<BookBoxModel>> bookBoxModelsForTransportation, Pulsiodetails pulsioDetails,
        String packageNumber) {/*ww  w  . j a  v  a  2  s  .c om*/
    try {
        Workbook workbook = new HSSFWorkbook();
        Map<String, CellStyle> styles = createStyles(workbook);

        for (String bookspackageNumber : bookBoxModelsForTransportation.keySet()) {

            Sheet sheet = workbook.createSheet(bookspackageNumber);

            //Default sheet styles
            sheet.setDisplayGridlines(false);
            sheet.setPrintGridlines(false);
            sheet.getPrintSetup().setLandscape(true);
            sheet.setFitToPage(true);
            sheet.setHorizontallyCenter(true);
            sheet.setDefaultRowHeight((short) 300);
            sheet.setDefaultColumnWidth(15);

            sheet.setColumnWidth(1, 6000);
            sheet.setColumnWidth(5, 3000);
            sheet.setColumnWidth(6, 3000);
            sheet.setColumnWidth(7, 3000);
            sheet.setColumnWidth(8, 3000);

            // Generate header part
            insertPulsioImage(workbook, sheet, pulsioDetails);
            insertDate(sheet, styles.get("title"));
            insertContacts(sheet, styles.get("pulsioName"), styles.get("contacts"), pulsioDetails);
            insertTitle(sheet, styles.get("title"));

            // Generate table part
            insertTableHeaders(sheet, styles.get("tableHeadersLeft"), styles.get("tableHeadersMiddle"),
                    styles.get("tableHeadersRight"));
            List<BookBoxModel> bookBoxModels = bookBoxModelsForTransportation.get(bookspackageNumber);
            int index = insertTableBody(sheet, styles.get("tableBodyLeft"), styles.get("tableBodyMiddle"),
                    styles.get("tableBodyRight"), styles.get("tableFooters"), bookBoxModels);

            String deliveryAddress = bookBoxModels.get(0).getDeliveryAddress();
            String client = bookBoxModels.get(0).getClient();
            insertFooter(sheet, styles.get("footer"), index, bookspackageNumber, deliveryAddress, client);
        }

        workbook.write(outputStream);
    } catch (FileNotFoundException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
}

From source file:com.griffinslogistics.excel.BDLGenerator.java

public static OutputStream generateSingle(OutputStream outputStream, List<BookBoxModel> bookBoxModels,
        Pulsiodetails pulsiodetails, String packageNumber) {

    try {//  w ww . j a  v  a  2 s  .c  o  m
        Workbook workbook = new HSSFWorkbook();
        Map<String, CellStyle> styles = createStyles(workbook);
        Sheet sheet = workbook.createSheet("Bon de livraison");

        //Default sheet styles
        sheet.setDisplayGridlines(false);
        sheet.setPrintGridlines(false);
        sheet.getPrintSetup().setLandscape(true);
        sheet.setFitToPage(true);
        sheet.setHorizontallyCenter(true);
        sheet.setDefaultRowHeight((short) 300);
        sheet.setDefaultColumnWidth(15);

        sheet.setColumnWidth(1, 6000);
        sheet.setColumnWidth(5, 3000);
        sheet.setColumnWidth(6, 3000);
        sheet.setColumnWidth(7, 3000);
        sheet.setColumnWidth(8, 3000);

        // Generate header part
        insertPulsioImage(workbook, sheet, pulsiodetails);
        insertDate(sheet, styles.get("title"));
        insertContacts(sheet, styles.get("pulsioName"), styles.get("contacts"), pulsiodetails);
        insertTitle(sheet, styles.get("title"));

        // Generate table part
        insertTableHeaders(sheet, styles.get("tableHeadersLeft"), styles.get("tableHeadersMiddle"),
                styles.get("tableHeadersRight"));
        int index = insertTableBody(sheet, styles.get("tableBodyLeft"), styles.get("tableBodyMiddle"),
                styles.get("tableBodyRight"), styles.get("tableFooters"), bookBoxModels);

        String deliveryAddress = bookBoxModels.get(0).getDeliveryAddress();
        String client = bookBoxModels.get(0).getClient();

        insertFooter(sheet, styles.get("footer"), index, packageNumber, deliveryAddress, client);

        workbook.write(outputStream);
    } catch (FileNotFoundException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    }

    return outputStream;
}

From source file:com.vaadin.addon.spreadsheet.SpreadsheetFactory.java

License:Open Source License

/**
 * Sets the size, default row height and default column width for the given
 * new Sheet in the target Spreadsheet. Finally loads the sheet.
 *
 * @param spreadsheet// ww w .  j a  va  2s .  co m
 *            Target spreadsheet
 * @param sheet
 *            Target sheet
 * @param rows
 *            Amount of rows
 * @param columns
 *            Amount of columns
 */
static void generateNewSpreadsheet(final Spreadsheet spreadsheet, final Sheet sheet, int rows, int columns) {
    sheet.createRow(rows - 1).createCell(columns - 1);
    setDefaultRowHeight(spreadsheet, sheet);
    // use excel default column width instead of Apache POI default (8)
    sheet.setDefaultColumnWidth(DEFAULT_COL_WIDTH_UNITS);
    reloadSpreadsheetData(spreadsheet, sheet);
}

From source file:com.vaadin.addon.spreadsheet.SpreadsheetFactory.java

License:Open Source License

private static void setDefaultColumnWidth(Spreadsheet spreadsheet, final Sheet sheet) {
    int charactersToPixels = ExcelToHtmlUtils.getColumnWidthInPx(sheet.getDefaultColumnWidth() * 256);
    if (charactersToPixels > 0) {
        spreadsheet.getState().defColW = charactersToPixels;
    } else {//from  w  ww.ja  v a2 s .c  om
        spreadsheet.getState().defColW = SpreadsheetUtil.getDefaultColumnWidthInPx();
        sheet.setDefaultColumnWidth(DEFAULT_COL_WIDTH_UNITS);
    }
}

From source file:com.zlfun.framework.excel.ExcelUtils.java

public static <T> void write(String sheetName, Class<T> clazz, List<T> list, OutputStream out) {
    if (out == null) {
        return;/*from   w w  w.j  a v  a 2  s .  c om*/
    }
    Workbook workbook = new HSSFWorkbook();
    Sheet sheet = workbook.createSheet(sheetName);
    // 15
    sheet.setDefaultColumnWidth(15);

    Drawing drawing = sheet.createDrawingPatriarch();

    List<String> header = buildHeader(workbook, sheet, clazz);

    buildBody(workbook, sheet, drawing, header, list);

    try {
        workbook.write(out);
    } catch (IOException ex) {
        // TODO Auto-generated catch block
        Logger.getLogger(ExcelUtils.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:de.iteratec.iteraplan.businesslogic.exchange.legacyExcel.exporter.ExportWorkbook.java

License:Open Source License

/**
 * Makes a new sheet with <code>sheetName</code> and returns it. Only its current row insert
 * marker is tracked in this Class//from   ww w. j  a v  a 2 s.  co  m
 * 
 * @param sheetName
 * @return The internal sheet ID of the newly created sheet
 */
public int createSheet(String sheetName) {
    // If these characters are not replaced, then the Excel workbook cannot be generated and it
    // throws an IllegalArgumentException
    String sanitizedSheetName = StringUtils.replaceEach(sheetName,
            new String[] { "\\", "/", "*", "[", "]", "?" }, new String[] { "_", "_", "_", "(", ")", "_" });

    checkIfSheetExists(sanitizedSheetName);

    Sheet sheet = this.getWb().createSheet(sanitizedSheetName);
    sheet.setZoom(SHEET_NUMERATOR, SHEET_DENOMINATOR);
    sheet.setDefaultColumnWidth(DEFAULT_COLUMN_WIDTH);

    sheetOrder.add(sheet);

    return sheetOrder.size() - 1; // return the sheet position in the list
}

From source file:de.quamoco.qm.editor.excelexport.HumanReadableExcelExporter.java

License:Apache License

private void createAllInOneSheet(Workbook workbook) {
    Sheet sheet = workbook.createSheet("All-In-One");
    sheet.setDefaultColumnWidth(30);

    String[] names = new String[] { "Measure Name", "Tool", "Normalization", "Measure Description",
            "Measure Weight", "Influenced Factor", "Factor weight", "Impacted Quality Aspect",
            "Effect of the Impact", "Rationale for the Impact", "Description of the Quality Aspect" };

    Row header = sheet.createRow(0);//from  ww w  .j a va2  s .  co  m
    for (int col = 0; col < names.length; col++) {
        header.createCell(col).setCellValue(names[col]);
    }

    int row = 1;
    for (Measure measure : measures) {
        for (Factor factor : measure.getMeasuresDirect()) {

            for (Impact imp : factor.getInfluences()) {
                Factor qa = imp.getTarget();
                Evaluation qaeval = qa.getActualEvaluation(context);

                WeightedSumFactorAggregation wsf = null;
                if (!(qaeval instanceof WeightedSumFactorAggregation)) {
                    System.err.println("WARNING: factor '" + factor + "' qa '" + qa
                            + "' does not have a WeightedSumFactorAggregation");
                } else {
                    wsf = (WeightedSumFactorAggregation) qaeval;
                }

                double qaweight = Double.NaN;
                if (wsf != null) {
                    for (Ranking ranking : wsf.getRankings()) {
                        if (ranking.getRankedElement() == factor) {
                            qaweight = ranking.getWeight();
                        }
                    }
                }

                Evaluation factoreval = factor.getActualEvaluation(context);
                WeightedSumMultiMeasureEvaluation mme = null;
                if (factoreval == null) {
                    System.err.println("WARNING: measure '" + measure.getQualifiedName() + "' factor '"
                            + factor.getQualifiedName() + "' does not have an evaluation at all.");
                } else if (!(factoreval instanceof WeightedSumMultiMeasureEvaluation)) {
                    System.err.println("WARNING: measure '" + measure.getQualifiedName() + "' factor '"
                            + factor.getQualifiedName() + "' does not have a multiMeasureEvaluation, but a "
                            + factoreval.getClass());
                } else {
                    mme = (WeightedSumMultiMeasureEvaluation) factoreval;
                }

                String norm = "NO NORMALIZATION";
                double weight = Double.NaN;
                if (mme != null) {
                    for (Ranking ranking : mme.getRankings()) {
                        if (ranking.getRankedElement() == measure) {
                            weight = ranking.getWeight();
                            if (ranking instanceof MeasureRanking) {
                                MeasureRanking mr = (MeasureRanking) ranking;
                                Function f = mr.getFunction();

                                norm = mr.getRange() + printFunction(f)
                                        + (mr.getNormlizationMeasure() != null
                                                ? mr.getNormlizationMeasure().getQualifiedName()
                                                : "");
                            }
                        }
                    }
                }

                Row r = sheet.createRow(row++);

                //               "Measure Name", 
                //               "Tool",
                //               "Normalization", 
                //               "Measure Description", 
                //               "Measure Weight",
                //               "Influenced Factor", 
                //               "Factor weight",
                //               "Impacted Quality Aspect", 
                //               "Effect of the Impact",
                //               "Rationale for the Impact", 
                //               "Description of the Quality Aspect"

                int cell = 0;
                r.createCell(cell++).setCellValue(measure.getQualifiedName());
                r.createCell(cell++).setCellValue(getToolName(measure));
                r.createCell(cell++).setCellValue(norm);
                r.createCell(cell++).setCellValue(measure.getDescription());
                if (!Double.isNaN(weight)) {
                    r.createCell(cell++).setCellValue(weight);
                } else {
                    r.createCell(cell++).setCellValue("NO WEIGHT GIVEN.");
                }
                r.createCell(cell++).setCellValue(factor.getQualifiedName());
                if (!Double.isNaN(qaweight)) {
                    r.createCell(cell++).setCellValue(qaweight);
                } else {
                    r.createCell(cell++).setCellValue("NO WEIGHT GIVEN.");
                }
                r.createCell(cell++).setCellValue(qa.getQualifiedName());
                r.createCell(cell++).setCellValue(imp.getEffect().getLiteral());
                r.createCell(cell++).setCellValue(imp.getJustification());
                r.createCell(cell++).setCellValue(qa.getDescription());
            }
        }
    }
}

From source file:de.quamoco.qm.editor.excelexport.HumanReadableExcelExporter.java

License:Apache License

private void createMeasureSheet(Workbook workbook) {
    Sheet sheet = workbook.createSheet("Measures");
    sheet.setDefaultColumnWidth(30);

    String[] names = new String[] { "Measure Name", "Tool", "Normalization", "Measure Description",
            "Measure Weight", "Influenced Factor" };

    Row header = sheet.createRow(0);//w  w w . j  av  a2s. c o m
    for (int col = 0; col < names.length; col++) {
        header.createCell(col).setCellValue(names[col]);
    }

    int row = 1;
    for (Measure measure : measures) {
        for (Factor factor : measure.getMeasuresDirect()) {
            Evaluation eval = factor.getActualEvaluation(context);
            WeightedSumMultiMeasureEvaluation mme = null;
            if (eval == null) {
                System.err.println("WARNING: measure '" + measure.getQualifiedName() + "' factor '"
                        + factor.getQualifiedName() + "' does not have an evaluation at all.");
            } else if (!(eval instanceof WeightedSumMultiMeasureEvaluation)) {
                System.err.println("WARNING: measure '" + measure.getQualifiedName() + "' factor '"
                        + factor.getQualifiedName() + "' does not have a multiMeasureEvaluation, but a "
                        + eval.getClass());
            } else {
                mme = (WeightedSumMultiMeasureEvaluation) eval;
            }

            String norm = "NO NORMALIZATION";
            double weight = Double.NaN;
            if (mme != null) {
                for (Ranking ranking : mme.getRankings()) {
                    if (ranking.getRankedElement() == measure) {
                        weight = ranking.getWeight();
                        if (ranking instanceof MeasureRanking) {
                            MeasureRanking mr = (MeasureRanking) ranking;
                            Function f = mr.getFunction();

                            norm = mr.getRange() + printFunction(f)
                                    + (mr.getNormlizationMeasure() != null
                                            ? mr.getNormlizationMeasure().getQualifiedName()
                                            : "");
                        }
                    }
                }
            }

            Row r = sheet.createRow(row++);

            int cell = 0;
            r.createCell(cell++).setCellValue(measure.getQualifiedName());
            r.createCell(cell++).setCellValue(getToolName(measure));
            r.createCell(cell++).setCellValue(norm);
            r.createCell(cell++).setCellValue(measure.getDescription());
            if (!Double.isNaN(weight)) {
                r.createCell(cell++).setCellValue(weight);
            } else {
                r.createCell(cell++).setCellValue("NO WEIGHT GIVEN.");
            }
            r.createCell(cell++).setCellValue(factor.getQualifiedName());
        }
    }
}

From source file:de.quamoco.qm.editor.excelexport.HumanReadableExcelExporter.java

License:Apache License

private void createFactorSheet(Workbook workbook) {
    Sheet sheet = workbook.createSheet("Factors");
    sheet.setDefaultColumnWidth(30);

    String[] names = new String[] { "Factor Name", "Factor Description", "Factor Weight",
            "Impacted Quality Aspect", "Effect of the Impact", "Rationale for the Impact" };

    Row header = sheet.createRow(0);//from   w  ww. j ava 2  s.c  om
    for (int col = 0; col < names.length; col++) {
        header.createCell(col).setCellValue(names[col]);
    }

    int row = 1;
    for (Factor factor : factors) {

        if (factor.getCharacterizes() == null) {
            continue;
        }

        for (Impact imp : factor.getInfluences()) {
            Factor qa = imp.getTarget();
            Evaluation eval = qa.getActualEvaluation(context);

            WeightedSumFactorAggregation wsf = null;
            if (!(eval instanceof WeightedSumFactorAggregation)) {
                System.err.println("WARNING: factor '" + factor + "' qa '" + qa
                        + "' does not have a WeightedSumFactorAggregation");
            } else {
                wsf = (WeightedSumFactorAggregation) eval;
            }

            double weight = Double.NaN;
            if (wsf != null) {
                for (Ranking ranking : wsf.getRankings()) {
                    if (ranking.getRankedElement() == factor) {
                        weight = ranking.getWeight();
                    }
                }
            }

            Row r = sheet.createRow(row++);

            int cell = 0;
            r.createCell(cell++).setCellValue(factor.getQualifiedName());
            r.createCell(cell++).setCellValue(factor.getDescription());
            r.createCell(cell++).setCellValue(weight);
            r.createCell(cell++).setCellValue(qa.getQualifiedName());
            r.createCell(cell++).setCellValue(imp.getEffect().getLiteral());
            r.createCell(cell++).setCellValue(imp.getJustification());
        }
    }
}

From source file:de.quamoco.qm.editor.excelexport.HumanReadableExcelExporter.java

License:Apache License

private void createQASheet(Workbook workbook) {
    Sheet sheet = workbook.createSheet("QualityAspects");
    sheet.setDefaultColumnWidth(30);

    String[] names = new String[] { "QualityAspect Name", "Quality Aspect Description" };

    Row header = sheet.createRow(0);/*from ww  w  . j  a  v a2s  .c  o  m*/
    for (int col = 0; col < names.length; col++) {
        header.createCell(col).setCellValue(names[col]);
    }

    int row = 1;
    for (Factor factor : factors) {

        if (factor.getCharacterizes() != null) {
            continue;
        }

        Row r = sheet.createRow(row++);

        int cell = 0;
        r.createCell(cell++).setCellValue(factor.getQualifiedName());
        r.createCell(cell++).setCellValue(factor.getDescription());
    }
}