Example usage for org.apache.poi.ss.usermodel Workbook setSheetName

List of usage examples for org.apache.poi.ss.usermodel Workbook setSheetName

Introduction

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

Prototype

void setSheetName(int sheet, String name);

Source Link

Document

Set the sheet name.

Usage

From source file:net.sf.excelutils.tags.SheetTag.java

License:Apache License

private void setSheetName(Object context, Workbook wb, int sheetIndex, String sheetName) {
    // set sheetName
    if (!"".equals(sheetName)) {
        Object o = ExcelParser.getValue(context, sheetName);
        if (null != o && !"".equals(o)) {
            sheetName = o.toString();//  w  w w  .  j  a v a2 s . c  o m
        }
        wb.setSheetName(sheetIndex, sheetName);
    }
}

From source file:org.alfresco.repo.web.scripts.person.UserCSVUploadGet.java

License:Open Source License

@Override
protected void populateBody(Object resource, Workbook workbook, Sheet sheet, List<QName> properties)
        throws IOException {
    // Set the sheet name
    workbook.setSheetName(0, "UsersToAdd");

    // Add a blank line
    sheet.createRow(1);// w  ww  .j a v a  2s .  com
}

From source file:org.alfresco.repo.web.scripts.TestDeclarativeSpreadsheetWebScriptGet.java

License:Open Source License

@Override
protected void populateBody(Object resource, Workbook workbook, Sheet sheet, List<QName> properties)
        throws IOException {
    // Set the sheet name
    workbook.setSheetName(0, "test");
}

From source file:org.bbreak.excella.reports.processor.ReportProcessor.java

License:Open Source License

/**
 * ???????//from w  w  w .jav  a2s .c om
 *
 * @param workbook 
 * @param reportBook 
 * @return ?????
 */
private Set<String> expandTemplate(Workbook workbook, ReportBook reportBook) {

    Set<String> delSheetNames = new TreeSet<String>(Collections.reverseOrder());
    Set<String> useSheetNames = new HashSet<String>();

    // ????
    for (ReportSheet reportSheet : reportBook.getReportSheets()) {

        if (reportSheet != null) {
            if (reportSheet.getSheetName().equals(reportSheet.getTemplateName())) {
                // ?????
                int lastSheetIndex = workbook.getNumberOfSheets() - 1;
                workbook.setSheetOrder(reportSheet.getSheetName(), lastSheetIndex);
                useSheetNames.add(reportSheet.getTemplateName());
            } else {
                int tempIdx = workbook.getSheetIndex(reportSheet.getTemplateName());
                Sheet sheet = workbook.cloneSheet(tempIdx);
                ReportsUtil.copyPrintSetup(workbook, tempIdx, sheet);
                workbook.setSheetName(workbook.getSheetIndex(sheet), reportSheet.getSheetName());
                delSheetNames.add(reportSheet.getTemplateName());
            }
        }
    }

    // ?
    for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
        Sheet sheet = workbook.getSheetAt(i);
        if (!isOutputSheet(sheet, reportBook)) {
            delSheetNames.add(sheet.getSheetName());
        }
    }

    delSheetNames.removeAll(useSheetNames);

    // ?????

    return delSheetNames;

}

From source file:org.cgiar.ccafs.ap.summaries.projects.xlsx.BudgetPerPartnersSummaryXLS.java

License:Open Source License

/**
 * This method is used to generate the csv file for the ProjectLeading institutions.
 * // ww  w .  j  a  v  a2s. c  o m
 * @param projectPartnerInstitutions is the list of institutions to be added
 * @param projectList is the list with the projects related to each institution
 */
public byte[] generateXLS(List<Map<String, Object>> informationBudgetByPartnersReport, int year) {

    try {

        // Writting headers
        String[] headers = new String[] { "Project Id", "Project title", "Partner", "Total Budget W1/W2 (USD)",
                "Gender W1/W2 (USD)", "Total Budget W3/Bilateral (USD)", "Gender W3/Bilateral (USD)" };

        // Writting style content
        int[] headersType = new int[] { BaseXLS.COLUMN_TYPE_HYPERLINK, BaseXLS.COLUMN_TYPE_TEXT_LONG,
                BaseXLS.COLUMN_TYPE_TEXT_LONG, BaseXLS.COLUMN_TYPE_BUDGET, BaseXLS.COLUMN_TYPE_BUDGET,
                BaseXLS.COLUMN_TYPE_BUDGET, BaseXLS.COLUMN_TYPE_BUDGET };

        Workbook workbook = xls.initializeWorkbook(true);

        // renaming sheet
        workbook.setSheetName(0, "Budget Summary Per Partners");
        Sheet sheet = workbook.getSheetAt(0);

        xls.initializeSheet(sheet, headersType);

        // Writing the sheet in the yellow box
        xls.writeTitleBox(sheet, xls.getText("summaries.budget.partners.summary.name").concat(" " + year));

        // Writing the sheet in the yellow box
        xls.writeDescription(sheet, xls.getText("summaries.budget.partners.summary.description"));

        // write text box
        xls.createLogo(workbook, sheet);

        xls.writeHeaders(sheet, headers);

        this.addContent(informationBudgetByPartnersReport, sheet);

        // this.flush();
        xls.writeWorkbook();

        byte[] byteArray = xls.getBytes();

        // Closing streams.
        xls.closeStreams();

        return byteArray;

    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.cgiar.ccafs.ap.summaries.projects.xlsx.ImpactPathwayContributionsSummaryXLS.java

License:Open Source License

/**
 * This method is used to generate the xls file for the ProjectLeading institutions.
 * /*from w  w  w. jav a 2  s . co  m*/
 * @param projectList is the list with the projects partner leaders
 * @return a byte array with the information provided for the xls file.
 */
public byte[] generateXLS(List<Map<String, Object>> projectList) {

    Workbook workbook = xls.initializeWorkbook(true);

    /***************** Indicator Contribution Report Project Level ******************/
    // Defining headers
    String[] headersProject = new String[] { "Project Id", "Title", "Flagship", "Outcome statement",
            "Indicator", "Target", "Target narrative", "Target gender " };

    // Defining header types
    int[] headerTypesProject = { BaseXLS.COLUMN_TYPE_HYPERLINK, BaseXLS.COLUMN_TYPE_TEXT_LONG,
            BaseXLS.COLUMN_TYPE_TEXT_SHORT, BaseXLS.COLUMN_TYPE_TEXT_LONG, BaseXLS.COLUMN_TYPE_TEXT_LONG,
            BaseXLS.COLUMN_TYPE_TEXT_LONG, BaseXLS.COLUMN_TYPE_TEXT_LONG, BaseXLS.COLUMN_TYPE_TEXT_LONG };

    // creating sheet
    Sheet sheet = workbook.getSheetAt(0);
    workbook.setSheetName(0, "Impact Pathway Contributions");

    try {
        xls.initializeSheet(sheet, headerTypesProject);

        xls.writeHeaders(sheet, headersProject);
        this.addContent(projectList, sheet);

        // Set description
        xls.writeDescription(sheet, "");

        // write text box
        xls.writeTitleBox(sheet, "Impact Pathway Contributions Summary");

        // write text box
        xls.createLogo(workbook, sheet);

        xls.writeWorkbook();

        byte[] byteArray = xls.getBytes();

        // Closing streams.
        xls.closeStreams();

        return byteArray;

    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;

}

From source file:org.cgiar.ccafs.ap.summaries.projects.xlsx.LeadInstitutionPartnersSummaryXLS.java

License:Open Source License

/**
 * This method is used to generate the csv file for the ProjectLeading institutions.
 * /*from ww w. jav a  2 s .c  om*/
 * @param projectPartnerInstitutions is the list of institutions to be added
 * @param projectList is the list with the projects related to each institution
 * @return a byte array with the information provided for the xls file.
 */
public byte[] generateXLS(List<Map<String, Object>> projectLeadingInstitutions) {

    try {

        String[] headers = new String[] { "Institution name", "Institution acronym", "Web site",
                "Country location", "Projects" };

        int[] headerTypes = { BaseXLS.COLUMN_TYPE_TEXT_LONG, BaseXLS.COLUMN_TYPE_TEXT_SHORT,
                BaseXLS.COLUMN_TYPE_TEXT_LONG, BaseXLS.COLUMN_TYPE_TEXT_SHORT, BaseXLS.COLUMN_TYPE_TEXT_LONG };

        Workbook workbook = xls.initializeWorkbook(true);
        workbook.setSheetName(0, "  Institutions leading projects");
        Sheet sheet = workbook.getSheetAt(0);

        xls.initializeSheet(sheet, headerTypes);
        xls.writeTitleBox(sheet, "  CCAFS Institutions leading projects");
        xls.writeHeaders(sheet, headers);

        this.addContent(sheet, projectLeadingInstitutions);
        sheet.autoSizeColumn(3);
        // Adding CCAFS logo
        xls.createLogo(workbook, sheet);
        // Set description
        xls.writeDescription(sheet, xls.getText("summaries.leadInstitutionParters.summary.description"));
        xls.writeWorkbook();
        byte[] byteArray = xls.getBytes();
        // Closing streams.
        xls.closeStreams();

        return byteArray;

    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.cgiar.ccafs.ap.summaries.projects.xlsx.LeadProjectPartnersSummaryXLS.java

License:Open Source License

/**
 * This method is used to generate the xls file for the ProjectLeading institutions.
 * /*from  w  ww .j  av a  2  s.c  om*/
 * @param projectList is the list with the projects partner leaders
 * @return a byte array with the information provided for the xls file.
 */
public byte[] generateXLS(List<Map<String, Object>> projectList) {

    try {

        // Defining headers
        String[] headers = new String[] { "Project Id", "Start date", "End date", "Title", "Type", "Summary",
                "Flagship(s)", "Region(s)", "Lead institution", "Leader", "Coordinator", "Total budget W1/W2",
                "Total budget W3/Bilateral" };

        // Defining header types
        int[] headerTypes = { BaseXLS.COLUMN_TYPE_NUMERIC, BaseXLS.COLUMN_TYPE_DATE, BaseXLS.COLUMN_TYPE_DATE,
                BaseXLS.COLUMN_TYPE_TEXT_LONG, BaseXLS.COLUMN_TYPE_TEXT_SHORT, BaseXLS.COLUMN_TYPE_TEXT_LONG,
                BaseXLS.COLUMN_TYPE_TEXT_SHORT, BaseXLS.COLUMN_TYPE_TEXT_SHORT, BaseXLS.COLUMN_TYPE_TEXT_LONG,
                BaseXLS.COLUMN_TYPE_TEXT_LONG, BaseXLS.COLUMN_TYPE_TEXT_LONG, BaseXLS.COLUMN_TYPE_BUDGET,
                BaseXLS.COLUMN_TYPE_BUDGET };

        Workbook workbook = xls.initializeWorkbook(true);

        workbook.setSheetName(0, "Project leaders");
        Sheet sheet = workbook.getSheetAt(0);
        xls.initializeSheet(sheet, headerTypes);
        xls.writeTitleBox(sheet, " CCAFS Project leaders");
        xls.writeHeaders(sheet, headers);

        this.addContent(sheet, projectList);
        sheet.autoSizeColumn(5);
        // Adding CCAFS logo
        xls.createLogo(workbook, sheet);
        // Set description
        xls.writeDescription(sheet, xls.getText("summaries.leadProjectPartners.summary.description"));
        xls.writeWorkbook();
        byte[] byteArray = xls.getBytes();
        // Closing streams.
        xls.closeStreams();

        return byteArray;

    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.cgiar.ccafs.ap.summaries.projects.xlsx.NoLoggedInPartnersSummaryXLS.java

License:Open Source License

/**
 * This method is used to generate the xls file for the partners not having logged in P&R.
 * /*ww  w  . j ava2  s .co m*/
 * @param PartnersInformation is the list of partners to be added
 */
public byte[] generateXLS(List<Map<String, Object>> PartnersInformation) {

    try {

        // Writting headers
        String[] headers = new String[] { "ID", "Name", "Email", "Contact Type", "Related Project Ids", };

        // Writting style content
        int[] headersType = new int[] { BaseXLS.COLUMN_TYPE_NUMERIC, BaseXLS.COLUMN_TYPE_TEXT_SHORT,
                BaseXLS.COLUMN_TYPE_TEXT_SHORT, BaseXLS.COLUMN_TYPE_TEXT_SHORT, BaseXLS.COLUMN_TYPE_TEXT_LONG };

        Workbook workbook = xls.initializeWorkbook(true);

        // renaming sheet
        workbook.setSheetName(0, "Partners not logged in");
        Sheet sheet = workbook.getSheetAt(0);

        xls.initializeSheet(sheet, headersType);

        // Writing the sheet in the yellow box
        xls.writeTitleBox(sheet, xls.getText("summaries.partners.notlogged.summary.name"));

        // Writing the sheet in the yellow box
        xls.writeDescription(sheet, xls.getText("summaries.partners.notlogged.summary.description"));

        // write text box
        xls.createLogo(workbook, sheet);

        xls.writeHeaders(sheet, headers);

        this.addContent(PartnersInformation, sheet);
        sheet.autoSizeColumn(1);

        // this.flush();
        xls.writeWorkbook();

        byte[] byteArray = xls.getBytes();

        // Closing streams.
        xls.closeStreams();

        return byteArray;

    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.cgiar.ccafs.ap.summaries.projects.xlsx.PartnersSummaryXLS.java

License:Open Source License

/**
 * This method is used to generate the csv file for the ProjectPartner institutions.
 *
 * @param projectPartnerInstitutions is the list of institutions to be added
 * @param projectList is the list with the projects related to each institution
 * @return a byte array with the information provided for the xls file.
 *//*  w w  w. ja  v  a  2  s.c  om*/
public byte[] generateCSV(List<Map<String, Object>> projectPartnerInstitutions) {

    try {
        String[] headers = new String[] { "Institution name", "Institution acronym", "Partner type", "Web site",
                "Country location", "Projects" };
        int[] headersType = { BaseXLS.COLUMN_TYPE_TEXT_LONG, BaseXLS.COLUMN_TYPE_TEXT_SHORT,
                BaseXLS.COLUMN_TYPE_TEXT_LONG, BaseXLS.COLUMN_TYPE_TEXT_LONG, BaseXLS.COLUMN_TYPE_TEXT_SHORT,
                BaseXLS.COLUMN_TYPE_TEXT_LONG };

        Workbook workbook = xls.initializeWorkbook(true);
        workbook.setSheetName(0, "Project Partners");
        Sheet sheet = workbook.getSheetAt(0);
        xls.initializeSheet(sheet, headersType);
        xls.writeTitleBox(sheet, "\t    Project Partners");
        xls.writeHeaders(sheet, headers);
        this.addContent(sheet, projectPartnerInstitutions);
        // Adding CCAFS logo
        xls.createLogo(workbook, sheet);
        // Set description
        xls.writeDescription(sheet, xls.getText("summaries.projectPartners.summary.description"));
        xls.writeWorkbook();
        byte[] byteArray = xls.getBytes();
        // Closing streams.
        xls.closeStreams();

        return byteArray;

    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}