CustomProperty

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);
    }
}
View Code

 

posted @ 2014-11-04 17:14  ◁王浩▷  阅读(58)  评论(0)    收藏  举报