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.bbreak.excella.reports.tag.RowRepeatParamParserTest.java

License:Open Source License

/**
 * {@link org.bbreak.excella.reports.tag.RowRepeatParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} ????
 */// w ww.  j  a va  2s  . co  m
@Test
public void testParseSheetCellObject() {

    Workbook workbook = getWorkbook();
    Sheet sheet1 = workbook.getSheetAt(0);

    // -----------------------
    // []??
    // -----------------------

    ReportBook reportBook = new ReportBook("", "test", new ConvertConfiguration[] {});
    //        reportBook.setCopyTemplate( true);
    ReportSheet reportSheet1 = new ReportSheet("sheet1", "Sheet1");
    reportBook.addReportSheet(reportSheet1);
    ReportSheet reportSheet2 = new ReportSheet("sheet1", "Sheet2");
    reportBook.addReportSheet(reportSheet2);
    ReportSheet reportSheet3 = new ReportSheet("sheet1", "Sheet3");
    reportBook.addReportSheet(reportSheet3);

    ReportSheet[] reportSheets = new ReportSheet[] { reportSheet1, reportSheet2, reportSheet3 };

    for (ReportSheet reportSheet : reportSheets) {
        ParamInfo info = reportSheet.getParamInfo();
        info.addParam("$R[]", "A", new Object[] { "AA1", "AA1", "AA2", "AA2", "AA3" });
        info.addParam("$R[]", "B", new Object[] { "BB1", "BB1", "BB2" });
        info.addParam("$R[]", "C", new Object[] { "CC1", "CC2", "CC3", "CC4", "CC5" });
        info.addParam("$", "D", "DDD");
    }

    RowRepeatParamParser parser = new RowRepeatParamParser();
    ReportsParserInfo reportsParserInfo = new ReportsParserInfo();
    reportsParserInfo.setReportParsers(
            new ArrayList<ReportsTagParser<?>>(ReportCreateHelper.createDefaultParsers().values()));
    reportsParserInfo.setReportBook(reportBook);
    reportsParserInfo.setParamInfo(reportSheets[0].getParamInfo());

    // ??.
    List<ParsedReportInfo> results = null;
    try {
        results = parseSheet(parser, sheet1, reportsParserInfo);
    } catch (ParseException e) {
        fail(e.toString());
    }

    CellObject[] expectBeCells = new CellObject[] { new CellObject(0, 0), new CellObject(2, 1) };
    CellObject[] expectAfCells = new CellObject[] { new CellObject(4, 0), new CellObject(4, 1) };
    checkResult(expectBeCells, expectAfCells, results);

    // ??
    if (version.equals("2007")) {
        int index = workbook.getSheetIndex(PoiUtil.TMP_SHEET_NAME);
        if (index > 0) {
            workbook.removeSheetAt(index);
        }
    }

    checkSheet("Sheet1", sheet1, true);

    // -----------------------
    // []
    // 
    // 
    // ??
    // ?
    // 
    // -----------------------
    workbook = getWorkbook();
    Sheet sheet2 = workbook.getSheetAt(1);
    // ??
    results = null;
    try {
        results = parseSheet(parser, sheet2, reportsParserInfo);
    } catch (ParseException e) {
        fail(e.toString());
    }

    expectBeCells = new CellObject[] { new CellObject(0, 0), new CellObject(2, 1), new CellObject(4, 2) };
    expectAfCells = new CellObject[] { new CellObject(4, 0), new CellObject(4, 1), new CellObject(5, 2) };
    checkResult(expectBeCells, expectAfCells, results);

    // ??
    if (version.equals("2007")) {
        int index = workbook.getSheetIndex(PoiUtil.TMP_SHEET_NAME);
        if (index > 0) {
            workbook.removeSheetAt(index);
        }
    }
    checkSheet("Sheet2", sheet2, true);

    // -----------------------
    // []
    // 
    // -----------------------
    workbook = getWorkbook();
    Sheet sheet3 = workbook.getSheetAt(2);
    // ??
    results = null;
    try {
        results = parseSheet(parser, sheet3, reportsParserInfo);
    } catch (ParseException e) {
        fail(e.toString());
    }

    expectBeCells = new CellObject[] { new CellObject(0, 0), new CellObject(0, 1), new CellObject(0, 2),
            new CellObject(17, 1), new CellObject(18, 0) };
    expectAfCells = new CellObject[] { new CellObject(2, 0), new CellObject(1, 1), new CellObject(4, 2),
            new CellObject(19, 1), new CellObject(20, 0) };
    checkResult(expectBeCells, expectAfCells, results);

    // ??
    if (version.equals("2007")) {
        int index = workbook.getSheetIndex(PoiUtil.TMP_SHEET_NAME);
        if (index > 0) {
            workbook.removeSheetAt(index);
        }
    }
    checkSheet("Sheet3", sheet3, true);

    // -----------------------
    // []?
    // ????????
    // -----------------------
    workbook = getWorkbook();
    Sheet sheet4 = workbook.getSheetAt(3);
    // ??
    results = null;
    try {
        results = parseSheet(parser, sheet4, reportsParserInfo);
    } catch (ParseException e) {
        fail(e.toString());
    }

    expectBeCells = new CellObject[] { new CellObject(0, 0), new CellObject(1, 0), new CellObject(2, 0) };
    expectAfCells = new CellObject[] { new CellObject(0, 0), new CellObject(1, 0), new CellObject(2, 0) };
    checkResult(expectBeCells, expectAfCells, results);

    // ??
    if (version.equals("2007")) {
        int index = workbook.getSheetIndex(PoiUtil.TMP_SHEET_NAME);
        if (index > 0) {
            workbook.removeSheetAt(index);
        }
    }
    checkSheet("Sheet4", sheet4, true);

    Sheet sheet5 = workbook.getSheetAt(4);
    // ??
    try {
        parseSheet(parser, sheet5, reportsParserInfo);
        fail("?????????????????");
    } catch (ParseException e) {
    }

    // -----------------------
    // []?
    // ?????
    // -----------------------
    workbook = getWorkbook();
    Sheet sheet6 = workbook.getSheetAt(5);
    // ??
    try {
        parseSheet(parser, sheet6, reportsParserInfo);
        fail();
    } catch (ParseException e) {
        assertTrue(e instanceof ParseException);
    }

    // ------------------------------------------------------------
    // []
    // ??????????
    //   PoiUtil.getMergedAddress??
    //   ?????????
    // ------------------------------------------------------------
    workbook = getWorkbook();
    Sheet sheet7 = workbook.getSheetAt(6);
    // ??
    try {
        results = parseSheet(parser, sheet7, reportsParserInfo);
        fail("???");
    } catch (ParseException e) {
        // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress)
        // ?throw????????
        assertTrue(e.getCause() instanceof IllegalArgumentException);
        assertTrue(e.getMessage().contains("There are crossing merged regions in the range."));
    }

    // ------------------------------------------------------------
    // []
    // ?????????
    // ------------------------------------------------------------
    workbook = getWorkbook();
    Sheet sheet8 = workbook.getSheetAt(7);
    // ??
    results = null;
    try {
        results = parseSheet(parser, sheet8, reportsParserInfo);
    } catch (ParseException e) {
        e.printStackTrace();
        fail(e.toString());
    }

    expectBeCells = new CellObject[] { new CellObject(2, 0), new CellObject(2, 1), new CellObject(2, 2),
            new CellObject(2, 3), new CellObject(2, 4), new CellObject(14, 0) };
    expectAfCells = new CellObject[] { new CellObject(10, 0), new CellObject(10, 1), new CellObject(10, 2),
            new CellObject(4, 3), new CellObject(6, 4), new CellObject(22, 0) };
    checkResult(expectBeCells, expectAfCells, results);

    // ??
    if (version.equals("2007")) {
        int index = workbook.getSheetIndex(PoiUtil.TMP_SHEET_NAME);
        if (index > 0) {
            workbook.removeSheetAt(index);
        }
    }
    checkSheet("Sheet8", sheet8, true);

    // ------------------------------------------------------------
    // []
    // ?????????
    // ------------------------------------------------------------
    workbook = getWorkbook();
    Sheet sheet9 = workbook.getSheetAt(8);
    // ??
    results = null;
    try {
        results = parseSheet(parser, sheet9, reportsParserInfo);
    } catch (ParseException e) {
        e.printStackTrace();
        fail(e.toString());
    }

    expectBeCells = new CellObject[] { new CellObject(3, 0), new CellObject(3, 1), new CellObject(3, 2),
            new CellObject(3, 3), new CellObject(3, 4) };
    expectAfCells = new CellObject[] { new CellObject(15, 0), new CellObject(15, 1), new CellObject(15, 2),
            new CellObject(6, 3), new CellObject(9, 4) };
    checkResult(expectBeCells, expectAfCells, results);

    // ??
    if (version.equals("2007")) {
        int index = workbook.getSheetIndex(PoiUtil.TMP_SHEET_NAME);
        if (index > 0) {
            workbook.removeSheetAt(index);
        }
    }

    checkSheet("Sheet9", sheet9, true);

    // ------------------------------------------------------------
    // []
    // ??????????
    //   PoiUtil.getMergedAddress??
    //   ?????????
    // ------------------------------------------------------------
    workbook = getWorkbook();
    Sheet sheet10 = workbook.getSheetAt(9);
    // ??
    results = null;
    try {
        results = parseSheet(parser, sheet10, reportsParserInfo);
        fail("???");
    } catch (ParseException e) {
        // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress)
        // ?throw????????
        assertTrue(e.getCause() instanceof IllegalArgumentException);
        assertTrue(e.getMessage().contains("There are crossing merged regions in the range."));
    }

    // ------------------------------------------------------------
    // []
    // ?????
    // ------------------------------------------------------------
    workbook = getWorkbook();
    Sheet sheet17 = workbook.getSheetAt(16);
    results = null;
    try {
        results = parseSheet(parser, sheet17, reportsParserInfo);
    } catch (ParseException e) {
        e.printStackTrace();
        fail(e.toString());
    }
    checkSheet("Sheet17", sheet17, true);

    // ------------------------------------------------------------
    // []
    // 
    // ------------------------------------------------------------
    workbook = getWorkbook();
    Sheet sheet18 = workbook.getSheetAt(17);
    // ??
    results = null;
    try {
        results = parseSheet(parser, sheet18, reportsParserInfo);
    } catch (ParseException e) {
        e.printStackTrace();
        fail(e.toString());
    }

    // ?=?=-1,=-1(?????),=-1(???)
    expectBeCells = new CellObject[] { new CellObject(1, 1), new CellObject(2, 2), new CellObject(2, 4),
            new CellObject(4, 3) };
    expectAfCells = new CellObject[] { new CellObject(5, 1), new CellObject(5, 2), new CellObject(5, 4),
            new CellObject(10, 3) };
    checkResult(expectBeCells, expectAfCells, results);

    // ??
    if (version.equals("2007")) {
        int index = workbook.getSheetIndex(PoiUtil.TMP_SHEET_NAME);
        if (index > 0) {
            workbook.removeSheetAt(index);
        }
    }

    checkSheet("Sheet18", sheet18, true);
}

From source file:org.bbreak.excella.reports.tag.SumParamParserTest.java

License:Open Source License

/**
 * {@link org.bbreak.excella.reports.tag.SumParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} ????
 *//* w  w w .j a  v  a  2  s  .c  o m*/
@Test
public void testParseSheetCellObject() {

    // -----------------------
    // []?
    // -----------------------

    Workbook workbook = getWorkbook();

    Sheet sheet1 = workbook.getSheetAt(0);

    ReportBook reportBook = new ReportBook("", "test", new ConvertConfiguration[] {});
    //        reportBook.setCopyTemplate( true);
    ReportSheet reportSheet = new ReportSheet("Sheet1", "Sheet1");
    reportBook.addReportSheet(reportSheet);

    // 
    ParamInfo info = reportSheet.getParamInfo();

    ParamInfo info$1 = new ParamInfo();
    info$1.addParam(SingleParamParser.DEFAULT_TAG, "p1", (byte) 1);
    info$1.addParam(SingleParamParser.DEFAULT_TAG, "p2", (short) 30);

    ParamInfo info$2 = new ParamInfo();
    info$2.addParam(SingleParamParser.DEFAULT_TAG, "p1", 100);
    info$2.addParam(SingleParamParser.DEFAULT_TAG, "p2", 300L);

    ParamInfo info$3 = new ParamInfo();
    info$3.addParam(SingleParamParser.DEFAULT_TAG, "p1", 3.5f);
    info$3.addParam(SingleParamParser.DEFAULT_TAG, "p2", 0.889);

    ParamInfo info$4 = new ParamInfo();
    info$4.addParam(SingleParamParser.DEFAULT_TAG, "p1", new BigInteger("50000"));
    info$4.addParam(SingleParamParser.DEFAULT_TAG, "p2", new BigDecimal("6.66"));

    info.addParam(BlockRowRepeatParamParser.DEFAULT_TAG, "br1",
            new ParamInfo[] { info$1, info$2, info$3, info$4 });

    SumParamParser parser = new SumParamParser();
    ReportsParserInfo reportsParserInfo = new ReportsParserInfo();
    reportsParserInfo.setReportParsers(
            new ArrayList<ReportsTagParser<?>>(ReportCreateHelper.createDefaultParsers().values()));
    reportsParserInfo.setReportBook(reportBook);
    reportsParserInfo.setParamInfo(reportSheet.getParamInfo());

    // ??
    List<ParsedReportInfo> results = null;
    try {
        results = parseSheet(parser, sheet1, reportsParserInfo);
    } catch (ParseException e) {
        fail(e.toString());
    }

    // ????
    checkResult(new CellObject[] { new CellObject(4, 1), new CellObject(7, 1) }, results);

    // ??
    if (version.equals("2007")) {
        int index = workbook.getSheetIndex(PoiUtil.TMP_SHEET_NAME);
        if (index > 0) {
            workbook.removeSheetAt(index);
        }
    }

    checkSheet("Sheet1", sheet1, true);

}

From source file:org.datanucleus.store.excel.ExcelSchemaHandler.java

License:Open Source License

@Override
public void deleteSchemaForClasses(Set<String> classNames, Properties props, Object connection) {
    Workbook wb = (Workbook) connection;
    ManagedConnection mconn = null;/*from  w w w.j  av  a 2 s  .  co m*/
    try {
        if (wb == null) {
            mconn = storeMgr.getConnection(-1);
            wb = (Workbook) mconn.getConnection();
        }

        Iterator<String> classIter = classNames.iterator();
        ClassLoaderResolver clr = storeMgr.getNucleusContext().getClassLoaderResolver(null);
        while (classIter.hasNext()) {
            String className = classIter.next();
            AbstractClassMetaData cmd = storeMgr.getMetaDataManager().getMetaDataForClass(className, clr);
            if (cmd != null) {
                StoreData storeData = storeMgr.getStoreDataForClass(cmd.getFullClassName());
                Table table = null;
                if (storeData != null) {
                    table = storeData.getTable();
                } else {
                    table = new CompleteClassTable(storeMgr, cmd, null);
                }

                String sheetName = table.getName();
                Sheet sheet = wb.getSheet(sheetName);
                if (sheet != null) {
                    wb.removeSheetAt(wb.getSheetIndex(sheetName));
                    if (NucleusLogger.DATASTORE_PERSIST.isDebugEnabled()) {
                        NucleusLogger.DATASTORE_PERSIST.debug(
                                Localiser.msg("Excel.SchemaDelete.Class", cmd.getFullClassName(), sheetName));
                    }
                }
            }
        }
    } finally {
        if (mconn != null) {
            mconn.release();
        }
    }
}

From source file:org.formulacompiler.spreadsheet.internal.excel.xls.saver.ExcelXLSSaver.java

License:Open Source License

private void removeDataFrom(final Workbook _xwb) {
    for (int i = _xwb.getNumberOfSheets() - 1; i >= 0; i--) {
        _xwb.removeSheetAt(i);
    }/* w ww.ja  v a 2s.c  o  m*/
    for (int i = 0; i < _xwb.getNumberOfNames(); i++) {
        _xwb.removeName(i);
    }
}

From source file:org.mifos.dmt.excel.CreateExcel.java

License:Open Source License

public Workbook generate(String baseTemplate, DMTMigrationParams params)
        throws InvalidFormatException, IOException, DMTException {
    InputStream inp = new FileInputStream(baseTemplate);

    Workbook wb = WorkbookFactory.create(inp);
    ArrayList<String> sheetSpec = readSheetSpec(params);
    for (int i = wb.getNumberOfSheets(); i > 0; i--) {
        String sheetName = wb.getSheetName(i - 1);
        if (sheetSpec.contains(sheetName)) {
            wb.removeSheetAt(i - 1);
        } else {/*from   ww  w . j  av a  2 s  .  c  o m*/
            logger.info("Adding sheet : " + sheetName);
        }

    }
    Sheet configSheet = wb.getSheetAt(0);
    editConfigSheet(configSheet);

    return wb;
}

From source file:org.riflemansd.businessprofit.excel.ExcelExampleFont.java

License:Open Source License

public static void main(String[] args) {
    // create a new file
    FileOutputStream out = null;/*w w  w  . ja  v a2 s .  c om*/
    try {
        out = new FileOutputStream("workbook.xls");
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ExcelExampleFont.class.getName()).log(Level.SEVERE, null, ex);
    }
    // create a new workbook
    Workbook wb = new HSSFWorkbook();
    // create a new sheet
    Sheet s = wb.createSheet();
    // declare a row object reference
    Row r = null;
    // declare a cell object reference
    Cell c = null;
    // create 3 cell styles
    CellStyle cs = wb.createCellStyle();
    CellStyle cs2 = wb.createCellStyle();
    CellStyle cs3 = wb.createCellStyle();
    DataFormat df = wb.createDataFormat();
    // create 2 fonts objects
    Font f = wb.createFont();
    Font f2 = wb.createFont();

    //set font 1 to 12 point type
    f.setFontHeightInPoints((short) 12);
    //make it blue
    f.setColor((short) 0xc);
    // make it bold
    //arial is the default font
    f.setBoldweight(Font.BOLDWEIGHT_BOLD);

    //set font 2 to 10 point type
    f2.setFontHeightInPoints((short) 10);
    //make it red
    f2.setColor((short) Font.COLOR_RED);
    //make it bold
    f2.setBoldweight(Font.BOLDWEIGHT_BOLD);

    f2.setStrikeout(true);

    //set cell stlye
    cs.setFont(f);
    //set the cell format 
    cs.setDataFormat(df.getFormat("#,##0.0"));

    //set a thin border
    cs2.setBorderBottom(cs2.BORDER_THIN);
    //fill w fg fill color
    cs2.setFillPattern((short) CellStyle.SOLID_FOREGROUND);
    //set the cell format to text see DataFormat for a full list
    cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));

    // set the font
    cs2.setFont(f2);

    // set the sheet name in Unicode
    wb.setSheetName(0, "\u0422\u0435\u0441\u0442\u043E\u0432\u0430\u044F "
            + "\u0421\u0442\u0440\u0430\u043D\u0438\u0447\u043A\u0430");
    // in case of plain ascii
    // wb.setSheetName(0, "HSSF Test");
    // create a sheet with 30 rows (0-29)
    int rownum;
    for (rownum = (short) 0; rownum < 30; rownum++) {
        // create a row
        r = s.createRow(rownum);
        // on every other row
        if ((rownum % 2) == 0) {
            // make the row height bigger  (in twips - 1/20 of a point)
            r.setHeight((short) 0x249);
        }

        //r.setRowNum(( short ) rownum);
        // create 10 cells (0-9) (the += 2 becomes apparent later
        for (short cellnum = (short) 0; cellnum < 10; cellnum += 2) {
            // create a numeric cell
            c = r.createCell(cellnum);
            // do some goofy math to demonstrate decimals
            c.setCellValue(rownum * 10000 + cellnum + (((double) rownum / 1000) + ((double) cellnum / 10000)));

            String cellValue;

            // create a string cell (see why += 2 in the
            c = r.createCell((short) (cellnum + 1));

            // on every other row
            if ((rownum % 2) == 0) {
                // set this cell to the first cell style we defined
                c.setCellStyle(cs);
                // set the cell's string value to "Test"
                c.setCellValue("Test");
            } else {
                c.setCellStyle(cs2);
                // set the cell's string value to "\u0422\u0435\u0441\u0442"
                c.setCellValue("\u0422\u0435\u0441\u0442");
            }

            // make this column a bit wider
            s.setColumnWidth((short) (cellnum + 1), (short) ((50 * 8) / ((double) 1 / 20)));
        }
    }

    //draw a thick black border on the row at the bottom using BLANKS
    // advance 2 rows
    rownum++;
    rownum++;

    r = s.createRow(rownum);

    // define the third style to be the default
    // except with a thick black border at the bottom
    cs3.setBorderBottom(cs3.BORDER_THICK);

    //create 50 cells
    for (short cellnum = (short) 0; cellnum < 50; cellnum++) {
        //create a blank type cell (no value)
        c = r.createCell(cellnum);
        // set it to the thick black border style
        c.setCellStyle(cs3);
    }

    //end draw thick black border

    // demonstrate adding/naming and deleting a sheet
    // create a sheet, set its title then delete it
    s = wb.createSheet();
    wb.setSheetName(1, "DeletedSheet");
    wb.removeSheetAt(1);
    //end deleted sheet
    try {
        // write the workbook to the output stream
        // close our file (don't blow out our file handles
        wb.write(out);
    } catch (IOException ex) {
        Logger.getLogger(ExcelExampleFont.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        out.close();
    } catch (IOException ex) {
        Logger.getLogger(ExcelExampleFont.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.spdx.compare.AbstractFileCompareSheet.java

License:Apache License

/**
 * @param wb//  www. j  a  va 2s  .  com
 * @param sheetName
 */
public static void create(Workbook wb, String sheetName, int columnWidth) {
    int sheetNum = wb.getSheetIndex(sheetName);
    if (sheetNum >= 0) {
        wb.removeSheetAt(sheetNum);
    }
    Sheet sheet = wb.createSheet(sheetName);
    Row row = sheet.createRow(0);
    CellStyle headerStyle = AbstractSheet.createHeaderStyle(wb);
    CellStyle defaultStyle = AbstractSheet.createLeftWrapStyle(wb);
    sheet.setColumnWidth(FILENAME_COL, FILENAME_COL_WIDTH * 256);
    sheet.setDefaultColumnStyle(FILENAME_COL, defaultStyle);
    Cell fileNameHeadercell = row.createCell(FILENAME_COL);
    fileNameHeadercell.setCellStyle(headerStyle);
    fileNameHeadercell.setCellValue(FILENAME_TITLE);
    sheet.setColumnWidth(DIFF_COL, DIFF_COL_WIDTH * 256);
    sheet.setDefaultColumnStyle(DIFF_COL, defaultStyle);
    Cell diffHeaderCell = row.createCell(DIFF_COL);
    diffHeaderCell.setCellStyle(headerStyle);
    diffHeaderCell.setCellValue(DIFF_TITLE);

    for (int i = FIRST_DOCUMENT_COL; i < MultiDocumentSpreadsheet.MAX_DOCUMENTS + FIRST_DOCUMENT_COL; i++) {
        sheet.setColumnWidth(i, columnWidth * 256);
        sheet.setDefaultColumnStyle(i, defaultStyle);
        Cell cell = row.createCell(i);
        cell.setCellStyle(headerStyle);
    }
}

From source file:org.spdx.compare.CreatorSheet.java

License:Apache License

/**
 * @param wb//from w w  w.j a  v  a2 s .c om
 * @param sheetName
 */
public static void create(Workbook wb, String sheetName) {
    int sheetNum = wb.getSheetIndex(sheetName);
    if (sheetNum >= 0) {
        wb.removeSheetAt(sheetNum);
    }
    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 < MultiDocumentSpreadsheet.MAX_DOCUMENTS; i++) {
        sheet.setColumnWidth(i, COL_WIDTH * 256);
        sheet.setDefaultColumnStyle(i, defaultStyle);
        Cell cell = row.createCell(i);
        cell.setCellStyle(headerStyle);
    }
}

From source file:org.spdx.compare.DocumentAnnotationSheet.java

License:Apache License

/**
 * @param wb/* w w  w . j av a2 s .  co  m*/
 * @param sheetName
 */
public static void create(Workbook wb, String sheetName) {
    int sheetNum = wb.getSheetIndex(sheetName);
    if (sheetNum >= 0) {
        wb.removeSheetAt(sheetNum);
    }
    Sheet sheet = wb.createSheet(sheetName);
    CellStyle headerStyle = AbstractSheet.createHeaderStyle(wb);
    CellStyle defaultStyle = AbstractSheet.createLeftWrapStyle(wb);
    Row row = sheet.createRow(0);
    sheet.setColumnWidth(ANNOTATOR_COL, ANNOTATOR_COL_WIDTH * 256);
    sheet.setDefaultColumnStyle(ANNOTATOR_COL, defaultStyle);
    Cell annotatorHeaderCell = row.createCell(ANNOTATOR_COL);
    annotatorHeaderCell.setCellStyle(headerStyle);
    annotatorHeaderCell.setCellValue(ANNOTATOR_COL_TEXT_TITLE);

    sheet.setColumnWidth(TYPE_COL, TYPE_COL_WIDTH * 256);
    sheet.setDefaultColumnStyle(TYPE_COL, defaultStyle);
    Cell typeHeaderCell = row.createCell(TYPE_COL);
    typeHeaderCell.setCellStyle(headerStyle);
    typeHeaderCell.setCellValue(TYPE_COL_TEXT_TITLE);

    sheet.setColumnWidth(COMMENT_COL, COMMENT_COL_WIDTH * 256);
    sheet.setDefaultColumnStyle(COMMENT_COL, defaultStyle);
    Cell commentHeaderCell = row.createCell(COMMENT_COL);
    commentHeaderCell.setCellStyle(headerStyle);
    commentHeaderCell.setCellValue(COMMENT_COL_TEXT_TITLE);

    for (int i = FIRST_DATE_COL; i < MultiDocumentSpreadsheet.MAX_DOCUMENTS; i++) {
        sheet.setColumnWidth(i, DATE_COL_WIDTH * 256);
        sheet.setDefaultColumnStyle(i, defaultStyle);
        Cell cell = row.createCell(i);
        cell.setCellStyle(headerStyle);
    }
}

From source file:org.spdx.compare.DocumentRelationshipSheet.java

License:Apache License

/**
 * @param wb//w  w  w .jav  a  2s. c om
 * @param sheetName
 */
public static void create(Workbook wb, String sheetName) {
    int sheetNum = wb.getSheetIndex(sheetName);
    if (sheetNum >= 0) {
        wb.removeSheetAt(sheetNum);
    }
    Sheet sheet = wb.createSheet(sheetName);
    CellStyle headerStyle = AbstractSheet.createHeaderStyle(wb);
    CellStyle defaultStyle = AbstractSheet.createLeftWrapStyle(wb);
    Row row = sheet.createRow(0);

    sheet.setColumnWidth(TYPE_COL, TYPE_COL_WIDTH * 256);
    sheet.setDefaultColumnStyle(TYPE_COL, defaultStyle);
    Cell typeHeaderCell = row.createCell(TYPE_COL);
    typeHeaderCell.setCellStyle(headerStyle);
    typeHeaderCell.setCellValue(TYPE_COL_TEXT_TITLE);

    for (int i = FIRST_RELATIONSHIP_COL; i < MultiDocumentSpreadsheet.MAX_DOCUMENTS; i++) {
        sheet.setColumnWidth(i, FIRST_RELATIONSHIP_COL_WIDTH * 256);
        sheet.setDefaultColumnStyle(i, defaultStyle);
        Cell cell = row.createCell(i);
        cell.setCellStyle(headerStyle);
    }
}