Home » excel » java – Unable to set author and title using Apache POI

java – Unable to set author and title using Apache POI

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am able to get and set the author and title name but unable to see it in output file. When i see details by clicking right and of my output file , it has old author and title name. please help me..

I am using poi apache api for excel files.

Following is the sample of my code :

public void processPOIFSReaderEvent(POIFSReaderEvent event)
{
   SummaryInformation si = null;       
   si = (SummaryInformation) PropertySetFactory.create(event.getStream());    
   si.setTitle(title);
   si.setAuthor("Author Name");
 } 
How to&Answers:

Probably you need to write back to stream your changes.

Check example here

Answer:

Try this:

HSSF:

SummaryInformation summaryInfo = workbook.getSummaryInformation();
summaryInfo.setAuthor(author); 

XSSF:

POIXMLProperties xmlProps = workbook.getProperties();    
POIXMLProperties.CoreProperties coreProps = xmlProps.getCoreProperties();    
coreProps.setCreator(author);