Created
August 11, 2017 07:43
-
-
Save bozhink/9df3070d3bf880e24c16e096254cc9b1 to your computer and use it in GitHub Desktop.
NPOI Summary Information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// See https://stackoverflow.com/questions/11143303/how-to-set-author-name-to-excel-file-using-poi | |
public static void SetAuthor(this IWorkbook workbook, string author) | |
{ | |
if (workbook is NPOI.XSSF.UserModel.XSSFWorkbook) | |
{ | |
var xssfWorkbook = workbook as NPOI.XSSF.UserModel.XSSFWorkbook; | |
var xmlProps = xssfWorkbook.GetProperties(); | |
var coreProps = xmlProps.CoreProperties; | |
coreProps.Creator = author; | |
return; | |
} | |
if (workbook is NPOI.HSSF.UserModel.HSSFWorkbook) | |
{ | |
var hssfWorkbook = workbook as NPOI.HSSF.UserModel.HSSFWorkbook; | |
var summaryInfo = hssfWorkbook.SummaryInformation; | |
if (summaryInfo != null) | |
{ | |
summaryInfo.Author = author; | |
return; | |
} | |
var newDocInfo = NPOI.HPSF.PropertySetFactory.CreateDocumentSummaryInformation(); | |
var newInfo = NPOI.HPSF.PropertySetFactory.CreateSummaryInformation(); | |
newInfo.Author = author; | |
hssfWorkbook.DocumentSummaryInformation = newDocInfo; | |
hssfWorkbook.SummaryInformation = newInfo; | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment