Top Description Constructors Methods
org.apache.poi.ss.util

public Class WorkbookUtil

extends Object
Class Inheritance

Helper methods for when working with Usermodel Workbooks

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

a valid string, "empty" if to short, "null" if null
createSafeSheetName
(final String
can be any string, will be truncated if necessary, allowed to be null
nameProposal
)

Creates a valid sheet name, which is conform to the rules.

public static String

Returns:

a valid string, "empty" if to short, "null" if null
createSafeSheetName
(final String
can be any string, will be truncated if necessary, allowed to be null
nameProposal
,
char
the char to replace invalid characters.
replaceChar
)

Creates a valid sheet name, which is conform to the rules.

public static void
validateSheetName(String
the name to validate
sheetName
)

Validates sheet name.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

WorkbookUtilback to summary
public WorkbookUtil()

Method Detail

createSafeSheetNameback to summary
public static String createSafeSheetName(final String nameProposal)

Creates a valid sheet name, which is conform to the rules. In any case, the result safely can be used for org.apache.poi.ss.usermodel.Workbook#setSheetName(int, String).
Rules:

  • never null
  • minimum length is 1
  • maximum length is 31
  • doesn't contain special chars: : 0x0000, 0x0003, / \ ? * ] [
  • Sheet names must not begin or end with ' (apostrophe)
Invalid characters are replaced by one space character ' '.
Parameters
nameProposal:String

can be any string, will be truncated if necessary, allowed to be null

Returns:String

a valid string, "empty" if to short, "null" if null

createSafeSheetNameback to summary
public static String createSafeSheetName(final String nameProposal, char replaceChar)

Creates a valid sheet name, which is conform to the rules. In any case, the result safely can be used for org.apache.poi.ss.usermodel.Workbook#setSheetName(int, String).
Rules:

  • never null
  • minimum length is 1
  • maximum length is 31
  • doesn't contain special chars: : 0x0000, 0x0003, / \ ? * ] [
  • Sheet names must not begin or end with ' (apostrophe)
Parameters
nameProposal:String

can be any string, will be truncated if necessary, allowed to be null

replaceChar:char

the char to replace invalid characters.

Returns:String

a valid string, "empty" if to short, "null" if null

validateSheetNameback to summary
public static void validateSheetName(String sheetName)

Validates sheet name.

The character count MUST be greater than or equal to 1 and less than or equal to 31. The string MUST NOT contain the any of the following characters:

  • 0x0000
  • 0x0003
  • colon (:)
  • backslash (\)
  • asterisk (*)
  • question mark (?)
  • forward slash (/)
  • opening square bracket ([)
  • closing square bracket (])
The string MUST NOT begin or end with the single quote (') character.
Parameters
sheetName:String

the name to validate

Exceptions
IllegalArgumentException:
if validation fails