/** * Creates a valid sheet name, which is conform to the rules. * In any case, the result safely can be used for * {@link org.apache.poi.ss.usermodel.Workbook#setSheetName(int, String)}. * <br> * Rules: * <ul> * <li>never null</li> * <li>minimum length is 1</li> * <li>maximum length is 31</li> * <li>doesn't contain special chars: : 0x0000, 0x0003, / \ ? * ] [ </li> * <li>Sheet names must not begin or end with ' (apostrophe)</li> * </ul> * Invalid characters are replaced by one space character ' '. * * @param nameProposal can be any string, will be truncated if necessary, * allowed to be null * @return a valid string, "empty" if to short, "null" if null */ public static String createSafeSheetName(final String nameProposal) { return createSafeSheetName(nameProposal, ' '); }
/** * Set the sheetname for this sheet. (this appears in the tabs at the bottom) * @param sheetName the name of the sheet * @see org.apache.poi.ss.util.WorkbookUtil#createSafeSheetName(String nameProposal) * for a safe way to create valid names * @throws IllegalArgumentException if sheet name will cause excel to crash. */ public void setSheetname(String sheetName) { WorkbookUtil.validateSheetName(sheetName); field_5_sheetname = sheetName; field_4_isMultibyteUnicode = StringUtil.hasMultibyte(sheetName) ? 1 : 0; }
public void setSheetHidden(int sheetIx, int hidden) { validateSheetIndex(sheetIx); WorkbookUtil.validateSheetState(hidden); workbook.setSheetHidden(sheetIx, hidden); }
public void setSheetHidden(int sheetIx, int hidden) { validateSheetIndex(sheetIx); WorkbookUtil.validateSheetState(hidden); workbook.setSheetHidden(sheetIx, hidden); }
@Override public void export(FacesContext context, String filename, List<DataTable> tables, boolean pageOnly, boolean selectionOnly, String encodingType, MethodExpression preProcessor, MethodExpression postProcessor, ExporterOptions options, MethodExpression onTableRender) throws IOException { Workbook wb = createWorkBook(); if (preProcessor != null) { preProcessor.invoke(context.getELContext(), new Object[]{wb}); } for (int i = 0; i < tables.size(); i++) { DataTable table = tables.get(i); String sheetName = getSheetName(context, table); if (sheetName == null) { sheetName = table.getId(); } sheetName = WorkbookUtil.createSafeSheetName(sheetName); if (sheetName.equals("empty") || sheetName.equals("null")) { sheetName = "Sheet" + String.valueOf(i + 1); } Sheet sheet = createSheet(wb, sheetName); applyOptions(wb, table, sheet, options); exportTable(context, table, sheet, pageOnly, selectionOnly); for (int j = 0; j < table.getColumnsCount(); j++) { sheet.autoSizeColumn((short) j); } } if (postProcessor != null) { postProcessor.invoke(context.getELContext(), new Object[]{wb}); } writeExcelToResponse(context.getExternalContext(), wb, filename); }
sheetname = sheetname.substring(0, 31); WorkbookUtil.validateSheetName(sheetname);
/** * Hide or unhide a sheet. * * <ul> * <li>0 - visible. </li> * <li>1 - hidden. </li> * <li>2 - very hidden.</li> * </ul> * @param sheetIx the sheet index (0-based) * @param state one of the following <code>Workbook</code> constants: * <code>Workbook.SHEET_STATE_VISIBLE</code>, * <code>Workbook.SHEET_STATE_HIDDEN</code>, or * <code>Workbook.SHEET_STATE_VERY_HIDDEN</code>. * @throws IllegalArgumentException if the supplied sheet index or state is invalid */ public void setSheetHidden(int sheetIx, int state) { validateSheetIndex(sheetIx); WorkbookUtil.validateSheetState(state); CTSheet ctSheet = sheets.get(sheetIx).sheet; ctSheet.setState(STSheetState.Enum.forInt(state + 1)); }
@Override public void export(FacesContext context, DataTable table, String filename, boolean pageOnly, boolean selectionOnly, String encodingType, MethodExpression preProcessor, MethodExpression postProcessor, ExporterOptions options, MethodExpression onTableRender) throws IOException { Workbook wb = createWorkBook(); String sheetName = getSheetName(context, table); if (sheetName == null) { sheetName = table.getId(); } sheetName = WorkbookUtil.createSafeSheetName(sheetName); if (sheetName.equals("empty") || sheetName.equals("null")) { sheetName = "Sheet"; } Sheet sheet = createSheet(wb, sheetName); if (preProcessor != null) { preProcessor.invoke(context.getELContext(), new Object[]{wb}); } applyOptions(wb, table, sheet, options); exportTable(context, table, sheet, pageOnly, selectionOnly); for (int i = 0; i < table.getColumnsCount(); i++) { sheet.autoSizeColumn((short) i); } if (postProcessor != null) { postProcessor.invoke(context.getELContext(), new Object[]{wb}); } writeExcelToResponse(context.getExternalContext(), wb, filename); }
sheetname = sheetname.substring(0, 31); WorkbookUtil.validateSheetName(sheetname);
Device device = Context.getIdentityManager().getById(deviceId); deviceEvents.setDeviceName(device.getName()); sheetNames.add(WorkbookUtil.createSafeSheetName(deviceEvents.getDeviceName())); if (device.getGroupId() != 0) { Group group = Context.getGroupsManager().getById(device.getGroupId());
/** * Set the sheetname for this sheet. (this appears in the tabs at the bottom) * @param sheetName the name of the sheet * @see org.apache.poi.ss.util.WorkbookUtil#createSafeSheetName(String nameProposal) * for a safe way to create valid names * @throws IllegalArgumentException if sheet name will cause excel to crash. */ public void setSheetname(String sheetName) { WorkbookUtil.validateSheetName(sheetName); field_5_sheetname = sheetName; field_4_isMultibyteUnicode = StringUtil.hasMultibyte(sheetName) ? 1 : 0; }
Device device = Context.getIdentityManager().getById(deviceId); deviceStops.setDeviceName(device.getName()); sheetNames.add(WorkbookUtil.createSafeSheetName(deviceStops.getDeviceName())); if (device.getGroupId() != 0) { Group group = Context.getGroupsManager().getById(device.getGroupId());
/** * Set the sheetname for this sheet. (this appears in the tabs at the bottom) * @param sheetName the name of the sheet * @see org.apache.poi.ss.util.WorkbookUtil#createSafeSheetName(String nameProposal) * for a safe way to create valid names * @throws IllegalArgumentException if sheet name will cause excel to crash. */ public void setSheetname(String sheetName) { WorkbookUtil.validateSheetName(sheetName); field_5_sheetname = sheetName; field_4_isMultibyteUnicode = StringUtil.hasMultibyte(sheetName) ? 1 : 0; }
Device device = Context.getIdentityManager().getById(deviceId); deviceTrips.setDeviceName(device.getName()); sheetNames.add(WorkbookUtil.createSafeSheetName(deviceTrips.getDeviceName())); if (device.getGroupId() != 0) { Group group = Context.getGroupsManager().getById(device.getGroupId());
/** * Set the sheetname for this sheet. (this appears in the tabs at the bottom) * @param sheetName the name of the sheet * @see org.apache.poi.ss.util.WorkbookUtil#createSafeSheetName(String nameProposal) * for a safe way to create valid names * @throws IllegalArgumentException if sheet name will cause excel to crash. */ public void setSheetname(String sheetName) { WorkbookUtil.validateSheetName(sheetName); field_5_sheetname = sheetName; field_4_isMultibyteUnicode = StringUtil.hasMultibyte(sheetName) ? 1 : 0; }
Device device = Context.getIdentityManager().getById(deviceId); deviceRoutes.setDeviceName(device.getName()); sheetNames.add(WorkbookUtil.createSafeSheetName(deviceRoutes.getDeviceName())); if (device.getGroupId() != 0) { Group group = Context.getGroupsManager().getById(device.getGroupId());
/** * Set the sheet name. * * @param sheetIndex sheet number (0 based) * @param sheetname the new sheet name * @throws IllegalArgumentException if the name is null or invalid * or workbook already contains a sheet with this name * @see #createSheet(String) * @see org.apache.poi.ss.util.WorkbookUtil#createSafeSheetName(String nameProposal) */ public void setSheetName(int sheetIndex, String sheetname) { validateSheetIndex(sheetIndex); // YK: Mimic Excel and silently truncate sheet names longer than 31 characters if(sheetname != null && sheetname.length() > 31) sheetname = sheetname.substring(0, 31); WorkbookUtil.validateSheetName(sheetname); if (containsSheet(sheetname, sheetIndex )) throw new IllegalArgumentException( "The workbook already contains a sheet of this name" ); XSSFFormulaUtils utils = new XSSFFormulaUtils(this); utils.updateSheetName(sheetIndex, sheetname); workbook.getSheets().getSheetArray(sheetIndex).setName(sheetname); }
/** * Creates a valid sheet name, which is conform to the rules. * In any case, the result safely can be used for * {@link org.apache.poi.ss.usermodel.Workbook#setSheetName(int, String)}. * <br> * Rules: * <ul> * <li>never null</li> * <li>minimum length is 1</li> * <li>maximum length is 31</li> * <li>doesn't contain special chars: : 0x0000, 0x0003, / \ ? * ] [ </li> * <li>Sheet names must not begin or end with ' (apostrophe)</li> * </ul> * Invalid characters are replaced by one space character ' '. * * @param nameProposal can be any string, will be truncated if necessary, * allowed to be null * @return a valid string, "empty" if to short, "null" if null */ public static String createSafeSheetName(final String nameProposal) { return createSafeSheetName(nameProposal, ' '); }
sheetname = sheetname.substring(0, 31); WorkbookUtil.validateSheetName(sheetname);
/** * Creates a valid sheet name, which is conform to the rules. * In any case, the result safely can be used for * {@link org.apache.poi.ss.usermodel.Workbook#setSheetName(int, String)}. * <br> * Rules: * <ul> * <li>never null</li> * <li>minimum length is 1</li> * <li>maximum length is 31</li> * <li>doesn't contain special chars: : 0x0000, 0x0003, / \ ? * ] [ </li> * <li>Sheet names must not begin or end with ' (apostrophe)</li> * </ul> * Invalid characters are replaced by one space character ' '. * * @param nameProposal can be any string, will be truncated if necessary, * allowed to be null * @return a valid string, "empty" if to short, "null" if null */ public final static String createSafeSheetName(final String nameProposal) { return createSafeSheetName(nameProposal, ' '); }