如何在Open XML SDK 2.5中为excel设置Origin Company(作者)?

时间:2017-06-20 12:43:06

标签: xml excel properties sdk

我可以通过.PackageProperties为文档设置很多属性,但我找不到公司部分?

public SpreadsheetDocument CreateDocument(string path)
    {
        m_Document = SpreadsheetDocument.Create(path, SpreadsheetDocumentType.Workbook);
        FilePath = path;

        // create the workbook
        WorkbookPart workbookPart = m_Document.AddWorkbookPart();
        workbookPart.Workbook = new Workbook();     // create the worksheet
        WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
        worksheetPart.Worksheet = new Worksheet();

        // create sheet data
        SheetData sheetData = new SheetData();
        worksheetPart.Worksheet.AppendChild(sheetData);

        //// save worksheet
        //worksheetPart.Worksheet.Save();

        //add sheets container
        Sheets sheets = new Sheets();
        workbookPart.Workbook.AppendChild(sheets);
        workbookPart.Workbook.Save();

        //add default styles
        m_StyleHelper.AttachToDocument(m_Document);

        //set properties
        m_Document.PackageProperties.Subject = "Statistics sub";
        m_Document.PackageProperties.Creator = "c1";

        m_Document.PackageProperties.Created = DateTime.Now;
        m_Document.PackageProperties.Modified = DateTime.Now;
        m_Document.PackageProperties.LastModifiedBy = "lmb1";
        m_Document.PackageProperties.Category = "Statistics1";
        m_Document.PackageProperties.Description = "Statistics2";            
        m_Document.PackageProperties.Title = "Title1";


        return m_Document;
    }

enter image description here

我搜索了高低,但没有运气:(

提前致谢!

西蒙

1 个答案:

答案 0 :(得分:0)

我终于明白了,公司在.ExtendedFilePropertiesPart中设置如下:

m_Document.AddExtendedFilePropertiesPart();
m_Document.ExtendedFilePropertiesPart.Properties = new DocumentFormat.OpenXml.ExtendedProperties.Properties();
m_Document.ExtendedFilePropertiesPart.Properties.Company = new DocumentFormat.OpenXml.ExtendedProperties.Company("My Company");