Example usage for org.apache.poi.hssf.usermodel HSSFSheet getHeader

List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet getHeader

Introduction

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

Prototype

@Override
    public HSSFHeader getHeader() 

Source Link

Usage

From source file:excel.FileExcel.java

public File excel_mutation_report(ArrayList<MutationReportData> datamutation, KodeNamaKonter konterinfo,
        Date Start, Date End, Date CurrentDate) {
    if (datamutation.size() != 0) {
        DateFormat time = new SimpleDateFormat("hhmm");
        String fileName = "Mutation_" + konterinfo.nama_konter + "_" + fmt.format(CurrentDate) + "_"
                + time.format(CurrentDate) + ".xls";
        File ExcelMutation = new File(fileName);
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet();

        // set page
        sheet.getPrintSetup().setLandscape(false);

        //Set Header Information 
        Header headerPage = sheet.getHeader();
        headerPage.setCenter(HeaderFooter.page());
        headerPage.setRight(fileName);/* w  w w .  ja  va2 s  .  c  o  m*/

        //Set Footer Information with Page Numbers
        Footer footerPage = sheet.getFooter();
        footerPage.setCenter("Page " + HeaderFooter.page() + " of " + HeaderFooter.numPages());

        // prepare variable to edit the xls
        HSSFRow header;
        HSSFCell cell;
        HSSFCellStyle titlestyle = workbook.createCellStyle();
        HSSFCellStyle headerstyle = workbook.createCellStyle();
        HSSFCellStyle datastyle = workbook.createCellStyle();
        HSSFFont boldfont = workbook.createFont();
        HSSFFont normalfont = workbook.createFont();

        // create the title 
        header = sheet.createRow(1);
        cell = header.createCell(1);
        boldfont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        titlestyle.setFont(boldfont);
        titlestyle.setAlignment(CellStyle.ALIGN_CENTER);
        titlestyle.setBorderTop(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderBottom(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderRight(HSSFCellStyle.BORDER_NONE);
        cell.setCellStyle(titlestyle);
        cell.setCellValue("TABEL MUTATION REPORT");
        sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 3));

        // create file info
        // create file info
        header = sheet.createRow(3);
        cell = header.createCell(2);
        cell.setCellValue("Konter : ");
        cell = header.createCell(3);
        cell.setCellValue(konterinfo.nama_konter);

        header = sheet.createRow(4);
        cell = header.createCell(2);
        cell.setCellValue("Tanggal : ");
        cell = header.createCell(3);
        cell.setCellValue(fmt.format(Start));
        cell = header.createCell(4);
        cell.setCellValue("-");
        cell = header.createCell(5);
        cell.setCellValue(fmt.format(End));

        // create the header
        headerstyle.setFont(boldfont);
        headerstyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
        header = sheet.createRow(7);
        cell = header.createCell(1);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Tanggal");
        cell = header.createCell(2);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Barang Masuk");
        cell = header.createCell(3);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Setoran Masuk");
        sheet.autoSizeColumn(1);
        sheet.autoSizeColumn(2);
        sheet.autoSizeColumn(3);

        normalfont.setBoldweight(Font.BOLDWEIGHT_NORMAL);
        datastyle.setFont(normalfont);
        datastyle.setAlignment(CellStyle.ALIGN_RIGHT);
        datastyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderRight(HSSFCellStyle.BORDER_THIN);

        int i;
        // fill the data
        for (i = 0; i < datamutation.size(); i++) {
            header = sheet.createRow(8 + i);
            cell = header.createCell(1);
            cell.setCellStyle(datastyle);
            cell.setCellValue(fmt.format(datamutation.get(i).tanggal_mutasi));
            cell = header.createCell(2);
            cell.setCellStyle(datastyle);
            cell.setCellValue(datamutation.get(i).barang_keluar);
            cell = header.createCell(3);
            cell.setCellStyle(datastyle);
            cell.setCellValue(datamutation.get(i).setoran);
        }

        datastyle.setFont(boldfont);
        header = sheet.createRow(i + 10);
        cell = header.createCell(1);
        cell.setCellStyle(datastyle);
        cell.setCellValue("Hutang Konter");
        cell = header.createCell(2);
        cell.setCellStyle(datastyle);
        cell.setCellValue(fmt.format(CurrentDate));
        cell = header.createCell(3);
        cell.setCellStyle(datastyle);
        cell.setCellValue(konterinfo.hutang_konter);
        sheet.autoSizeColumn(1);
        sheet.autoSizeColumn(2);
        sheet.autoSizeColumn(3);

        try {
            FileOutputStream out = new FileOutputStream(ExcelMutation);
            workbook.write(out);
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            ExcelMutation = null;
        } catch (IOException e) {
            e.printStackTrace();
            ExcelMutation = null;
        }
        return ExcelMutation;
    } else {
        return null;
    }
}

From source file:io.vertigo.dynamo.plugins.export.xls.XLSExporter.java

License:Apache License

/**
 * Ralise l'export des donnes de contenu et de la ligne d'en-tte.
 *
 * @param parameters Paramtre de cet export
 * @param workbook Document excel/*w  w  w.j a va  2 s . c  o m*/
 * @param sheet Feuille Excel
 * @param forceLandscape Indique si le parametrage force un affichage en paysage
 */
private void exportData(final ExportSheet parameters, final HSSFWorkbook workbook, final HSSFSheet sheet,
        final boolean forceLandscape) {
    initHssfStyle(workbook);

    // Column width
    final Map<Integer, Double> maxWidthPerColumn = new HashMap<>();
    if (parameters.hasDtObject()) {
        exportObject(parameters, workbook, sheet, maxWidthPerColumn);
    } else {
        exportList(parameters, workbook, sheet, maxWidthPerColumn);
    }
    // On definit la largeur des colonnes:
    double totalWidth = 0;
    int cellIndex;
    for (final Map.Entry<Integer, Double> entry : maxWidthPerColumn.entrySet()) {
        cellIndex = entry.getKey();
        final Double maxLength = entry.getValue();
        final double usesMaxLength = Math.min(maxLength.doubleValue(), MAX_COLUMN_WIDTH);
        sheet.setColumnWidth(cellIndex, Double.valueOf(usesMaxLength * 256).intValue());
        totalWidth += usesMaxLength;
    }
    /**
     * @todo ne serait-il pas plus simple d'utilisersheet.autoSizeColumn(i); de poi 3.0.1 ?
     */

    // note: il ne semble pas simple de mettre title et author dans les
    // proprits du document
    final String title = parameters.getTitle();
    if (title != null) {
        final HSSFHeader header = sheet.getHeader();
        header.setLeft(title);
    }
    sheet.setHorizontallyCenter(true);
    sheet.getPrintSetup().setPaperSize(PrintSetup.A4_PAPERSIZE);
    if (forceLandscape || totalWidth > 85) {
        sheet.getPrintSetup().setLandscape(true);
    }

    // On dfinit le footer
    final HSSFFooter footer = sheet.getFooter();
    footer.setRight("Page " + HeaderFooter.page() + " / " + HeaderFooter.numPages());
}

From source file:io.vertigo.quarto.plugins.export.xls.XLSExporter.java

License:Apache License

/**
 * Ralise l'export des donnes de contenu et de la ligne d'en-tte.
 *
 * @param parameters Paramtre de cet export
 * @param workbook Document excel/*from  w ww  .jav  a 2  s . co m*/
 * @param sheet Feuille Excel
 * @param forceLandscape Indique si le parametrage force un affichage en paysage
 */
private void exportData(final ExportSheet parameters, final HSSFWorkbook workbook, final HSSFSheet sheet,
        final boolean forceLandscape) {
    // Column width
    final Map<Integer, Double> maxWidthPerColumn = new HashMap<>();
    if (parameters.hasDtObject()) {
        exportObject(parameters, workbook, sheet, maxWidthPerColumn);
    } else {
        exportList(parameters, workbook, sheet, maxWidthPerColumn);
    }
    // On definit la largeur des colonnes:
    double totalWidth = 0;
    int cellIndex;
    for (final Map.Entry<Integer, Double> entry : maxWidthPerColumn.entrySet()) {
        cellIndex = entry.getKey();
        final Double maxLength = entry.getValue();
        final int usesMaxLength = Double.valueOf(Math.min(maxLength.doubleValue(), MAX_COLUMN_WIDTH))
                .intValue();
        sheet.setColumnWidth(cellIndex, usesMaxLength * 256);
        totalWidth += usesMaxLength;
    }
    /**
     * @todo ne serait-il pas plus simple d'utilisersheet.autoSizeColumn(i); de poi 3.0.1 ?
     */

    // note: il ne semble pas simple de mettre title et author dans les proprits du document
    final String title = parameters.getTitle();
    if (title != null) {
        final HSSFHeader header = sheet.getHeader();
        header.setLeft(title);
    }
    sheet.setHorizontallyCenter(true);
    sheet.getPrintSetup().setPaperSize(PrintSetup.A4_PAPERSIZE);
    if (forceLandscape || totalWidth > 85) {
        sheet.getPrintSetup().setLandscape(true);
    }

    // On dfinit le footer
    final HSSFFooter footer = sheet.getFooter();
    footer.setRight("Page " + HeaderFooter.page() + " / " + HeaderFooter.numPages());
}

From source file:module.siadap.domain.SiadapRootModule.java

License:Open Source License

private void populateSheet(HSSFSheet sheetToWriteTo, boolean considerQuotas, UnitSiadapWrapper unitToSearchIn,
        HSSFWorkbook wb, boolean shouldIncludeEndOfRole, boolean includeHarmonizationResponsibles,
        boolean shouldIncludeUniverse) {

    CreationHelper creationHelper = wb.getCreationHelper();

    // make the sheet fit the page
    PrintSetup ps = sheetToWriteTo.getPrintSetup();

    sheetToWriteTo.setAutobreaks(true);/*from  ww w.j ava2  s.com*/

    ps.setFitHeight((short) 1);
    ps.setFitWidth((short) 1);

    /* ** styles ** */

    // CostCenter style
    HSSFFont costCenterFont = wb.createFont();
    costCenterFont.setColor(HSSFColor.DARK_BLUE.index);
    costCenterFont.setFontHeightInPoints((short) 12);
    costCenterFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    CellStyle costCenterStyle = wb.createCellStyle();
    costCenterStyle.setFont(costCenterFont);

    // make the Unit header style
    CellStyle unitHeaderStyle = wb.createCellStyle();
    unitHeaderStyle.setBorderBottom(CellStyle.BORDER_THIN);
    unitHeaderStyle.setBorderTop(CellStyle.BORDER_THIN);
    unitHeaderStyle.setBorderLeft(CellStyle.BORDER_THIN);
    unitHeaderStyle.setBorderRight(CellStyle.BORDER_THIN);
    unitHeaderStyle.setAlignment(CellStyle.ALIGN_CENTER);
    unitHeaderStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    HSSFFont headerFont = wb.createFont();
    headerFont.setFontHeightInPoints((short) 12);
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerFont.setItalic(true);
    unitHeaderStyle.setFont(headerFont);

    // make the default name style
    CellStyle defaultTextNameStyle = wb.createCellStyle();
    defaultTextNameStyle.setBorderLeft(CellStyle.BORDER_THIN);
    defaultTextNameStyle.setBorderRight(CellStyle.BORDER_THIN);
    defaultTextNameStyle.setBorderBottom(CellStyle.BORDER_NONE);
    defaultTextNameStyle.setBorderTop(CellStyle.BORDER_NONE);
    defaultTextNameStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    HSSFFont defaultFont = wb.createFont();
    defaultFont.setFontHeightInPoints((short) 11);
    defaultTextNameStyle.setFont(defaultFont);

    // make the last line name style
    CellStyle defaultTextNameLastStyle = wb.createCellStyle();
    defaultTextNameLastStyle.setBorderLeft(CellStyle.BORDER_THIN);
    defaultTextNameLastStyle.setBorderRight(CellStyle.BORDER_THIN);
    defaultTextNameLastStyle.setBorderBottom(CellStyle.BORDER_THIN);
    defaultTextNameLastStyle.setBorderTop(CellStyle.BORDER_NONE);
    defaultTextNameLastStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    defaultTextNameLastStyle.setFont(defaultFont);

    // make the default IST-ID last line style
    CellStyle defaultTextIstIdLastStyle = wb.createCellStyle();
    defaultTextIstIdLastStyle.setBorderLeft(CellStyle.BORDER_THIN);
    defaultTextIstIdLastStyle.setBorderBottom(CellStyle.BORDER_THIN);
    defaultTextIstIdLastStyle.setBorderTop(CellStyle.BORDER_NONE);
    defaultTextIstIdLastStyle.setBorderRight(CellStyle.BORDER_THIN);
    defaultTextIstIdLastStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    defaultTextIstIdLastStyle.setAlignment(CellStyle.ALIGN_CENTER);
    defaultTextIstIdLastStyle.setFont(defaultFont);

    // make the default IST-ID style
    CellStyle defaultTextIstIdStyle = wb.createCellStyle();
    defaultTextIstIdStyle.setBorderLeft(CellStyle.BORDER_THIN);
    defaultTextIstIdStyle.setBorderBottom(CellStyle.BORDER_NONE);
    defaultTextIstIdStyle.setBorderTop(CellStyle.BORDER_NONE);
    defaultTextIstIdStyle.setBorderRight(CellStyle.BORDER_THIN);
    defaultTextIstIdStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    defaultTextIstIdStyle.setAlignment(CellStyle.ALIGN_CENTER);
    defaultTextIstIdStyle.setFont(defaultFont);

    // header style

    // CellStyle headerStyle = wb.createCellStyle();
    // HSSFFont headerFont = wb.createFont();
    // headerFont.setFontName(HSSFFont.FONT_ARIAL);
    // headerFont.setFontHeightInPoints((short) 10);
    // headerStyle.setFont(headerFont);
    //

    // first line style
    CellStyle firstLineStyle = wb.createCellStyle();
    HSSFFont firstLineFont = wb.createFont();
    firstLineFont.setColor(HSSFColor.DARK_BLUE.index);
    firstLineFont.setFontHeightInPoints((short) 14);
    firstLineFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    firstLineStyle.setFont(firstLineFont);
    firstLineStyle.setAlignment(CellStyle.ALIGN_CENTER);
    firstLineStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

    // second line style
    CellStyle secondLineStyle = wb.createCellStyle();
    HSSFFont secondLineFont = wb.createFont();
    secondLineFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    secondLineFont.setFontHeightInPoints((short) 14);
    secondLineStyle.setFont(secondLineFont);
    secondLineStyle.setAlignment(CellStyle.ALIGN_CENTER);
    secondLineStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

    // the style for Unit Harmonization responsibles - title
    CellStyle unitHarmonizationTitleStyle = wb.createCellStyle();
    // the BLUE title font - is equal to 'firstLineFont'
    unitHarmonizationTitleStyle.setFont(firstLineFont);
    // now we just have to shade it
    unitHarmonizationTitleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    unitHarmonizationTitleStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    unitHarmonizationTitleStyle.setAlignment(CellStyle.ALIGN_CENTER);

    // the style for Unit Harmonization responsibles - normal

    // let's create the BLUE Arial 14 font for the responsibles of
    // harmonization
    HSSFFont harmonizationResponsibleFont = wb.createFont();
    harmonizationResponsibleFont.setColor(HSSFColor.DARK_BLUE.index);
    harmonizationResponsibleFont.setFontHeightInPoints((short) 14);

    CellStyle unitHarmonizationResponsibleStyle = wb.createCellStyle();
    unitHarmonizationResponsibleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    unitHarmonizationResponsibleStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    unitHarmonizationResponsibleStyle.setFont(harmonizationResponsibleFont);
    unitHarmonizationResponsibleStyle.setAlignment(CellStyle.ALIGN_CENTER);

    /* ** END of styles ** */

    /* ** Immutable IST header ** */

    HSSFHeader header = sheetToWriteTo.getHeader();
    header.setCenter(HSSFHeader.font("Arial", "Normal") + HSSFHeader.fontSize((short) 10));
    header.setCenter("Instituto Superior Tcnico");

    int rowIndex = START_ROW_INDEX;
    int cellIndex = START_CELL_INDEX;

    int firstLineIndex = rowIndex++;
    int secondLineIndex = rowIndex++;
    /* ** Write the first lines with the dates ** */
    HSSFRow row = sheetToWriteTo.createRow(firstLineIndex);
    HSSFCell cell = row.createCell(cellIndex);
    cell.setCellValue("SIADAP - LISTA DE AVALIADORES " + unitToSearchIn.getYear());
    cell.setCellStyle(firstLineStyle);
    sheetToWriteTo
            .addMergedRegion(new CellRangeAddress(firstLineIndex, firstLineIndex, cellIndex, cellIndex + 3));

    // second line
    if (!considerQuotas) {
        cellIndex = START_CELL_INDEX;
        row = sheetToWriteTo.createRow(secondLineIndex);
        cell = row.createCell(cellIndex);
        cell.setCellValue("PESSOAL CONTRATADO PELA ADIST");
        cell.setCellStyle(secondLineStyle);

    }

    /* ** write the IST logo ** */

    int pictureIdx = wb.addPicture(istLogoBytes, Workbook.PICTURE_TYPE_PNG);
    HSSFPatriarch drawingPatriarch = sheetToWriteTo.createDrawingPatriarch();
    ClientAnchor clientAnchor = creationHelper.createClientAnchor();
    clientAnchor.setCol1(cellIndex);
    clientAnchor.setRow1(rowIndex);
    HSSFPicture picture = drawingPatriarch.createPicture(clientAnchor, pictureIdx);

    // let's give the next item some space
    rowIndex += 6;

    /* ** Dynamic IST footer ** */

    HSSFFooter footer = sheetToWriteTo.getFooter();
    footer.setLeft("Lista gerada em: " + HSSFFooter.date() + " " + HSSFFooter.time());
    footer.setCenter(HSSFFooter.page());
    footer.setRight("SIADAP - Lista de avaliadores " + unitToSearchIn.getYear());

    for (UnitSiadapWrapper eachUnit : unitToSearchIn
            .getAllChildUnits(unitToSearchIn.getConfiguration().getUnitRelations())) {

        Collection<Person> harmonizationResponsibles = eachUnit.getHarmonizationResponsibles();
        if (includeHarmonizationResponsibles && !harmonizationResponsibles.isEmpty()) {
            // let's add the section stating the responsible for
            // Harmonization
            cellIndex = START_CELL_INDEX;
            row = sheetToWriteTo.createRow(++rowIndex);
            // let's merge the row
            sheetToWriteTo.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, cellIndex, cellIndex + 3));
            cell = row.createCell(cellIndex);
            cell.setCellStyle(unitHarmonizationTitleStyle);
            cell.setCellValue("UNIDADE DE HARMONIZAO: " + eachUnit.getName());
            // a 'blank' styled line
            row = sheetToWriteTo.createRow(++rowIndex);
            // merge it
            sheetToWriteTo.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, cellIndex, cellIndex + 3));
            row.createCell(cellIndex).setCellStyle(unitHarmonizationResponsibleStyle);
            // each responsible has one of the following lines
            for (Person harmonizationResponsible : harmonizationResponsibles) {
                cellIndex = START_CELL_INDEX;
                row = sheetToWriteTo.createRow(++rowIndex);
                // merge it
                sheetToWriteTo
                        .addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, cellIndex, cellIndex + 3));
                cell = row.createCell(cellIndex);
                cell.setCellStyle(unitHarmonizationResponsibleStyle);
                cell.setCellValue("RESPONS?VEL PELA HARMONIZAO: " + harmonizationResponsible.getName());
            }
            // and let's add an extra 'blank' styled line
            row = sheetToWriteTo.createRow(++rowIndex);
            sheetToWriteTo.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, cellIndex, cellIndex + 3));
            row.createCell(cellIndex).setCellStyle(unitHarmonizationResponsibleStyle);
            // and a regular one! (skip one in the index)
            ++rowIndex;

        }
        if (eachUnit.getQuotaAwareTotalPeopleWorkingInUnit(false, considerQuotas) > 0) {

            row = sheetToWriteTo.createRow(++rowIndex);
            cellIndex = START_CELL_INDEX;
            // write the unit name and cost center
            String unitNameWithCC = eachUnit.getUnit().getPartyName().getContent();
            if (eachUnit.getUnit().getPartyTypesSet().contains(PartyType.readBy("CostCenter"))) {
                unitNameWithCC += " - " + eachUnit.getUnit().getAcronym();
            }
            cell = row.createCell(cellIndex++);
            sheetToWriteTo.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, --cellIndex, ++cellIndex));
            cell.setCellValue(unitNameWithCC);
            cell.setCellStyle(costCenterStyle);

            /* **** write the Unit header ***** */

            // restart the cell's index
            cellIndex = START_CELL_INDEX;

            // IST id avaliado
            int firstLineAfterUnitNameIndex = ++rowIndex;
            int secondLineAfterUnitNameIndex = ++rowIndex;

            row = sheetToWriteTo.createRow(firstLineAfterUnitNameIndex);
            cell = row.createCell(cellIndex);
            cell.setCellStyle(unitHeaderStyle);
            cell.setCellValue("IST id.");

            row = sheetToWriteTo.createRow(secondLineAfterUnitNameIndex);
            cell = row.createCell(cellIndex);
            cell.setCellStyle(unitHeaderStyle);

            // merge the IST id
            sheetToWriteTo.addMergedRegion(new CellRangeAddress(firstLineAfterUnitNameIndex,
                    secondLineAfterUnitNameIndex, cellIndex, cellIndex));

            // Nome avaliado
            row = sheetToWriteTo.getRow(firstLineAfterUnitNameIndex);
            cell = row.createCell(++cellIndex);
            cell.setCellStyle(unitHeaderStyle);
            cell.setCellValue("Nome");

            row = sheetToWriteTo.getRow(secondLineAfterUnitNameIndex);
            cell = row.createCell(cellIndex);
            cell.setCellStyle(unitHeaderStyle);

            // merge
            sheetToWriteTo.addMergedRegion(new CellRangeAddress(firstLineAfterUnitNameIndex,
                    secondLineAfterUnitNameIndex, cellIndex, cellIndex));

            if (shouldIncludeUniverse) {

                // SIADAP do avaliado
                row = sheetToWriteTo.getRow(firstLineAfterUnitNameIndex);
                cell = row.createCell(++cellIndex);
                cell.setCellStyle(unitHeaderStyle);
                cell.setCellValue("SIADAP");

                row = sheetToWriteTo.getRow(secondLineAfterUnitNameIndex);
                cell = row.createCell(cellIndex);
                cell.setCellStyle(unitHeaderStyle);

                // merge
                sheetToWriteTo.addMergedRegion(new CellRangeAddress(firstLineAfterUnitNameIndex,
                        secondLineAfterUnitNameIndex, cellIndex, cellIndex));
            }

            // Ist id do avaliador
            row = sheetToWriteTo.getRow(firstLineAfterUnitNameIndex);
            cell = row.createCell(++cellIndex);
            cell.setCellStyle(unitHeaderStyle);
            cell.setCellValue("IST id.");

            row = sheetToWriteTo.getRow(secondLineAfterUnitNameIndex);
            cell = row.createCell(cellIndex);
            cell.setCellStyle(unitHeaderStyle);

            // merge
            sheetToWriteTo.addMergedRegion(new CellRangeAddress(firstLineAfterUnitNameIndex,
                    secondLineAfterUnitNameIndex, cellIndex, cellIndex));

            // avaliador
            row = sheetToWriteTo.getRow(firstLineAfterUnitNameIndex);
            cell = row.createCell(++cellIndex);
            cell.setCellStyle(unitHeaderStyle);
            cell.setCellValue("Avaliador");

            row = sheetToWriteTo.getRow(secondLineAfterUnitNameIndex);
            cell = row.createCell(cellIndex);
            cell.setCellStyle(unitHeaderStyle);

            // merge
            sheetToWriteTo.addMergedRegion(new CellRangeAddress(firstLineAfterUnitNameIndex,
                    secondLineAfterUnitNameIndex, cellIndex, cellIndex));

            List<PersonSiadapWrapper> listToUse = (considerQuotas) ? eachUnit.getUnitEmployeesWithQuotas(false)
                    : eachUnit.getUnitEmployeesWithoutQuotas(true);

            // now let's take care of exporting the persons
            for (PersonSiadapWrapper personWrapper : listToUse) {
                row = sheetToWriteTo.createRow(++rowIndex);
                // restart the cell's index
                cellIndex = START_CELL_INDEX;
                String istIdEvaluated = personWrapper.getPerson().getUser().getUsername();
                cell = row.createCell(cellIndex++);
                cell.setCellValue(istIdEvaluated);
                cell.setCellStyle(defaultTextIstIdStyle);

                String nameEvaluatedPerson = personWrapper.getPerson().getName();
                cell = row.createCell(cellIndex++);
                cell.setCellValue(nameEvaluatedPerson);
                cell.setCellStyle(defaultTextNameStyle);

                if (shouldIncludeUniverse) {

                    Siadap siadap = personWrapper.getSiadap();
                    String siadapUniverseToBeWritten = (siadap == null
                            || siadap.getDefaultSiadapUniverse() == null) ? "No definido"
                                    : siadap.getDefaultSiadapUniverse().getLocalizedName();
                    cell = row.createCell(cellIndex++);
                    cell.setCellValue(siadapUniverseToBeWritten);
                    cell.setCellStyle(defaultTextNameStyle);
                }

                PersonSiadapWrapper evaluatorWrapper = personWrapper.getEvaluator();
                String istIdEvaluator = evaluatorWrapper == null ? "-"
                        : evaluatorWrapper.getPerson().getUser().getUsername();
                cell = row.createCell(cellIndex++);
                cell.setCellValue(istIdEvaluator);
                cell.setCellStyle(defaultTextIstIdStyle);

                String nameEvaluatorWrapper = evaluatorWrapper == null ? "-" : evaluatorWrapper.getName();
                cell = row.createCell(cellIndex++);
                cell.setCellValue(nameEvaluatorWrapper);
                cell.setCellStyle(defaultTextNameStyle);

            }
            // let's make a bottom border on the last four cells
            for (int i = START_CELL_INDEX; i < START_CELL_INDEX + 4; i++) {
                cell = row.getCell(i);
                // let's diferentaitate between the IST-id and the name
                if (i == START_CELL_INDEX || i == START_CELL_INDEX + 2) // first
                // cell,
                // IST-ID
                // then.
                // or
                // third
                // cell
                // the
                // other
                // IST-ID
                {
                    cell.setCellStyle(defaultTextIstIdLastStyle);
                } else {
                    cell.setCellStyle(defaultTextNameLastStyle);
                }

            }
            row = sheetToWriteTo.createRow(++rowIndex);
            row = sheetToWriteTo.createRow(++rowIndex);

        }

    }

    sheetToWriteTo.autoSizeColumn(START_CELL_INDEX);
    sheetToWriteTo.autoSizeColumn(START_CELL_INDEX + 1);
    sheetToWriteTo.autoSizeColumn(START_CELL_INDEX + 2);
    sheetToWriteTo.autoSizeColumn(START_CELL_INDEX + 3);
    sheetToWriteTo.autoSizeColumn(START_CELL_INDEX + 4);

    // now let's resize the logo
    picture.resize();
}

From source file:org.adempiere.impexp.AbstractExcelExporter.java

License:Open Source License

protected void createHeaderFooter(HSSFSheet sheet) {
    // Sheet Header
    HSSFHeader header = sheet.getHeader();
    header.setRight(HSSFHeader.page() + " / " + HSSFHeader.numPages());
    // Sheet Footer
    HSSFFooter footer = sheet.getFooter();
    footer.setLeft(Adempiere.ADEMPIERE_R);
    footer.setCenter(Env.getHeader(getCtx(), 0));
    Timestamp now = new Timestamp(System.currentTimeMillis());
    footer.setRight(DisplayType.getDateFormat(DisplayType.DateTime, getLanguage()).format(now));
}

From source file:org.eclipse.scada.ae.ui.views.export.excel.impl.ExportEventsImpl.java

License:Open Source License

private HSSFSheet createSheet(final List<Event> events, final HSSFWorkbook workbook,
        final List<Field> columns) {
    final HSSFSheet sheet = workbook.createSheet(Messages.ExportImpl_ExcelSheet_Name);

    final HSSFHeader header = sheet.getHeader();
    header.setLeft(Messages.ExportImpl_ExcelSheet_Header);
    header.setRight(HeaderFooter.date() + " " + HeaderFooter.time());//$NON-NLS-1$

    final HSSFFooter footer = sheet.getFooter();
    footer.setLeft(String.format(Messages.ExportImpl_ExcelSheet_Footer_1, events.size()));

    footer.setRight(Messages.ExportImpl_ExcelSheet_Footer_2 + HeaderFooter.page()
            + Messages.ExportImpl_ExcelSheet_Footer_3 + HeaderFooter.numPages());

    makeHeader(columns, sheet);/*from   ww  w .j a v  a 2  s  . co  m*/

    final HSSFPrintSetup printSetup = sheet.getPrintSetup();
    printSetup.setLandscape(true);
    printSetup.setFitWidth((short) 1);
    printSetup.setFitHeight((short) 0);
    printSetup.setPaperSize(PrintSetup.A4_PAPERSIZE);

    sheet.setAutoFilter(new CellRangeAddress(0, 0, 0, columns.size() - 1));
    sheet.createFreezePane(0, 1);
    sheet.setFitToPage(true);
    sheet.setAutobreaks(true);

    printSetup.setFooterMargin(0.25);

    sheet.setMargin(Sheet.LeftMargin, 0.25);
    sheet.setMargin(Sheet.RightMargin, 0.25);
    sheet.setMargin(Sheet.TopMargin, 0.25);
    sheet.setMargin(Sheet.BottomMargin, 0.5);

    return sheet;
}

From source file:org.openXpertya.print.export.AbstractExcelExporter.java

License:Open Source License

protected void createHeaderFooter(HSSFSheet sheet) {
    // Sheet Header
    HSSFHeader header = sheet.getHeader();
    header.setRight(HSSFHeader.page() + " / " + HSSFHeader.numPages());
    // Sheet Footer
    HSSFFooter footer = sheet.getFooter();
    footer.setLeft(OpenXpertya.OXP_R);//  w  w  w  .  jav  a 2  s.c o  m
    footer.setCenter(Env.getHeader(getCtx(), 0));
    Timestamp now = new Timestamp(System.currentTimeMillis());
    footer.setRight(DisplayType.getDateFormat(DisplayType.DateTime, getLanguage()).format(now));
}

From source file:org.rti.zcore.dar.report.StockUsageReport.java

License:Apache License

@Override
public void getPatientRegister(Date beginDate, Date endDate, int siteId) {
    Connection conn = null;/*from w  w  w  . j ava  2 s .  c  o  m*/
    try {
        conn = DatabaseUtils.getZEPRSConnection(org.rti.zcore.Constants.DATABASE_ADMIN_USERNAME);

        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFCellStyle boldStyle = wb.createCellStyle();
        HSSFFont font = wb.createFont();
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        boldStyle.setFont(font);

        HSSFCellStyle headerStyle = wb.createCellStyle();
        headerStyle.setWrapText(true);
        headerStyle.setFont(font);
        //log.debug("Before getPatientStockMap:" + DateUtils.getTime());
        HashMap<Long, List<StockControl>> stockMap = InventoryDAO.getPatientStockMap(conn, siteId, beginDate,
                endDate);
        //log.debug("Before EncountersDAO.getAll:" + DateUtils.getTime());
        // loop through all of the items
        //List<Item> items = EncountersDAO.getAll(conn, Long.valueOf(131), "SQL_RETRIEVE_ALL_ADMIN131", Item.class);
        List<Item> items = null;
        Map queries = QueryLoader.instance().load("/" + Constants.SQL_GENERATED_PROPERTIES);
        String sql = (String) queries.get("SQL_RETRIEVE_ALL_ADMIN131") + " ORDER BY item.name";
        ArrayList values = new ArrayList();
        items = DatabaseUtils.getList(conn, Item.class, sql, values);
        //log.debug("Before looping through items:" + DateUtils.getTime());
        //int j = 0;
        boolean generateReport = false;
        for (Item item : items) {
            Boolean useInReport = item.getUse_in_report();
            Long itemId = item.getId();
            useInReport = Boolean.TRUE;
            if ((useInReport != null) && (useInReport.booleanValue() == Boolean.TRUE)) {
                List<StockControl> patientStockChanges = stockMap.get(itemId);
                if (patientStockChanges == null) {
                    patientStockChanges = new ArrayList<StockControl>();
                }
                List<StockControl> stockChanges = InventoryDAO.getStockEncounterChanges(conn, itemId, siteId,
                        beginDate, endDate, null, patientStockChanges);
                int stockChangesSize = stockChanges.size();
                //if ((stockChangesSize > 0) ||  ((stockChangesSize == 0 && (item.getUse_in_report() != null)  && (!item.getUse_in_report().equals(Boolean.FALSE))))) {
                if ((stockChangesSize > 0)) {
                    generateReport = true;
                    StockReport stockReport = InventoryDAO.generateStockSummary(conn, itemId, beginDate,
                            stockChanges, false);
                    // populate the common fields
                    //HSSFSheet sheet  = wb.getSheetAt(j);
                    String fixedName = StringManipulation.escapeString(item.getName()).replace("/", " ")
                            .replace("\\", " ").replace(",", "_").replace("[", "").replace("(", "-")
                            .replace(")", "-");
                    int lenName = fixedName.length();
                    String itemIdString = String.valueOf(itemId);
                    int lenItemId = itemIdString.length();
                    String uniqueName = null;
                    if ((lenName + lenItemId) < 31) {
                        uniqueName = fixedName + "_" + itemId;
                        //log.debug(itemId + " size: " + uniqueName.length());
                    } else {
                        int offset = (30 - lenItemId) - 1;
                        if (lenName > offset) {
                            uniqueName = fixedName.substring(0, offset) + "_" + itemIdString;
                            //log.debug(itemId + " size: " + uniqueName.length());
                        } else {
                            uniqueName = fixedName + "_" + itemId;
                        }
                    }
                    HSSFSheet sheet = null;
                    try {
                        sheet = wb.createSheet(uniqueName);
                    } catch (IllegalArgumentException e) {
                        log.debug("Problem with name : " + uniqueName + " Error: " + e.getMessage());
                        //this.setType("error");
                        // e.printStackTrace();
                    }
                    String code = "";
                    if (item.getCode() != null) {
                        code = " (" + item.getCode() + ")";
                    }
                    if (sheet != null) {
                        //sheet.createRow(0).createCell(0).setCellValue(new HSSFRichTextString(item.getName() + code));
                        HSSFHeader header = sheet.getHeader();
                        header.setCenter(item.getName() + code);
                        /*HSSFCell titleCell = sheet.createRow(0).createCell(0);
                        titleCell.setCellStyle(boldStyle);
                        titleCell.setCellValue(new HSSFRichTextString(item.getName() + code));*/
                        //sheet.createRow(2).createCell(0).setCellValue(new HSSFRichTextString("Beginning Balance"));
                        HSSFRow row = sheet.createRow(0);
                        row.setHeightInPoints((3 * sheet.getDefaultRowHeightInPoints()));

                        HSSFCell cell = row.createCell(0);
                        cell.setCellStyle(headerStyle);
                        cell.setCellValue(new HSSFRichTextString("Beginning \nBalance"));

                        //sheet.getRow(0).createCell(1).setCellValue(new HSSFRichTextString("Quantity Received this period"));
                        cell = row.createCell(1);
                        cell.setCellStyle(headerStyle);
                        cell.setCellValue(new HSSFRichTextString("Quantity \nReceived \nthis period"));
                        //sheet.getRow(0).createCell(2).setCellValue(new HSSFRichTextString("Quantity dispensed this period"));
                        cell = row.createCell(2);
                        cell.setCellStyle(headerStyle);
                        cell.setCellValue(new HSSFRichTextString("Quantity \ndispensed \nthis period"));
                        //sheet.getRow(0).createCell(3).setCellValue(new HSSFRichTextString("Total Issued to Patients"));
                        cell = row.createCell(3);
                        cell.setCellStyle(headerStyle);
                        cell.setCellValue(new HSSFRichTextString("Total Issued \nto Patients"));
                        //sheet.getRow(0).createCell(4).setCellValue(new HSSFRichTextString("Positive Adjustments"));
                        cell = row.createCell(4);
                        cell.setCellStyle(headerStyle);
                        cell.setCellValue(new HSSFRichTextString("Positive \nAdjustments"));
                        //sheet.getRow(0).createCell(5).setCellValue(new HSSFRichTextString("Negative Adjustments"));
                        cell = row.createCell(5);
                        cell.setCellStyle(headerStyle);
                        cell.setCellValue(new HSSFRichTextString("Negative \nAdjustments"));
                        //sheet.getRow(0).createCell(6).setCellValue(new HSSFRichTextString("Ending Balance / Physical Count"));
                        cell = row.createCell(6);
                        cell.setCellStyle(headerStyle);
                        cell.setCellValue(new HSSFRichTextString("Ending Balance \nPhysical Count"));

                        sheet.autoSizeColumn((short) 0);
                        sheet.autoSizeColumn((short) 1);
                        sheet.autoSizeColumn((short) 2);
                        sheet.autoSizeColumn((short) 3);
                        sheet.autoSizeColumn((short) 4);
                        sheet.autoSizeColumn((short) 5);
                        sheet.autoSizeColumn((short) 6);

                        sheet.createRow(1).createCell(0).setCellValue(stockReport.getBalanceBF());
                        sheet.getRow(1).createCell(1).setCellValue(stockReport.getAdditionsTotal());
                        sheet.getRow(1).createCell(2).setCellValue(stockReport.getDeletionsTotal());
                        sheet.getRow(1).createCell(3).setCellValue(stockReport.getTotalDispensed());
                        sheet.getRow(1).createCell(4).setCellValue(stockReport.getPosAdjustments());
                        sheet.getRow(1).createCell(5).setCellValue(stockReport.getNegAdjustments());
                        sheet.getRow(1).createCell(6).setCellValue(stockReport.getOnHand());

                        row = sheet.createRow(4);
                        row.setHeightInPoints((3 * sheet.getDefaultRowHeightInPoints()));

                        //sheet.createRow(4).createCell(0).setCellValue(new HSSFRichTextString("Date"));
                        cell = row.createCell(0);
                        cell.setCellStyle(headerStyle);
                        cell.setCellValue(new HSSFRichTextString("Date"));
                        //sheet.getRow(4).createCell(1).setCellValue(new HSSFRichTextString("Type of Stock Change"));
                        cell = row.createCell(1);
                        cell.setCellStyle(headerStyle);
                        cell.setCellValue(new HSSFRichTextString("Type of \nStock \nChange"));
                        //sheet.getRow(4).createCell(2).setCellValue(new HSSFRichTextString("Expiry Date"));
                        cell = row.createCell(2);
                        cell.setCellStyle(headerStyle);
                        cell.setCellValue(new HSSFRichTextString("Expiry \nDate"));
                        //sheet.getRow(4).createCell(3).setCellValue(new HSSFRichTextString("Reference / Notes"));
                        cell = row.createCell(3);
                        cell.setCellStyle(headerStyle);
                        cell.setCellValue(new HSSFRichTextString("Reference/ \n Notes"));
                        //sheet.getRow(4).createCell(4).setCellValue(new HSSFRichTextString("Additions"));
                        cell = row.createCell(4);
                        cell.setCellStyle(headerStyle);
                        cell.setCellValue(new HSSFRichTextString("Additions"));
                        //sheet.getRow(4).createCell(5).setCellValue(new HSSFRichTextString("Subtractions"));
                        cell = row.createCell(5);
                        cell.setCellStyle(headerStyle);
                        cell.setCellValue(new HSSFRichTextString("Subtractions"));
                        //sheet.getRow(4).createCell(6).setCellValue(new HSSFRichTextString("Recorded Balance"));
                        cell = row.createCell(6);
                        cell.setCellStyle(headerStyle);
                        cell.setCellValue(new HSSFRichTextString("Recorded \nBalance"));
                        //sheet.getRow(4).createCell(7).setCellValue(new HSSFRichTextString("Calculated Balance"));
                        cell = row.createCell(7);
                        cell.setCellStyle(headerStyle);
                        cell.setCellValue(new HSSFRichTextString("Calculated \nBalance"));

                        sheet.autoSizeColumn((short) 7);

                        int k = 4;

                        for (StockControl stockControl : stockChanges) {
                            if (stockControl.getDate_of_record() != null) {
                                k++;
                                String stockChangeTypeString = null;
                                Integer posAdjust = null;
                                Integer negAdjust = null;
                                if (stockControl.getType_of_change() != null) {
                                    int stockChangeType = stockControl.getType_of_change();
                                    switch (stockChangeType) {
                                    case 3263:
                                        stockChangeTypeString = "Received";
                                        posAdjust = stockControl.getChange_value();
                                        break;
                                    case 3264:
                                        stockChangeTypeString = "Issued";
                                        negAdjust = stockControl.getChange_value();
                                        break;
                                    case 3265:
                                        stockChangeTypeString = "Losses";
                                        negAdjust = stockControl.getChange_value();
                                        break;
                                    case 3266:
                                        stockChangeTypeString = "Pos. Adjust.";
                                        posAdjust = stockControl.getChange_value();
                                        break;
                                    case 3267:
                                        stockChangeTypeString = "Neg. Adjust.";
                                        negAdjust = stockControl.getChange_value();
                                        break;
                                    case 3279:
                                        stockChangeTypeString = "Out-of-stock";
                                        break;

                                    default:
                                        break;
                                    }
                                }

                                row = sheet.createRow(k);

                                if (stockControl.getDate_of_record() != null) {
                                    Date dateRecord = stockControl.getDate_of_record();
                                    row.createCell(0)
                                            .setCellValue(new HSSFRichTextString(dateRecord.toString()));
                                } else {
                                    row.createCell(0).setCellValue(new HSSFRichTextString(""));
                                }
                                row.createCell(1).setCellValue(new HSSFRichTextString(stockChangeTypeString));
                                if (stockControl.getExpiry_date() != null) {
                                    Date expiryDate = stockControl.getExpiry_date();
                                    row.createCell(2)
                                            .setCellValue(new HSSFRichTextString(expiryDate.toString()));
                                } else {
                                    row.createCell(2).setCellValue(new HSSFRichTextString(""));
                                }
                                row.createCell(3).setCellValue(new HSSFRichTextString(stockControl.getNotes()));
                                if (posAdjust != null) {
                                    row.createCell(4).setCellValue(posAdjust);
                                }
                                if (negAdjust != null) {
                                    row.createCell(5).setCellValue(negAdjust);
                                }
                                if (stockControl.getBalance() != null) {
                                    row.createCell(6).setCellValue(stockControl.getBalance());
                                }
                                if (stockControl.getComputedBalance() != null) {
                                    row.createCell(7).setCellValue(stockControl.getComputedBalance());
                                }
                            }
                        }
                    }
                }
            }
            //j++;
        }
        if (generateReport) {
            FileOutputStream stream = new FileOutputStream(this.getReportPath());
            wb.write(stream);
            stream.close();
        } else {
            this.setType("empty");
        }

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            conn.close();
        } catch (SQLException e) {
            log.error(e);
        }
    }
}