public static void SaveCustomProperty(this WorkbookBase book, string propertyName, string propertyValue)
{
if (string.IsNullOrEmpty(propertyValue))
{
return;
}
Office.DocumentProperties pros = book.CustomDocumentProperties as Office.DocumentProperties;
foreach (Office.DocumentProperty item in pros)
{
if (item.Name.StartsWith(propertyName))
{
item.Delete();
}
}
if (propertyValue.Length > 250)
{
string[] sValues = propertyValue.ToArrayByLenth(250);
for (int i = 1; i <= sValues.Length; i++)
{
pros.Add(propertyName + i.ToString(), false, Office.MsoDocProperties.msoPropertyTypeString, sValues[i - 1], Type.Missing);
}
}
else
{
pros.Add(propertyName, false, Office.MsoDocProperties.msoPropertyTypeString, propertyValue, Type.Missing);
}
}