コード例 #1
0
   def replaceSummaryInfo(self, ole2filename, blank=False):

      fin = FileInputStream(ole2filename)
      fs = NPOIFSFileSystem(fin)
      root = fs.getRoot()
      si = False
      siFound = False
      for obj in root:
         x = obj.getShortDescription()
         if x == (u"\u0005" + "SummaryInformation"):
            siFound = True
            if blank == False:
               test = root.getEntry((u"\u0005" + "SummaryInformation")) 
               dis = DocumentInputStream(test);
               ps = PropertySet(dis);
               #https://poi.apache.org/apidocs/org/apache/poi/hpsf/SummaryInformation.html
               si = SummaryInformation(ps);

      if blank == False and siFound == True:
         si.write(root, (u"\u0005" + "SummaryInformation"))
      else:
         ps = PropertySetFactory.newSummaryInformation()      
         ps.write(root, (u"\u0005" + "SummaryInformation"));
      
      out = FileOutputStream(ole2filename);
      fs.writeFilesystem(out);
      out.close();
コード例 #2
0
 def replaceDocumentSummary(self, ole2filename, blank=False):
    fin = FileInputStream(ole2filename)
    fs = NPOIFSFileSystem(fin)
    root = fs.getRoot()
    si = False
    siFound = False
    for obj in root:
       x = obj.getShortDescription()
       if x == (u"\u0005" + "DocumentSummaryInformation"):   
          siFound=True
          if blank == False:
             test = root.getEntry((u"\u0005" + "DocumentSummaryInformation")) 
             dis = DocumentInputStream(test);
             ps = PropertySet(dis);
             try:
                si = DocumentSummaryInformation(ps)
             except UnexpectedPropertySetTypeException as e:
                sys.stderr.write("Error writing old DocumentSymmaryInformation:" + str(e).replace('org.apache.poi.hpsf.UnexpectedPropertySetTypeException:',''))
                sys.exit(1)
                
    if blank == False and siFound == True:
       si.write(root, (u"\u0005" + "DocumentSummaryInformation"))
    else:
       ps = PropertySetFactory.newDocumentSummaryInformation()      
       ps.write(root, (u"\u0005" + "DocumentSummaryInformation"));
    
    out = FileOutputStream(ole2filename);
    fs.writeFilesystem(out);
    out.close();