Java Code Examples for org.apache.poi.ss.usermodel.Workbook#removeSheetAt()
The following examples show how to use
org.apache.poi.ss.usermodel.Workbook#removeSheetAt() .
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: PerFileSheetV2d2.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: 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 3
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 4
Source File: PerFileSheetV1d2.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 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: DocumentRelationshipSheet.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(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); } }
Example 7
Source File: ExternalRefsSheet.java From tools with Apache License 2.0 | 6 votes |
/** * @param wb * @param externalRefsSheetName */ public static void create(Workbook wb, String externalRefsSheetName) { int sheetNum = wb.getSheetIndex(externalRefsSheetName); if (sheetNum >= 0) { wb.removeSheetAt(sheetNum); } Sheet sheet = wb.createSheet(externalRefsSheetName); 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 8
Source File: PackageInfoSheetV09d3.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: PackageInfoSheetV2d2.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 10
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 11
Source File: PackageInfoSheetV09d3.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 12
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 13
Source File: PackageInfoSheetV09d2.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 14
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 15
Source File: PackageInfoSheetV2d0.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 16
Source File: ExcelExportOfTemplateUtil.java From jeewx with Apache License 2.0 | 5 votes |
private static Workbook createSheetInUserModel2FileByTemplate( TemplateExportParams params, Class<?> pojoClass, Collection<?> dataSet, Map<String, Object> map) { // step 1. 判断模板的地址 if (StringUtils.isEmpty(params.getTemplateUrl())) { return null; } Workbook wb = null; // step 2. 判断模板的Excel类型,解析模板 try { wb = getCloneWorkBook(params); // step 3. 删除其他的sheet for (int i = wb.getNumberOfSheets()-1; i >= 0; i--) { if (i != params.getSheetNum()) { wb.removeSheetAt(i); } } if(StringUtils.isNotEmpty(params.getSheetName())){ wb.setSheetName(0, params.getSheetName()); } // step 4. 解析模板 parseTemplate(wb.getSheetAt(0), map); if(dataSet != null){ // step 5. 正常的数据填充 addDataToSheet(params, pojoClass, dataSet, wb.getSheetAt(0), wb); } } catch (Exception e) { e.printStackTrace(); return null; } return wb; }
Example 17
Source File: AbstractFileCompareSheet.java From tools with Apache License 2.0 | 5 votes |
/** * @param wb * @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); } }
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); }