using Sarand.Net.Standard.Base.Utils;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Sarand.Net.Standard.Proc.Excel
{
//=======================================================================
public static class ExcelHelper
{
//-------------------------------------------------------------------
///
/// Validate worksheet name.
/// Worksheet names cannot:
/// - Be blank.
/// - Contain more than 31 characters.
/// - Contain any of the following characters: / \ ? * : [ ]
/// - For example, 02/17/2016 would not be a valid worksheet name, but 02-17-2016 would work fine.
/// - Begin or end with an apostrophe ('), but they can be used in between text or numbers in a name.
/// - Be named "History". This is a reserved word Excel uses internally.
///
///
///
public static bool IsValidSheetName(String name)
{
if (Base.Utils.StringUtil.IsBlank(name)) return false;
if (name.Length > 31) return false;
if (Regex.IsMatch(name, "[/\\\\?*:[\\]]")) return false;
if (name.StartsWith("'") || name.EndsWith("'")) return false;
if (name.EqualsCI("History")) return false;
return true;
}
//-------------------------------------------------------------------
}
//=======================================================================
}