Files
Common-VS2019/SacsStandardProc/Proc/Excel/ExcelHelper.cs
T
2024-02-27 15:45:02 +00:00

39 lines
1.5 KiB
C#

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
{
//-------------------------------------------------------------------
/// <summary>
/// Validate worksheet name.
/// <para>Worksheet names cannot:</para>
/// <para>- Be blank.</para>
/// <para>- Contain more than 31 characters.</para>
/// <para>- Contain any of the following characters: / \ ? * : [ ]</para>
/// <para>- For example, 02/17/2016 would not be a valid worksheet name, but 02-17-2016 would work fine.</para>
/// <para>- Begin or end with an apostrophe ('), but they can be used in between text or numbers in a name.</para>
/// <para>- Be named "History". This is a reserved word Excel uses internally.</para>
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
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;
}
//-------------------------------------------------------------------
}
//=======================================================================
}