using System; using System.Collections.Generic; using System.Text; using HH.WMS.Utils.NPOI.SS.UserModel; namespace HH.WMS.Utils.NPOI.SS.Util { /** * Helper methods for when working with Usermodel Workbooks */ public class WorkbookUtil { /** * 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)}. *
* Rules: * * 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(String nameProposal) { if (nameProposal == null) { return "null"; } if (nameProposal.Length < 1) { return "empty"; } int length = Math.Min(31, nameProposal.Length); String shortenname = nameProposal.Substring(0, length); StringBuilder result = new StringBuilder(shortenname); for (int i=0; i * 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: * * The string MUST NOT begin or end with the single quote (') character. *

* * @param sheetName the name to validate */ public static void ValidateSheetName(String sheetName) { if (sheetName == null) { throw new ArgumentException("sheetName must not be null"); } int len = sheetName.Length; if (len < 1 || len > 31) { throw new ArgumentException("sheetName '" + sheetName + "' is invalid - character count MUST be greater than or equal to 1 and less than or equal to 31"); } for (int i=0; i