Java Code Examples for org.apache.poi.ss.usermodel.Workbook#getSheetIndex()
The following examples show how to use
org.apache.poi.ss.usermodel.Workbook#getSheetIndex() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PerFileSheetV2d0.java From tools with Apache License 2.0 | 6 votes |
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 centerStyle = AbstractSheet.createCenterStyle(wb); CellStyle wrapStyle = AbstractSheet.createLeftWrapStyle(wb); 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]); } }
Example 2
Source File: ReviewerSheet.java From tools with Apache License 2.0 | 6 votes |
/** * @param wb * @param reviewerSheetName */ 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); } }
Example 3
Source File: ExtractedLicenseSheet.java From tools with Apache License 2.0 | 6 votes |
/** * @param wb * @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(EXTRACTED_TEXT_COL, EXTRACTED_TEXT_WIDTH*256); sheet.setDefaultColumnStyle(EXTRACTED_TEXT_COL, defaultStyle); Cell extractedHeaderCell = row.createCell(EXTRACTED_TEXT_COL); extractedHeaderCell.setCellStyle(headerStyle); extractedHeaderCell.setCellValue(EXTRACTED_TEXT_TITLE); for (int i = FIRST_LIC_ID_COL; i < MultiDocumentSpreadsheet.MAX_DOCUMENTS; i++) { sheet.setColumnWidth(i, LIC_ID_COL_WIDTH*256); sheet.setDefaultColumnStyle(i, defaultStyle); Cell cell = row.createCell(i); cell.setCellStyle(headerStyle); } }
Example 4
Source File: PackageInfoSheetV9d1.java From tools with Apache License 2.0 | 6 votes |
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 < 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]); } }
Example 5
Source File: DocumentSheet.java From tools with Apache License 2.0 | 6 votes |
/** * @param wb * @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 < 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]); } }
Example 6
Source File: VerificationSheet.java From tools with Apache License 2.0 | 6 votes |
/** * @param wb * @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); } }
Example 7
Source File: CreatorSheet.java From tools with Apache License 2.0 | 6 votes |
/** * @param wb * @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); } }
Example 8
Source File: PackageInfoSheetV1d2.java From tools with Apache License 2.0 | 6 votes |
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 < 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]); } }
Example 9
Source File: PerFileSheetV09d3.java From tools with Apache License 2.0 | 6 votes |
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 centerStyle = AbstractSheet.createCenterStyle(wb); CellStyle wrapStyle = AbstractSheet.createLeftWrapStyle(wb); 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]); } }
Example 10
Source File: PackageInfoSheetV2d1.java From tools with Apache License 2.0 | 6 votes |
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 < 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]); } }
Example 11
Source File: PerFileSheet.java From tools with Apache License 2.0 | 6 votes |
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 centerStyle = AbstractSheet.createCenterStyle(wb); CellStyle wrapStyle = AbstractSheet.createLeftWrapStyle(wb); 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]); } }
Example 12
Source File: OriginsSheetV1d1.java From tools with Apache License 2.0 | 6 votes |
public static void create(Workbook wb, String sheetName) { int sheetNum = wb.getSheetIndex(sheetName); if (sheetNum >= 0) { wb.removeSheetAt(sheetNum); } 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); }
Example 13
Source File: OriginsSheetV1d2.java From tools with Apache License 2.0 | 6 votes |
public static void create(Workbook wb, String sheetName) { int sheetNum = wb.getSheetIndex(sheetName); if (sheetNum >= 0) { wb.removeSheetAt(sheetNum); } 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); }
Example 14
Source File: ReviewersSheet.java From tools with Apache License 2.0 | 6 votes |
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 centerStyle = AbstractSheet.createCenterStyle(wb); CellStyle wrapStyle = AbstractSheet.createLeftWrapStyle(wb); 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]); } }
Example 15
Source File: NonStandardLicensesSheetV1d1.java From tools with Apache License 2.0 | 6 votes |
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 centerStyle = AbstractSheet.createCenterStyle(wb); CellStyle wrapStyle = AbstractSheet.createLeftWrapStyle(wb); 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]); } }
Example 16
Source File: PackageInfoSheetV9d1.java From tools with Apache License 2.0 | 6 votes |
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 < 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]); } }
Example 17
Source File: ExcelDropQuery.java From micro-integrator with Apache License 2.0 | 5 votes |
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"); } int sheetIndex = workbook.getSheetIndex(this.getTableName()); workbook.removeSheetAt(sheetIndex); TDriverUtil.writeRecords(workbook, ((TExcelConnection) this.getConnection()).getPath()); }
Example 18
Source File: PackageSheet.java From tools with Apache License 2.0 | 5 votes |
/** * @param wb * @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 headerRow = sheet.createRow(0); sheet.setColumnWidth(FIELD_COL, FIELD_COL_WIDTH*256); sheet.setDefaultColumnStyle(FIELD_COL, defaultStyle); Cell fieldCell = headerRow.createCell(FIELD_COL); fieldCell.setCellStyle(headerStyle); fieldCell.setCellValue(FIELD_HEADER_TEXT); sheet.setColumnWidth(EQUALS_COL, EQUALS_COL_WIDTH * 256); sheet.setDefaultColumnStyle(EQUALS_COL, defaultStyle); Cell equalsCell = headerRow.createCell(EQUALS_COL); equalsCell.setCellStyle(headerStyle); equalsCell.setCellValue(EQUALS_HEADER_TEXT); for (int i = FIRST_DOC_COL; i < MultiDocumentSpreadsheet.MAX_DOCUMENTS+FIRST_DOC_COL; i++) { sheet.setColumnWidth(i, COL_WIDTH*256); sheet.setDefaultColumnStyle(i, defaultStyle); Cell cell = headerRow.createCell(i); cell.setCellStyle(headerStyle); } }
Example 19
Source File: LicenseSheet.java From tools with Apache License 2.0 | 5 votes |
/** * Create a blank worksheet NOTE: Replaces / deletes existing sheet by the same name */ public static void create(Workbook wb, String sheetName) { int sheetNum = wb.getSheetIndex(sheetName); if (sheetNum >= 0) { wb.removeSheetAt(sheetNum); } Sheet sheet = wb.createSheet(sheetName); Row row = sheet.createRow(0); for (int i = 0; i < HEADER_TITLES.length; i++) { Cell cell = row.createCell(i); cell.setCellValue(HEADER_TITLES[i]); } }
Example 20
Source File: SampleTest.java From xlsmapper with Apache License 2.0 | 4 votes |
/** * {@link XlsSheet} - 正規表現の場合のシートのコピー */ @Test public void test_Sheet_regex_clone() throws Exception { // 正規表現による複数のシートを出力する場合。 // 書き込み時に、シート名を設定して、一意に関連づけます。 SheetRegexClone sheet1 = new SheetRegexClone(); sheet1.sheetName = "Sheet_1"; // シート名の設定 SheetRegexClone sheet2 = new SheetRegexClone(); sheet2.sheetName = "Sheet_2"; // シート名の設定 SheetRegexClone sheet3 = new SheetRegexClone(); sheet3.sheetName = "Sheet_3"; // シート名の設定 SheetRegexClone[] sheets = new SheetRegexClone[]{sheet1, sheet2, sheet3}; // シートのクローン Workbook workbook = WorkbookFactory.create(new FileInputStream("src/test/data/sample_template.xlsx")); Sheet templateSheet = workbook.getSheet("XlsSheet(regexp)"); for(SheetRegexClone sheetObj : sheets) { int sheetIndex = workbook.getSheetIndex(templateSheet); Sheet cloneSheet = workbook.cloneSheet(sheetIndex); workbook.setSheetName(workbook.getSheetIndex(cloneSheet), sheetObj.sheetName); } // コピー元のシートを削除する workbook.removeSheetAt(workbook.getSheetIndex(templateSheet)); // クローンしたシートファイルを、一時ファイルに一旦出力する。 File cloneTemplateFile = File.createTempFile("template", ".xlsx"); workbook.write(new FileOutputStream(cloneTemplateFile)); // 複数のシートの書き込み XlsMapper xlsMapper = new XlsMapper(); xlsMapper.saveMultiple( new FileInputStream(cloneTemplateFile), // クローンしたシートを持つファイルを指定する new FileOutputStream(new File(OUT_DIR, "sample_out.xlsx")), sheets); }