You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by dpmihai <dp...@yahoo.com> on 2009/11/24 16:14:11 UTC

SummaryInformation

I saw the example ModifyDocumentSummaryInformation.java  to modify a
SummaryInformation for excel files. But I do not know how to create this
information at the same time with the file. 

To modify on an existing file is like this :

           File poiFilesystem = new File(filePath);
            InputStream is = new FileInputStream(poiFilesystem);
            POIFSFileSystem poifs = new POIFSFileSystem(is);
            is.close();
            DirectoryEntry dir = poifs.getRoot();

            SummaryInformation si =
PropertySetFactory.newSummaryInformation();
            si.setTitle(title);
            // other properties

            si.write(dir, SummaryInformation.DEFAULT_STREAM_NAME);
            
            OutputStream out = new FileOutputStream(poiFilesystem);
            poifs.writeFilesystem(out);
            out.close();

But if I do not have the file yet, I saw that no property in
SumarryInformation is created.
Is there a way to create the information when we create the file?( before we
close the file output stream)
-- 
View this message in context: http://old.nabble.com/SummaryInformation-tp26497648p26497648.html
Sent from the POI - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: SummaryInformation

Posted by dpmihai <dp...@yahoo.com>.
Is there a link from where to get a nightly build?

-- 
View this message in context: http://old.nabble.com/SummaryInformation-tp26497648p26525289.html
Sent from the POI - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: SummaryInformation

Posted by dpmihai <dp...@yahoo.com>.
Thank you for the link.


-- 
View this message in context: http://old.nabble.com/SummaryInformation-tp26497648p26528563.html
Sent from the POI - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: SummaryInformation

Posted by Nick Burch <ni...@torchbox.com>.
On Thu, 26 Nov 2009, dpmihai wrote:
> Is there a link from where to get a POI nightly build?

You can get nightlies from:
 	http://encore.torchbox.com/poi-svn-build/

Or, Dave is doing some great work on the "how to build" page if you want 
to just do a svn checkout yourself:
 	http://poi.apache.org/howtobuild.html

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: SummaryInformation

Posted by dpmihai <dp...@yahoo.com>.
Is there a link from where to get a POI nightly build? 

-- 
View this message in context: http://old.nabble.com/SummaryInformation-tp26497648p26525316.html
Sent from the POI - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: SummaryInformation

Posted by dpmihai <dp...@yahoo.com>.
Does createInformationProperties() creates a SummaryInformation object on
which I can set properties?  


Nick Burch wrote:
> 
> 
> I've added something inspired by this to POIDocument - the 
> createInformationProperties() method. Will hopefully do what you need.
> 
> (You'll need a nightly build or svn checkout - I've only just added it!)
> 
> Nick
> 

-- 
View this message in context: http://old.nabble.com/SummaryInformation-tp26497648p26512829.html
Sent from the POI - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: SummaryInformation

Posted by Nick Burch <ni...@torchbox.com>.
On Wed, 25 Nov 2009, Rainer Klute wrote:
> What you could do is looking into the HPSF test cases: In the
> src/testcases there is a class org.apache.poi.hpsf.basic.TestWrite. Look
> at its methods testWriteEmptyPropertySet and testWriteSimplePropertySet.

I've added something inspired by this to POIDocument - the 
createInformationProperties() method. Will hopefully do what you need.

(You'll need a nightly build or svn checkout - I've only just added it!)

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: SummaryInformation

Posted by Rainer Klute <ra...@itemis.de>.
Am 25.11.2009 14:38, schrieb dpmihai:
> The test testWriteSimplePropertySet() just creates an excel file which if I
> want to open with Microsoft Excel I get "file format is not valid" 
>   

Yes, that's true and intentional, because the properties stuff (HPSF) is
independend of Excel, Word etc.


> If i add just these lines at the beginning in the test method :
>
>         HSSFWorkbook wb = new HSSFWorkbook();
>         HSSFSheet xlsSheet = wb.createSheet("Page 1");
>         wb.write(out);
>
> I have a valid excel file but with no information. So I cannot write both
> content and summary on the same output stream? (I do not read the
> information, just I look inside the excel file at Properties).
>   

Hm, I never fiddled around with HSSF. Perhaps the others can help?


-- 
Rainer Klute
Software-Architekt

Telefon: +49 (0) 231 / 98 60-222
Telefax: +49 (0) 231 / 98 60-211
Mobil: +49 (0) 151 / 17396741
       +49 (0) 172 / 2324824

http://www.itemis.de/
rainer.klute@itemis.de
https://www.xing.com/profile/Rainer_Klute2
itemis AG
Am Brambusch 15-24
44536 Lünen

OpenPGP-Fingerprint: E4E4386515EE0BED5C162FBB5343461584B5A42E
- Wenn deine E-Mail vertraulicher als eine Postkarte sein soll...

Rechtlicher Hinweis:
Amtsgericht Dortmund, HRB 20621
Vorstand: Wolfgang Neuhaus, Jens Wagener, Dr. Georg Pietrek
Aufsichtsrat: Dr. Burkhard Igel(Vors.), Stephan Grollmann, Michael Neuhaus



Re: SummaryInformation

Posted by dpmihai <dp...@yahoo.com>.

This test fails :

public void testWriteSimplePropertySet()
            throws IOException, UnsupportedVariantTypeException
        {
            final String AUTHOR = "Rainer Klute";
            final String TITLE = "Test Document";

            final File filename = new File(POI_FS);
            filename.deleteOnExit();
            final OutputStream out = new FileOutputStream(filename);
            final POIFSFileSystem poiFs = new POIFSFileSystem();

            HSSFWorkbook wb = new HSSFWorkbook();
            HSSFSheet xlsSheet = wb.createSheet("Page 1");
            wb.write(out);

            final MutablePropertySet ps = new MutablePropertySet();
            final MutableSection si = new MutableSection();
            si.setFormatID(SectionIDMap.SUMMARY_INFORMATION_ID);
            ps.getSections().set(0, si);

            final MutableProperty p = new MutableProperty();
            p.setID(PropertyIDMap.PID_AUTHOR);
            p.setType(Variant.VT_LPWSTR);
            p.setValue(AUTHOR);
            si.setProperty(p);
            si.setProperty(PropertyIDMap.PID_TITLE, Variant.VT_LPSTR,
TITLE);

            poiFs.createDocument(ps.toInputStream(),
                                 SummaryInformation.DEFAULT_STREAM_NAME);
            poiFs.writeFilesystem(out);
            out.close();

            /* Read the POIFS: */
            final PropertySet[] psa = new PropertySet[1];
            final POIFSReader r = new POIFSReader();
            r.registerListener(new POIFSReaderListener()
                {
                    public void processPOIFSReaderEvent
                        (final POIFSReaderEvent event)
                    {
                        try
                        {
                            psa[0] =
PropertySetFactory.create(event.getStream());
                        }
                        catch (Exception ex)
                        {
                            ex.printStackTrace();
                            //fail(org.apache.poi.hpsf.Util.toString(ex));
                        }
                    }

                },
                SummaryInformation.DEFAULT_STREAM_NAME);
            r.read(new FileInputStream(filename));
            Assert.assertNotNull(psa[0]);
            Assert.assertTrue(psa[0].isSummaryInformation());

            final Section s = (Section) (psa[0].getSections().get(0));
            Object p1 = s.getProperty(PropertyIDMap.PID_AUTHOR);
            Object p2 = s.getProperty(PropertyIDMap.PID_TITLE);
            Assert.assertEquals(AUTHOR, p1);
            Assert.assertEquals(TITLE, p2);
        }

-- 
View this message in context: http://old.nabble.com/SummaryInformation-tp26497648p26525410.html
Sent from the POI - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: SummaryInformation

Posted by dpmihai <dp...@yahoo.com>.
The test testWriteSimplePropertySet() just creates an excel file which if I
want to open with Microsoft Excel I get "file format is not valid" 

If i add just these lines at the beginning in the test method :

        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet xlsSheet = wb.createSheet("Page 1");
        wb.write(out);

I have a valid excel file but with no information. So I cannot write both
content and summary on the same output stream? (I do not read the
information, just I look inside the excel file at Properties).
-- 
View this message in context: http://old.nabble.com/SummaryInformation-tp26497648p26512763.html
Sent from the POI - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: SummaryInformation

Posted by Rainer Klute <ra...@itemis.de>.
What you could do is looking into the HPSF test cases: In the
src/testcases there is a class org.apache.poi.hpsf.basic.TestWrite. Look
at its methods testWriteEmptyPropertySet and testWriteSimplePropertySet.
Both create a new file and write an empty resp. a simple property set to
it, close the file, reopen it and check whether the contents is as expected.

Comparing with your own code might help.

-- 
Rainer Klute
Software-Architekt

Telefon: +49 (0) 231 / 98 60-222
Telefax: +49 (0) 231 / 98 60-211
Mobil: +49 (0) 151 / 17396741
       +49 (0) 172 / 2324824

http://www.itemis.de/
rainer.klute@itemis.de
https://www.xing.com/profile/Rainer_Klute2
itemis AG
Am Brambusch 15-24
44536 Lünen

OpenPGP-Fingerprint: E4E4386515EE0BED5C162FBB5343461584B5A42E
- Wenn deine E-Mail vertraulicher als eine Postkarte sein soll...

Rechtlicher Hinweis:
Amtsgericht Dortmund, HRB 20621
Vorstand: Wolfgang Neuhaus, Jens Wagener, Dr. Georg Pietrek
Aufsichtsrat: Dr. Burkhard Igel(Vors.), Stephan Grollmann, Michael Neuhaus



Re: SummaryInformation

Posted by dpmihai <dp...@yahoo.com>.
I have a standalone application :

OutputStream fos = new FileOutputStream(fileName);
....
HSSFWorkbook wb = new HSSFWorkbook();
....
// do excel poi stuff
....
wb.write(fos);
fos.flush();
// (1)

fos.close();

// (2)

If I call the summary information <code> previously written at position (1)
no properties are set 
(and this is because POIFSFileSystem needs an input stream which I do not
have at that time). But if I call the <code> at position (2), meaning I have
a file on disk,  it works. 

I just want to create information at the same time with the file (1) and I
tried also with the HSSFWorkbook  as suggested :

SummaryInformation si = wb.getSummaryInformation();  
This method from WorkBook is inherited from POIDocument. (as I saw in api
documentation)

I get at this line the exception shown previously (NullPointerException) .
So I suppose there is no SummaryInformation yet.

And anyway I saw hat I have to write SummaryInformation (not just set
properties on it) which needs POIFSFileSystem  root.


-- 
View this message in context: http://old.nabble.com/SummaryInformation-tp26497648p26508848.html
Sent from the POI - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: SummaryInformation

Posted by Rainer Klute <ra...@itemis.de>.
Do you have a simple stand-alone application or a JUnit test case that
shows the faulty behaviour? And does the file contain an empty
SummaryInformation or none at all?

Am 24.11.2009 16:14, schrieb dpmihai:
> I saw the example ModifyDocumentSummaryInformation.java  to modify a
> SummaryInformation for excel files. But I do not know how to create this
> information at the same time with the file. 
>
> To modify on an existing file is like this :
>
>            File poiFilesystem = new File(filePath);
>             InputStream is = new FileInputStream(poiFilesystem);
>             POIFSFileSystem poifs = new POIFSFileSystem(is);
>             is.close();
>             DirectoryEntry dir = poifs.getRoot();
>
>             SummaryInformation si =
> PropertySetFactory.newSummaryInformation();
>             si.setTitle(title);
>             // other properties
>
>             si.write(dir, SummaryInformation.DEFAULT_STREAM_NAME);
>             
>             OutputStream out = new FileOutputStream(poiFilesystem);
>             poifs.writeFilesystem(out);
>             out.close();
>
> But if I do not have the file yet, I saw that no property in
> SumarryInformation is created.
> Is there a way to create the information when we create the file?( before we
> close the file output stream)
>   

-- 
Rainer Klute
Software-Architekt

Telefon: +49 (0) 231 / 98 60-222
Telefax: +49 (0) 231 / 98 60-211
Mobil: +49 (0) 151 / 17396741
       +49 (0) 172 / 2324824

http://www.itemis.de/
rainer.klute@itemis.de
https://www.xing.com/profile/Rainer_Klute2
itemis AG
Am Brambusch 15-24
44536 Lünen

OpenPGP-Fingerprint: E4E4386515EE0BED5C162FBB5343461584B5A42E
- Wenn deine E-Mail vertraulicher als eine Postkarte sein soll...

Rechtlicher Hinweis:
Amtsgericht Dortmund, HRB 20621
Vorstand: Wolfgang Neuhaus, Jens Wagener, Dr. Georg Pietrek
Aufsichtsrat: Dr. Burkhard Igel(Vors.), Stephan Grollmann, Michael Neuhaus



Re: SummaryInformation

Posted by Nick Burch <ni...@torchbox.com>.
On Tue, 24 Nov 2009, dpmihai wrote:
> If I do like this I gate the following exception :
>
> java.lang.NullPointerException
> 	at org.apache.poi.POIDocument.getPropertySet(POIDocument.java:126)
> 	at org.apache.poi.POIDocument.readProperties(POIDocument.java:99)
> 	at org.apache.poi.POIDocument.getSummaryInformation(POIDocument.java:85)
>        ...........................

Hmm. If you write the file out to an outputstream, then load it back in, 
does it have the properties then? Looking at the code, I have a nasty 
feeling it might not do even then. Can you check easily?

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: SummaryInformation

Posted by MSB <ma...@tiscali.co.uk>.
What about calling the getDocumentSummaryInformation() method that is also
defined on the POIDocument class and, therefore, inherited by HSSFDocument?
Do not know if this will work but it must be worth a try.

Yours

Mark B


dpmihai wrote:
> 
> If I do like this I gate the following exception :
> 
> java.lang.NullPointerException
> 	at org.apache.poi.POIDocument.getPropertySet(POIDocument.java:126)
> 	at org.apache.poi.POIDocument.readProperties(POIDocument.java:99)
> 	at org.apache.poi.POIDocument.getSummaryInformation(POIDocument.java:85)
>         ........................... 
> 
> 
> Nick Burch wrote:
>> 
>> On Tue, 24 Nov 2009, dpmihai wrote:
>>> ( before we close the file output stream)  : I was talking about the 
>>> file output stream used to write the WorkBook.
>> 
>> Can you not call the getSummaryInformation() method of HSSFWorkbook 
>> (inherited from POIDocument), and work on it that way before you save 
>> the workbook?
>> 
>> Nick
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
>> For additional commands, e-mail: dev-help@poi.apache.org
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/SummaryInformation-tp26497648p26498695.html
Sent from the POI - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: SummaryInformation

Posted by dpmihai <dp...@yahoo.com>.
If I do like this I gate the following exception :

java.lang.NullPointerException
	at org.apache.poi.POIDocument.getPropertySet(POIDocument.java:126)
	at org.apache.poi.POIDocument.readProperties(POIDocument.java:99)
	at org.apache.poi.POIDocument.getSummaryInformation(POIDocument.java:85)
        ........................... 


Nick Burch wrote:
> 
> On Tue, 24 Nov 2009, dpmihai wrote:
>> ( before we close the file output stream)  : I was talking about the 
>> file output stream used to write the WorkBook.
> 
> Can you not call the getSummaryInformation() method of HSSFWorkbook 
> (inherited from POIDocument), and work on it that way before you save 
> the workbook?
> 
> Nick
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
> For additional commands, e-mail: dev-help@poi.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/SummaryInformation-tp26497648p26498539.html
Sent from the POI - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: SummaryInformation

Posted by Nick Burch <ni...@torchbox.com>.
On Tue, 24 Nov 2009, dpmihai wrote:
> ( before we close the file output stream)  : I was talking about the 
> file output stream used to write the WorkBook.

Can you not call the getSummaryInformation() method of HSSFWorkbook 
(inherited from POIDocument), and work on it that way before you save 
the workbook?

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: SummaryInformation

Posted by dpmihai <dp...@yahoo.com>.
( before we close the file output stream)  : I was talking about the file
output stream used to write the WorkBook.

-- 
View this message in context: http://old.nabble.com/SummaryInformation-tp26497648p26497811.html
Sent from the POI - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org