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

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

Introduction

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

Prototype

void removeSheetAt(int index);

Source Link

Document

Removes sheet at the given index

Usage

From source file:org.spdx.spdxspreadsheet.OriginsSheetV0d9d4.java

License:Apache License

public static void create(Workbook wb, String sheetName) {
    int sheetNum = wb.getSheetIndex(sheetName);
    if (sheetNum >= 0) {
        wb.removeSheetAt(sheetNum);
    }/*from  w w w.j av a  2s .  c  o  m*/

    CellStyle headerStyle = AbstractSheet.createHeaderStyle(wb);
    CellStyle centerStyle = AbstractSheet.createCenterStyle(wb);
    CellStyle wrapStyle = AbstractSheet.createLeftWrapStyle(wb);
    Sheet sheet = wb.createSheet(sheetName);
    Row row = sheet.createRow(0);
    for (int i = 0; i < HEADER_TITLES.length; i++) {
        sheet.setColumnWidth(i, COLUMN_WIDTHS[i] * 256);
        if (LEFT_WRAP[i]) {
            sheet.setDefaultColumnStyle(i, wrapStyle);
        } else if (CENTER_NOWRAP[i]) {
            sheet.setDefaultColumnStyle(i, centerStyle);
        }
        Cell cell = row.createCell(i);
        cell.setCellStyle(headerStyle);
        cell.setCellValue(HEADER_TITLES[i]);
    }
    Row dataRow = sheet.createRow(1);
    Cell ssVersionCell = dataRow.createCell(SPREADSHEET_VERSION_COL);
    ssVersionCell.setCellValue(SPDXSpreadsheet.CURRENT_VERSION);
}

From source file:org.spdx.spdxspreadsheet.PackageInfoSheetV09d2.java

License:Apache License

public static void create(Workbook wb, String sheetName) {
    int sheetNum = wb.getSheetIndex(sheetName);
    if (sheetNum >= 0) {
        wb.removeSheetAt(sheetNum);
    }/* ww  w .  j  av a  2 s  .c o m*/
    Sheet sheet = wb.createSheet(sheetName);
    CellStyle headerStyle = AbstractSheet.createHeaderStyle(wb);
    CellStyle defaultStyle = AbstractSheet.createLeftWrapStyle(wb);
    Row row = sheet.createRow(0);
    for (int i = 0; i < HEADER_TITLES.length; i++) {
        sheet.setColumnWidth(i, COLUMN_WIDTHS[i] * 256);
        sheet.setDefaultColumnStyle(i, defaultStyle);
        Cell cell = row.createCell(i);
        cell.setCellStyle(headerStyle);
        cell.setCellValue(HEADER_TITLES[i]);
    }
}

From source file:org.spionen.james.jamesfile.ExcelJamesFile.java

License:Open Source License

public void writeFile(Map<Long, Subscriber> subscribers, File file) throws IOException {
    // Create the workbook from file first
    Workbook wb;
    try {/*from w  w  w.ja  v  a  2s . c o m*/
        wb = WorkbookFactory.create(file);
    } catch (InvalidFormatException | IOException ife) {
        // If it fails, just create a blank one
        if (file.getName().endsWith(".xlsx")) {
            wb = new XSSFWorkbook();
        } else {
            wb = new HSSFWorkbook();
        }
    }

    // First, remove all existing sheets
    int sheets = wb.getNumberOfSheets();
    for (int i = 0; i < sheets; i++) {
        wb.removeSheetAt(i);
    }

    Sheet s = wb.createSheet();
    // Create top row of sheet with header data
    Row top = s.createRow(0);
    FieldType[] fields = FieldType.standardOrder();
    for (int i = 0; i < fields.length; i++) {
        Cell c = top.createCell(i);
        c.setCellValue(fields[i].getDesc());
    }

    // And then, iterate through all subscribers
    int j = 1;
    for (long abNr : subscribers.keySet()) {
        Subscriber sub = subscribers.get(abNr);
        Row r = s.createRow(j);
        for (int k = 0; k < fields.length; k++) {
            Cell c = r.createCell(k, Cell.CELL_TYPE_STRING);
            String str = sub.getByField(fields[k]);
            if (str != null) {
                c.setCellValue(str);
            } else {
                c.setCellType(Cell.CELL_TYPE_BLANK);
            }
        }
        j++;
    }

    wb.write(new FileOutputStream(file));
}

From source file:org.wso2.carbon.dataservices.sql.driver.query.drop.ExcelDropQuery.java

License:Open Source License

private synchronized void executeSQL() throws SQLException {
    TExcelConnection excelConnection = (TExcelConnection) this.getConnection();
    //begin transaction,
    excelConnection.beginExcelTransaction();
    Workbook workbook = excelConnection.getWorkbook();

    if (!isSheetExists(workbook)) {
        throw new SQLException("Excel sheet named '" + this.getTableName() + "' does not exist");
    }/*  w  w  w  .j a  va  2  s.c  o m*/

    int sheetIndex = workbook.getSheetIndex(this.getTableName());
    workbook.removeSheetAt(sheetIndex);
    TDriverUtil.writeRecords(workbook, ((TExcelConnection) this.getConnection()).getPath());
}

From source file:qmul.align.AlignmentTester.java

License:Open Source License

/**
 * Print a summary sheet on the (gulp) excel spreadsheet
 * /*from  w w  w  .  j  a  v  a2s.  c  o m*/
 * @param wb
 * @param sheetName
 * @param speakerScores
 * @param originalSpks
 * @param speakerN
 */
private void printSummarySheet(Workbook wb, String sheetName, HashMap<String, ArrayList<Double>> speakerScores,
        HashMap<String, String> originalSpks, HashMap<String, ArrayList<Double>> speakerN,
        MetricsMap spkMetrics, MetricsMap totMetrics, boolean pairedCorpus) {

    CreationHelper creationHelper = wb.getCreationHelper();
    sheetName = (sheetName == null ? "Summary" : shorten(sheetName));
    System.out.println("Checking workbook " + wb + " for sheet " + sheetName);
    Sheet sheet = wb.getSheet(sheetName);
    if (sheet != null) {
        System.out.println("Exists, removing sheet " + sheetName);
        wb.removeSheetAt(wb.getSheetIndex(sheet));
    }
    sheet = wb.createSheet(sheetName);
    wb.setSheetOrder(sheetName, 0);
    int iRow = 0;
    // first general identifying stuff
    Row row = sheet.createRow(iRow++);
    row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(creationHelper.createRichTextString("Corpus"));
    row.createCell(1, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString(getCorpus().getId()));
    row = sheet.createRow(iRow++);
    row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(creationHelper.createRichTextString("Windower"));
    row.createCell(1, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString(getWin().toString()));
    row = sheet.createRow(iRow++);
    row.createCell(0, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString("Similarity Measure"));
    row.createCell(1, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString(getSim().toString()));
    // now header
    row = sheet.createRow(iRow++);
    row = sheet.createRow(iRow++);
    int iCol = 0;
    row.createCell(iCol++, Cell.CELL_TYPE_STRING).setCellValue(creationHelper.createRichTextString("Speaker"));
    row.createCell(iCol++, Cell.CELL_TYPE_STRING).setCellValue(creationHelper.createRichTextString("Genre"));
    row.createCell(iCol++, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString("Orig Speaker"));
    row.createCell(iCol++, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString("Orig Genre"));
    row.createCell(iCol++, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString("Speaker #units"));
    row.createCell(iCol++, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString("Dialogue #units"));
    row.createCell(iCol++, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString("Speaker #words"));
    row.createCell(iCol++, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString("Dialogue #words"));
    row.createCell(iCol++, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString("Speaker #tokens"));
    row.createCell(iCol++, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString("Dialogue #tokens"));
    row.createCell(iCol++, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString("Speaker avg offset"));
    row.createCell(iCol++, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString("Dialogue avg offset"));
    row.createCell(iCol++, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString("Speaker avg wordrate"));
    row.createCell(iCol++, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString("Dialogue avg wordrate"));
    iCol++;
    for (int i = 0; i < getWin().getLeftWindowSize(); i++) {
        row.createCell(i + iCol, Cell.CELL_TYPE_STRING)
                .setCellValue(creationHelper.createRichTextString("Mean i-" + (i + 1)));
    }
    // now means per speaker
    List<String> spks = new ArrayList<String>(speakerScores.keySet());
    Collections.sort(spks);
    List<Double> means = new ArrayList<Double>();
    List<Double> nums = new ArrayList<Double>();
    for (int i = 0; i < getWin().getLeftWindowSize(); i++) {
        means.add(0.0);
        nums.add(0.0);
    }
    int nAll = 0;
    int nMatch = 0;
    for (String spk : spks) {
        // System.out.println("org chk [" + originalSpks.get(spk) + "][" + spk + "]");
        boolean matching = false;
        if ((originalSpks.get(spk) != null) && originalSpks.get(spk).contains(":")) {
            int li = originalSpks.get(spk).lastIndexOf(":");
            String pre = originalSpks.get(spk).substring(0, li);
            String suf = originalSpks.get(spk).substring(li);
            matching = spk.startsWith(pre) && spk.endsWith(suf);
        }
        nAll++;
        if (!pairedCorpus || matching) {
            nMatch++;
            // System.out.println("match " + pre + " " + suf);
            row = sheet.createRow(iRow++);
            iCol = 0;
            String dId = spk.replaceFirst("(.*)_.*", "$1");
            row.createCell(iCol++, Cell.CELL_TYPE_STRING)
                    .setCellValue(creationHelper.createRichTextString(spk));
            row.createCell(iCol++, Cell.CELL_TYPE_STRING).setCellValue(
                    creationHelper.createRichTextString(corpus.getGenreMap().get(spk.split(":")[0])));
            row.createCell(iCol++, Cell.CELL_TYPE_STRING)
                    .setCellValue(creationHelper.createRichTextString(originalSpks.get(spk)));
            row.createCell(iCol++, Cell.CELL_TYPE_STRING).setCellValue(creationHelper
                    .createRichTextString(corpus.getGenreMap().get(originalSpks.get(spk).split(":")[0])));
            row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC).setCellValue(spkMetrics.getNumUnits(spk));
            row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC).setCellValue(totMetrics.getNumUnits(dId));
            row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC).setCellValue(spkMetrics.getNumWords(spk));
            row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC).setCellValue(totMetrics.getNumWords(dId));
            row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC).setCellValue(spkMetrics.getNumTokens(spk));
            row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC).setCellValue(totMetrics.getNumTokens(dId));
            if (Double.isNaN(spkMetrics.getTurnOffset(spk)) || spkMetrics.getNumTurnOffsets(spk) == 0) {
                iCol++;
            } else {
                row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC).setCellValue(
                        spkMetrics.getTurnOffset(spk) / (double) spkMetrics.getNumTurnOffsets(spk));
            }
            if (Double.isNaN(totMetrics.getTurnOffset(dId)) || totMetrics.getNumTurnOffsets(dId) == 0) {
                iCol++;
            } else {
                row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC).setCellValue(
                        totMetrics.getTurnOffset(dId) / (double) totMetrics.getNumTurnOffsets(dId));
            }
            if (Double.isNaN(spkMetrics.getWordRate(spk)) || spkMetrics.getNumWordRates(spk) == 0) {
                iCol++;
            } else {
                row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC)
                        .setCellValue(spkMetrics.getWordRate(spk) / (double) spkMetrics.getNumWordRates(spk));
            }
            if (Double.isNaN(totMetrics.getWordRate(dId)) || totMetrics.getNumWordRates(dId) == 0) {
                iCol++;
            } else {
                row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC)
                        .setCellValue(totMetrics.getWordRate(dId) / (double) totMetrics.getNumWordRates(dId));
            }
            iCol++;
            for (int i = 0; i < speakerScores.get(spk).size(); i++) {
                if (speakerN.get(spk).get(i) > 0.0) {
                    double mean = speakerScores.get(spk).get(i) / speakerN.get(spk).get(i);
                    row.createCell(i + iCol, Cell.CELL_TYPE_NUMERIC).setCellValue(mean);
                    means.set(i, means.get(i) + mean);
                    nums.set(i, nums.get(i) + 1);
                }
            }
        }
    }
    System.out.println("Matched " + nMatch + " of " + nAll);
    // and a final row for overall means
    row = sheet.createRow(iRow++);
    iCol = 14;
    row.createCell(iCol++, Cell.CELL_TYPE_STRING).setCellValue(creationHelper.createRichTextString("Overall"));
    for (int i = 0; i < getWin().getLeftWindowSize(); i++) {
        means.set(i, means.get(i) / nums.get(i));
        row.createCell(i + iCol, Cell.CELL_TYPE_NUMERIC).setCellValue(means.get(i));
    }
}

From source file:qmul.align.AlignmentTester.java

License:Open Source License

/**
 * Print a summary sheet on the (gulp) excel spreadsheet
 *//* ww w .  ja va 2s. c  o m*/
private void printSummaryCountSheet(Workbook wb, String sheetName,
        HashMap<String, HashMap<Object, Integer>> allCounts,
        HashMap<String, HashMap<Object, Integer>> commonCounts) {

    CreationHelper creationHelper = wb.getCreationHelper();
    sheetName = (sheetName == null ? "Summary" : shorten(sheetName));
    System.out.println("Checking workbook " + wb + " for sheet " + sheetName);
    Sheet sheet = wb.getSheet(sheetName);
    if (sheet != null) {
        System.out.println("Exists, removing sheet " + sheetName);
        wb.removeSheetAt(wb.getSheetIndex(sheet));
    }
    sheet = wb.createSheet(sheetName);
    wb.setSheetOrder(sheetName, 0);
    int iRow = 0;
    // first general identifying stuff
    Row row = sheet.createRow(iRow++);
    row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(creationHelper.createRichTextString("Corpus"));
    row.createCell(1, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString(getCorpus().getId()));
    row = sheet.createRow(iRow++);
    row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(creationHelper.createRichTextString("Windower"));
    row.createCell(1, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString(getWin().toString()));
    row = sheet.createRow(iRow++);
    row.createCell(0, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString("Similarity Measure"));
    row.createCell(1, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString(getSim().toString()));
    // now header
    row = sheet.createRow(iRow++);
    row = sheet.createRow(iRow++);
    int iCol = 0;
    row.createCell(iCol++, Cell.CELL_TYPE_STRING).setCellValue(creationHelper.createRichTextString("Type"));
    row.createCell(iCol++, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString("Overall count"));
    row.createCell(iCol++, Cell.CELL_TYPE_STRING)
            .setCellValue(creationHelper.createRichTextString("Common count"));
    for (String genre : allCounts.keySet()) {
        if (genre.isEmpty())
            continue;
        row.createCell(iCol++, Cell.CELL_TYPE_STRING)
                .setCellValue(creationHelper.createRichTextString(genre + " overall count"));
        row.createCell(iCol++, Cell.CELL_TYPE_STRING)
                .setCellValue(creationHelper.createRichTextString(genre + " common count"));
    }
    ArrayList<Object> keys = new ArrayList<Object>(allCounts.get("").keySet());
    Collections.sort(keys, new DescendingComparator<Object>(allCounts.get("")));
    for (Object key : keys) {
        row = sheet.createRow(iRow++);
        iCol = 0;
        row.createCell(iCol++, Cell.CELL_TYPE_STRING)
                .setCellValue(creationHelper.createRichTextString(key.toString()));
        Cell cell = row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC);
        if (allCounts.get("").get(key) != null) {
            cell.setCellValue(allCounts.get("").get(key));
        }
        cell = row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC);
        if (commonCounts.get("").get(key) != null) {
            cell.setCellValue(commonCounts.get("").get(key));
        }
        for (String genre : allCounts.keySet()) {
            if (genre.isEmpty())
                continue;
            cell = row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC);
            if (allCounts.get(genre).get(key) != null) {
                cell.setCellValue(allCounts.get(genre).get(key));
            }
            cell = row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC);
            if (commonCounts.get(genre).get(key) != null) {
                cell.setCellValue(commonCounts.get(genre).get(key));
            }
        }
    }
}

From source file:species.formatReader.SpreadsheetWriter.java

public static void writeHeadersInFormat(Workbook wb, JSONElement headerMarkers1, JSONArray orderedArray) {
    JSONObject headerMarkers = (JSONObject) headerMarkers1;
    //System.out.println("=CLASS===="+headerMarkers.getClass());
    Object o = headerMarkers.remove("undefined");
    Sheet sheet = wb.getSheet("headerMetadata");
    if (sheet != null) {
        int sindex = wb.getSheetIndex(sheet);
        wb.removeSheetAt(sindex);
    }//w  w  w .j av  a  2  s  .  c o  m
    sheet = wb.createSheet("headerMetadata");
    Map<String, Map<String, String>> reverseMarkers = new HashMap<String, Map<String, String>>();
    int rownum = 0;

    for (Object entry1 : headerMarkers.entrySet()) {
        Entry<String, Map<String, String>> entry = (Entry<String, Map<String, String>>) entry1;
        String headerName = entry.getKey();
        headerName = headerName.trim().toLowerCase();
        Map<String, String> headerValues = new HashMap<String, String>();
        for (Map.Entry<String, String> en : entry.getValue().entrySet()) {
            //System.out.println("=======HERE======" + en.getKey());
            if (en.getKey() != "undefined") {
                String val = (en.getValue() instanceof String ? en.getValue() : null);
                headerValues.put(en.getKey(), val);
            }
        }
        //System.out.println("==========NEW FUNC==============");
        //System.out.println(headerName);
        //System.out.println("---------" + entry.getValue() + entry.getValue().getClass());
        System.out.println("-------==============" + headerValues + headerValues.getClass());
        String dataColumns = "";
        if (headerValues.get("dataColumns") != null) {
            dataColumns = headerValues.get("dataColumns");
            dataColumns = dataColumns.trim();
        }
        String group = "";
        if (headerValues.get("group") != null) {
            //System.out.println(headerValues.get("group"));
            group = headerValues.get("group");
            group = group.trim();
        }

        //System.out.println("====ERROR FINIDING==" + headerValues.get("group"));
        String includeHeadings = "";
        if (headerValues.get("header") != null) {
            includeHeadings = headerValues.get("header");
            includeHeadings = includeHeadings.trim();
        }

        String append = "";
        if (headerValues.get("append") != null) {
            append = headerValues.get("append");
            append = append.trim();
        }

        String delimiter = "";
        if (headerValues.get("delimiter") != null) {
            delimiter = headerValues.get("delimiter");
            delimiter = delimiter.trim();
        }

        String images = "";
        if (headerValues.get("images") != null) {
            images = headerValues.get("images");
            images = images.trim();
        }

        String contributor = "";
        if (headerValues.get("contributor") != null) {
            contributor = headerValues.get("contributor");
            contributor = contributor.trim();
        }

        String attributions = "";
        if (headerValues.get("attributions") != null) {
            attributions = headerValues.get("attributions");
            attributions = attributions.trim();
        }

        String references = "";
        if (headerValues.get("references") != null) {
            references = headerValues.get("references");
            references = references.trim();
        }

        String license = "";
        if (headerValues.get("license") != null) {
            license = headerValues.get("license");
            license = license.trim();
        }

        String audience = "";
        if (headerValues.get("audience") != null) {
            audience = headerValues.get("audience");
            audience = audience.trim();
        }

        String language = "";
        if (headerValues.get("language") != null) {
            language = headerValues.get("language");
            language = language.trim();
        }

        //System.out.println("=======" + dataColumns);
        List<String> dcList = Arrays.asList(dataColumns.split(","));
        Iterator<String> dcIterator = dcList.iterator();
        while (dcIterator.hasNext()) {
            String nextVal = dcIterator.next();
            nextVal = nextVal.trim();
            //System.out.println("==THIS IS THE VALUE=== " + nextVal);
            if (!nextVal.equals("") && !nextVal.equals(null)) {
                if (reverseMarkers.containsKey(nextVal)) {
                    Map<String, String> m = reverseMarkers.get(nextVal);
                    String fieldNames = m.get("fieldNames");
                    if (fieldNames != "") {
                        fieldNames += FIELD_SEP + headerName;
                        m.put("fieldNames", fieldNames);
                    } else {
                        m.put("fieldNames", headerName);
                    }
                    String contentDelimiter = m.get("contentDelimiter");
                    if (contentDelimiter != "") {
                        contentDelimiter += COLUMN_SEP + headerName + KEYVALUE_SEP + delimiter;
                        m.put("contentDelimiter", contentDelimiter);
                    } else {
                        m.put("contentDelimiter", headerName + KEYVALUE_SEP + delimiter);
                    }
                    String contentFormat = m.get("contentFormat");
                    if (contentFormat != "") {
                        contentFormat += COLUMN_SEP + headerName + KEYVALUE_SEP + "Group=" + group + ";"
                                + "includeheadings=" + includeHeadings + ";" + "append=" + append + ";";
                        m.put("contentFormat", contentFormat);
                    } else {
                        m.put("contentFormat", headerName + KEYVALUE_SEP + "Group=" + group + ";"
                                + "includeheadings=" + includeHeadings + ";" + "append=" + append + ";");
                    }
                    String imagesCol = m.get("images");
                    if (imagesCol != "") {
                        imagesCol += COLUMN_SEP + headerName + KEYVALUE_SEP + images;
                        m.put("images", imagesCol);
                    } else {
                        m.put("images", headerName + KEYVALUE_SEP + images);
                    }
                    String contributorCol = m.get("contributor");
                    if (contributorCol != "") {
                        contributorCol += COLUMN_SEP + headerName + KEYVALUE_SEP + contributor;
                        m.put("contributor", contributorCol);
                    } else {
                        m.put("contributor", headerName + KEYVALUE_SEP + contributor);
                    }
                    String attributionsCol = m.get("attributions");
                    if (attributionsCol != "") {
                        attributionsCol += COLUMN_SEP + headerName + KEYVALUE_SEP + attributions;
                        m.put("attributions", attributionsCol);
                    } else {
                        m.put("attributions", headerName + KEYVALUE_SEP + attributions);
                    }
                    String referencesCol = m.get("references");
                    if (referencesCol != "") {
                        referencesCol += COLUMN_SEP + headerName + KEYVALUE_SEP + references;
                        m.put("references", referencesCol);
                    } else {
                        m.put("references", headerName + KEYVALUE_SEP + references);
                    }

                    String licenseCol = m.get("license");
                    if (licenseCol != "") {
                        licenseCol += COLUMN_SEP + headerName + KEYVALUE_SEP + license;
                        m.put("license", licenseCol);
                    } else {
                        m.put("license", headerName + KEYVALUE_SEP + license);
                    }
                    String audienceCol = m.get("audience");
                    if (audienceCol != "") {
                        audienceCol += COLUMN_SEP + headerName + KEYVALUE_SEP + audience;
                        m.put("audience", audienceCol);
                    } else {
                        m.put("audience", headerName + KEYVALUE_SEP + audience);
                    }

                    String languageCol = m.get("language");
                    if (languageCol != "") {
                        languageCol = language;
                        m.put("language", languageCol);
                    } else {
                        m.put("language", language);
                    }

                } else {
                    Map<String, String> m1 = new HashMap();
                    m1.put("fieldNames", headerName);
                    m1.put("contentDelimiter", headerName + KEYVALUE_SEP + delimiter);
                    m1.put("contentFormat", headerName + KEYVALUE_SEP + "Group=" + group + ";"
                            + "includeheadings=" + includeHeadings + ";" + "append=" + append + ";");
                    m1.put("images", headerName + KEYVALUE_SEP + images);
                    m1.put("contributor", headerName + KEYVALUE_SEP + contributor);
                    m1.put("attributions", headerName + KEYVALUE_SEP + attributions);
                    m1.put("references", headerName + KEYVALUE_SEP + references);
                    m1.put("license", headerName + KEYVALUE_SEP + license);
                    m1.put("audience", headerName + KEYVALUE_SEP + audience);
                    m1.put("language", language);

                    reverseMarkers.put(nextVal, m1);
                }
            }
        }

    }

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

    String[] headerRowValues = { "CONCEPT", "CATEGORY", "SUBCATEGORY", "FIELD NAME(S)", "CONTENT DELIMITER",
            "CONTENT FORMAT", "IMAGES", "CONTRIBUTOR", "ATTRIBUTIONS", "REFERENCES", "LICENSE", "AUDIENCE",
            "LANGUAGE" };
    int numOfColumns = headerRowValues.length;
    for (int cellNum = 0; cellNum < numOfColumns; cellNum++) {
        Cell cell = row.createCell(cellNum);
        cell.setCellValue(headerRowValues[cellNum]);
    }
    //System.out.println("====REVERSE MARKERS=====" + reverseMarkers);
    for (Map.Entry<String, Map<String, String>> entry : reverseMarkers.entrySet()) {
        String[] arr = new String[numOfColumns];
        String headerName = entry.getKey();
        List<String> pipedNameList = Arrays.asList(headerName.split("\\|"));
        Iterator<String> pnlIterator = pipedNameList.iterator();
        for (int i = 0; i < 3; i++) {
            if (pnlIterator.hasNext()) {
                arr[i] = pnlIterator.next();
            } else {
                arr[i] = "";
            }
        }
        Map<String, String> m2 = new HashMap(entry.getValue());
        arr[3] = m2.get("fieldNames");
        arr[4] = m2.get("contentDelimiter");
        arr[5] = m2.get("contentFormat");
        arr[6] = m2.get("images");
        arr[7] = m2.get("contributor");
        arr[8] = m2.get("attributions");
        arr[9] = m2.get("references");
        arr[10] = m2.get("license");
        arr[11] = m2.get("audience");
        arr[12] = m2.get("language");

        //Rewriting fieldnames according to columns in sheet 1

        String[] tokens = arr[3].split(FIELD_SEP);
        String finalKeysOrdered = "";
        int orderedArraySize = orderedArray.length();
        for (int k = 0; k < orderedArraySize; k++) {
            String kkk = orderedArray.getString(k);
            for (String token : tokens) {
                if (token.equals(kkk)) {
                    if (finalKeysOrdered == "") {
                        finalKeysOrdered = token;
                    } else {
                        finalKeysOrdered = finalKeysOrdered + FIELD_SEP + token;
                    }
                }
            }
        }
        arr[3] = finalKeysOrdered;
        /////////

        row = sheet.createRow(rownum++);
        for (int cellNum = 0; cellNum < numOfColumns; cellNum++) {
            Cell cell = row.createCell(cellNum);
            cell.setCellValue(arr[cellNum]);
        }

    }

}

From source file:species.formatReader.SpreadsheetWriter.java

public static void writeHeaderMarkersInSheet(Workbook wb, Map<String, Map<String, String>> headerMarkers) {
    Sheet sheet = wb.getSheet("headerMetadata");
    if (sheet != null) {
        int sindex = wb.getSheetIndex(sheet);
        wb.removeSheetAt(sindex);
    }//from  w w w  . j  a va 2 s  . c om
    sheet = wb.createSheet("headerMetadata");
    int rownum = 0;
    String headerName;
    //int headerMarkersSize = 0;
    /*
       for(int i = 0; i<headerMarkersSize; i++){
       JSONObject marker = headerMarkers.get(i);
            
       }*/

    Row row = sheet.createRow(rownum++);
    for (int cellNum = 0; cellNum <= 2; cellNum++) {
        Cell cell = row.createCell(cellNum);
        if (cellNum == 0) {
            //System.out.println("===HEADER NAME IN MARKER SHEET==== " );

            cell.setCellValue("column_name");
        } else if (cellNum == 1) {
            //System.out.println("===TAGS IN MARKER SHEET==== " );
            cell.setCellValue("type");
        } else if (cellNum == 2) {
            //System.out.println("===VALUES IN MARKER SHEET==== " );
            cell.setCellValue("value");
        }
    }
    for (Map.Entry<String, Map<String, String>> entry : headerMarkers.entrySet()) {
        headerName = entry.getKey();
        //System.out.println("===HEADER NAME IN MARKER SHEET==== " + headerName );
        for (Map.Entry<String, String> en : entry.getValue().entrySet()) {
            row = sheet.createRow(rownum++);
            for (int cellNum = 0; cellNum <= 2; cellNum++) {
                Cell cell = row.createCell(cellNum);
                if (cellNum == 0) {
                    //System.out.println("===HEADER NAME IN MARKER SHEET==== " + headerName );

                    cell.setCellValue(headerName);
                } else if (cellNum == 1) {
                    //System.out.println("===TAGS IN MARKER SHEET==== " + en.getKey());
                    cell.setCellValue(en.getKey());
                } else if (cellNum == 2) {
                    //System.out.println("===VALUES IN MARKER SHEET==== " + en.getValue());
                    cell.setCellValue(en.getValue());
                }
            }

        }
    }

    return;
}

From source file:summary.AbstractSummary.java

License:LGPL

/**
 * If the Sheet doesn't already exist in the Workbook, create it.  Otherwise this method
 * will delete the existing one and create a new one
 * @param wb an Excel workbook/*from  w  ww  .j a v a  2 s. c o m*/
 * @return a new, blank Sheet in the given Workbook
 */
public Sheet getSheet(Workbook wb) {
    Sheet sheet;

    int sheetIdx = wb.getSheetIndex(getSheetTitle());
    if (sheetIdx >= 0) {
        wb.removeSheetAt(sheetIdx);
    }
    sheet = wb.createSheet(getSheetTitle());

    return sheet;
}