<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>user@poi.apache.org Archives</title>
<link rel="self" href="http://mail-archives.apache.org/mod_mbox/poi-user/?format=atom"/>
<link href="http://mail-archives.apache.org/mod_mbox/poi-user/"/>
<id>http://mail-archives.apache.org/mod_mbox/poi-user/</id>
<updated>2009-12-05T17:27:36Z</updated>
<entry>
<title>Re: String formatting in cells?</title>
<author><name>MSB &lt;markbrdsly@tiscali.co.uk&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c26654385.post@talk.nabble.com%3e"/>
<id>urn:uuid:%3c26654385-post@talk-nabble-com%3e</id>
<updated>2009-12-05T10:19:06Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

It is time for me to retire I think. Ignore last message and simply try this;

    public static void main(String[] args) {
        File file = null;
        FileOutputStream fos = null;
        HSSFWorkbook workbook = null;
        HSSFSheet sheet = null;
        HSSFRow row = null;
        HSSFCell cell = null;
        HSSFCellStyle wrapStyle = null;
        try {
            file = new File("C:/temp/Wrap Test.xls");
            fos = new FileOutputStream(file);

            workbook = new HSSFWorkbook();

            wrapStyle = workbook.createCellStyle();
            wrapStyle.setWrapText(true);

            sheet = workbook.createSheet("Wrap Demo.");
            row = sheet.createRow(0);
            cell = row.createCell(0);

            cell.setCellValue("This is a slightly longer String.");
            cell.setCellStyle(wrapStyle);

            workbook.write(fos);
        }
        catch(IOException ioEx) {
            System.out.println("Caught: " + ioEx.getClass().getName());
            System.out.println("Message: " + ioEx.getMessage());
            System.out.println("Stacktrace follows:............");
            ioEx.printStackTrace(System.out);
        }
        finally {
            if(fos != null) {
                try {
                    fos.close();
                }
                catch(IOException ioEx) {
                    // I G N O R E
                }
            }
        }
    }

The key is the cell style object, it ensures that the long String will be
wrapped in the cell, that the 'breaks' occur at the word boundaries and
Excel itself ensures that the row is shown expanded to the correct height to
accomodate the cells contents.

Yours

Mark B


Michael L-3 wrote:
&gt; 
&gt; Is there a way to format the string put in a cell so that it will attempt
&gt; to fit
&gt; in the visible dimensions of the cell? Currently, if I put a string whose
&gt; length
&gt; is longer than that of the cell's width, the string is cut off and can
&gt; only be
&gt; read if the reader manually extends the width of the cell. I guess what I
&gt; really
&gt; want is for the string to go to a new line in the cell when it reaches the
&gt; end
&gt; of the cell's width. Is this possible using POI?
&gt; 
&gt; 
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://old.nabble.com/String-formatting-in-cells--tp26649280p26654385.html
Sent from the POI - User mailing list archive at Nabble.com.


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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: String formatting in cells?</title>
<author><name>MSB &lt;markbrdsly@tiscali.co.uk&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c26653493.post@talk.nabble.com%3e"/>
<id>urn:uuid:%3c26653493-post@talk-nabble-com%3e</id>
<updated>2009-12-05T07:21:31Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

I am not certain just what your requirements/constraints are so this
suggestion may be useless; can you not simply increase the width of the cell
so that it is able to accomodate the String? Obvisouly, this means that the
width of the column will be set to accomodate the longest String but there
is already a method in the API to accomplish just this task. Take a look at
the autoSizeColumn() method that is defined on both of the HSSFSheet and
XSSFSheet classes. Typically, you use this by iterating through all of the
columns on a sheet immediately prior to saving the workbook away.

To answer your original question, yes it is possible to recover the width of
the column, find out how long the String is, insert a carriage
return/carriage returns at the appropriate place(s) in the String, write the
String way to the cell and set the cells format so that it's contents wrap
but this could present you with other problems; what if the row was not high
enough? Then the users would have to scroll the contents of the cell up and
down within the cell to view them fully. Of course you can increase the
rows' height but it may be that setting the columns width is the easiest,
neatest answer if this fits your requirement.

Yours

Mark B


Michael L-3 wrote:
&gt; 
&gt; Is there a way to format the string put in a cell so that it will attempt
&gt; to fit
&gt; in the visible dimensions of the cell? Currently, if I put a string whose
&gt; length
&gt; is longer than that of the cell's width, the string is cut off and can
&gt; only be
&gt; read if the reader manually extends the width of the cell. I guess what I
&gt; really
&gt; want is for the string to go to a new line in the cell when it reaches the
&gt; end
&gt; of the cell's width. Is this possible using POI?
&gt; 
&gt; 
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://old.nabble.com/String-formatting-in-cells--tp26649280p26653493.html
Sent from the POI - User mailing list archive at Nabble.com.


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



</pre>
</div>
</content>
</entry>
<entry>
<title>String formatting in cells?</title>
<author><name>Michael L &lt;icarus21@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3cloom.20091204T220621-584@post.gmane.org%3e"/>
<id>urn:uuid:%3cloom-20091204T220621-584@post-gmane-org%3e</id>
<updated>2009-12-04T21:08:47Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Is there a way to format the string put in a cell so that it will attempt to fit
in the visible dimensions of the cell? Currently, if I put a string whose length
is longer than that of the cell's width, the string is cut off and can only be
read if the reader manually extends the width of the cell. I guess what I really
want is for the string to go to a new line in the cell when it reaches the end
of the cell's width. Is this possible using POI?


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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: evaluating array formula</title>
<author><name>Josh Micich &lt;josh.micich@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3ca644352c0912041108k35fe7b70ic6673ced2843069d@mail.gmail.com%3e"/>
<id>urn:uuid:%3ca644352c0912041108k35fe7b70ic6673ced2843069d@mail-gmail-com%3e</id>
<updated>2009-12-04T19:08:19Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
It looks like Petr Udalau has done a bit of work that should get committed soon.

This is the first related bugzilla entry that Petr has submitted.
https://issues.apache.org/bugzilla/show_bug.cgi?id=48292

If you are able to help in any way (by offering new code, design work,
junit test code or even QA) that would be appreciated.

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



</pre>
</div>
</content>
</entry>
<entry>
<title>Java heap space with files &gt;30MB</title>
<author><name>Leandro Carvalho &lt;leandrodcarvalho@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c4a73a48e0912040618pa22ab6dx296607cf91fa4fbd@mail.gmail.com%3e"/>
<id>urn:uuid:%3c4a73a48e0912040618pa22ab6dx296607cf91fa4fbd@mail-gmail-com%3e</id>
<updated>2009-12-04T14:18:51Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi all,

Sorry if this is already an old subject, i really tried to search solutions
about it, but always saying to increase my JVM memory allocation, convert my
XLS files to CSV or even limit the size of my documents. None of them are
doable in my current project.

Really simple code:
HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(new
FileInputStream("c:/plan1.xls")));

Where this "plan1.xls" has more then 30MB (actually my goal is something
like 200MB).
And i want to import the content to some database.

Can it be done?

I also tried the XLS2CSVmra.class, but got another Java heap space
excpetion.

Thank you in advance.

-- 
Leandro Carvalho


</pre>
</div>
</content>
</entry>
<entry>
<title>Background color for symbol/textpart in HWPFDocument</title>
<author><name>refref &lt;supermarich@mail.ru&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c26635772.post@talk.nabble.com%3e"/>
<id>urn:uuid:%3c26635772-post@talk-nabble-com%3e</id>
<updated>2009-12-04T05:52:19Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Hi,
How can i get background color for part of .doc-document?
(need it for doc2html)

Thnks
-- 
View this message in context: http://old.nabble.com/Background-color-for-symbol-textpart-in-HWPFDocument-tp26635772p26635772.html
Sent from the POI - User mailing list archive at Nabble.com.


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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: HSSFCell short/int</title>
<author><name>&quot;David Law&quot; &lt;david.law@apconsult.de&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c200912031348.nB3DmRW3025349@post.webmailer.de%3e"/>
<id>urn:uuid:%3c200912031348-nB3DmRW3025349@post-webmailer-de%3e</id>
<updated>2009-12-03T13:48:27Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi Josh,

thanks for that thorough explanation.
My formulation was rather ambiguous.

The need for migrating to int is clear.

My issue is that for Rows it makes sense in the HSSF world to
convert to "unsigned short" by AND'ing with 65535, as that is
the maximum no. of rows, but for columns the max is 256, so it
is really quite misleading, because the signed range of the
short is sufficient.

The HSSFCell.getCell(short) code...
int ushortCellNum = cellnum &amp; 0x0000FFFF; // avoid sign extension
return getCell(ushortCellNum);
...raises an issue with the beholder that is not relevant.

Maybe I can illustrate that with an example:
I actually noticed this while migrating code from the deprecated
method to the int method. My first shot was to AND my short with
65535 before calling the int method, so you see, I was forced to
deal with an issue that was irrelevant. My code would of course
have worked with the AND, but its not necessary.

I would replace the 2 lines with...
return getCell((int)cellnum);

In any case, I would think its better to give an out-of-range error
that mentions the value supplied &amp; not its unsigned equivalent.

Regards,
DaveLaw

----- original message --------

Subject: Re: HSSFCell short/int
Sent: Wed, 02 Dec 2009
From: Josh Micich&lt;josh.micich@gmail.com&gt;

&gt; Hello Dave,
&gt; 
&gt; It's not clear if you are questioning the merit of creating the newer
&gt; method "getCell(int)", or whether the old method "getCell(short)"
&gt; should have been deprecated at all, so I'll attempt to answer both
&gt; concerns.
&gt; 
&gt; 
&gt; The most visible reason why POI is moving away from bytes and shorts
&gt; is the need for typecasts when using literal integer constants, even
&gt; when the value is quite obviously within range.  For example without
&gt; the new method "row.getCell(5)" would not compile.  We would have to
&gt; write "row.getCell((short)5)".
&gt; 
&gt; There have been several POI bugs involving representation of unsigned
&gt; (ushort, ubyte) quantities with java datatypes (signed) of the same
&gt; width (short, byte).  When shorts and bytes are used, the corrected
&gt; code generally needs more typecasts and bit mask expressions.   If
&gt; those datatypes are changed to int, the code is usually simpler and
&gt; easier to read.
&gt; 
&gt; The new method "getCell(int) method may in the first place have been
&gt; introduced as a result of the XSSF common interface work (a separate
&gt; reason, as suggested by Mark B).
&gt; 
&gt; 
&gt; That sort-of explains the rationale for creating the new method
&gt; "getCell(int)".   The reason for deprecating the old is to eliminate
&gt; overloading (of "getCell").  Method overloading is sometimes very
&gt; handy but has quite a few pitfalls, and for that reason POI tries to
&gt; use overloading sparingly.
&gt; 
&gt; As far as the exact meaning of the '@deprecated' tag, in POI (unlike
&gt; in the java runtime library) it means "This method will be removed in
&gt; a future POI version".  An alternative is always given.  A deprecation
&gt; date has been provided in most places, to help POI users prioritize
&gt; clean-up of their own code.
&gt; 
&gt; 
&gt; You mentioned the comment from the the first line of the deprecated method:
&gt;         int ushortCellNum = cellnum &amp; 0x0000FFFF; // avoid sign extension
&gt; The bit-mask is correct for 16-bit unsigned conversion.  Masking with
&gt; 0xFF would be wrong because it would silently convert every possible
&gt; input to a valid column index.  For example: is it sensible for
&gt; "getCell((short)300)" to succeed?   Maybe it looks pointless to
&gt; convert values in the range (-32768...-1) to (32768...65535) is
&gt; because the maximum column index is 255.  This conversion to unsigned
&gt; 16-bit has been done because it's more likely that the caller intends
&gt; an unsigned quantity (column indexes are never negative).  So if a
&gt; negative value *does* get into this method, it's probably better to
&gt; format the error message in terms of the unsigned 16 bit quantity.
&gt; Similar results could have been achieved with bounds checking the
&gt; argument, but would involve duplicating all the MissingCellPolicy
&gt; logic too.
&gt; So - that line of code is there for making better error messages, and
&gt; has little to do with the reasons for the  deprecation.
&gt; 
&gt; regards,
&gt; Josh
&gt; 
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt; 
&gt; 

--- original message end ----


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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: HSSFCell short/int</title>
<author><name>Josh Micich &lt;josh.micich@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3ca644352c0912021127u49c3a3c0rb54bfd949f023212@mail.gmail.com%3e"/>
<id>urn:uuid:%3ca644352c0912021127u49c3a3c0rb54bfd949f023212@mail-gmail-com%3e</id>
<updated>2009-12-02T19:27:06Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hello Dave,

It's not clear if you are questioning the merit of creating the newer
method "getCell(int)", or whether the old method "getCell(short)"
should have been deprecated at all, so I'll attempt to answer both
concerns.


The most visible reason why POI is moving away from bytes and shorts
is the need for typecasts when using literal integer constants, even
when the value is quite obviously within range.  For example without
the new method "row.getCell(5)" would not compile.  We would have to
write "row.getCell((short)5)".

There have been several POI bugs involving representation of unsigned
(ushort, ubyte) quantities with java datatypes (signed) of the same
width (short, byte).  When shorts and bytes are used, the corrected
code generally needs more typecasts and bit mask expressions.   If
those datatypes are changed to int, the code is usually simpler and
easier to read.

The new method "getCell(int) method may in the first place have been
introduced as a result of the XSSF common interface work (a separate
reason, as suggested by Mark B).


That sort-of explains the rationale for creating the new method
"getCell(int)".   The reason for deprecating the old is to eliminate
overloading (of "getCell").  Method overloading is sometimes very
handy but has quite a few pitfalls, and for that reason POI tries to
use overloading sparingly.

As far as the exact meaning of the '@deprecated' tag, in POI (unlike
in the java runtime library) it means "This method will be removed in
a future POI version".  An alternative is always given.  A deprecation
date has been provided in most places, to help POI users prioritize
clean-up of their own code.


You mentioned the comment from the the first line of the deprecated method:
        int ushortCellNum = cellnum &amp; 0x0000FFFF; // avoid sign extension
The bit-mask is correct for 16-bit unsigned conversion.  Masking with
0xFF would be wrong because it would silently convert every possible
input to a valid column index.  For example: is it sensible for
"getCell((short)300)" to succeed?   Maybe it looks pointless to
convert values in the range (-32768...-1) to (32768...65535) is
because the maximum column index is 255.  This conversion to unsigned
16-bit has been done because it's more likely that the caller intends
an unsigned quantity (column indexes are never negative).  So if a
negative value *does* get into this method, it's probably better to
format the error message in terms of the unsigned 16 bit quantity.
Similar results could have been achieved with bounds checking the
argument, but would involve duplicating all the MissingCellPolicy
logic too.
So - that line of code is there for making better error messages, and
has little to do with the reasons for the  deprecation.

regards,
Josh

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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: HSSFCell short/int</title>
<author><name>MSB &lt;markbrdsly@tiscali.co.uk&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c26612088.post@talk.nabble.com%3e"/>
<id>urn:uuid:%3c26612088-post@talk-nabble-com%3e</id>
<updated>2009-12-02T16:42:48Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

I am only guessing David but the change my be the result of introducing the
SS model to accomodate both the binary and OpenXML based file formats
'invisibly'. If you look at the org.apache.poi.ss.usermodel package, you
will find there are classes called Workbook, Sheet, Cell, etc and these are
used by those who may have to work with both types of file format and do not
want to maintain two different code bases. Well, both HSSFCell and XSSFCell
both implement the Cell interface and I would guess that the decision was
taken to include just the single method getCell(int) in the interface and -
as a result - both concrete classes because the OpenXML file format does not
impose the 256 row limit on the user.

As I said, this is only a guess.

Yours

Mark B


David Law-2 wrote:
&gt; 
&gt; Could it be, the HSSFCell getCell(short cellnum)
&gt; method has been rather confusingly deprecated?
&gt; 
&gt; Arguably, its laudable to "avoid sign extension",
&gt; but as there can only be 256 columns anyway,
&gt; I find it really rather misleading.
&gt; 
&gt; Regards,
&gt; DaveLaw
&gt; 
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://old.nabble.com/HSSFCell-short-int-tp26607785p26612088.html
Sent from the POI - User mailing list archive at Nabble.com.


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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Determine version of excel file</title>
<author><name>MSB &lt;markbrdsly@tiscali.co.uk&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c26611959.post@talk.nabble.com%3e"/>
<id>urn:uuid:%3c26611959-post@talk-nabble-com%3e</id>
<updated>2009-12-02T16:36:28Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Hello again,

If you code to the 'SS' model then you will not need to check the type
returned by the WorkbookFactory at all. By this. I mean that you will use
objects from the org.apache.poi.ss.usermodel package such as Workbook, Sheet
and Cell in your program. That way, you need have no concerns at all about
the actual type - and therefore the file format - that you are dealing with.
Before deciding to move your code in this direction however, it would be
wise to look closely at the methods defined on the various interfaces just
to make sure that you can accomplish everything you require. Just as am
example, on HSSFSheet you can add a data validation whuilst this methgod has
not yet been declared within the Sheet interface. Should you need to
extended functionality then of course you can just test the type returned to
you by the WorkbookFactory and then 'direct' program flow accordingly.

Yours

Mark B

PS Sorry again for that 'just open the file and look at the header' bit this
morning. I was over-excited about the work we had on today and seriously
deprived of tea at that moment. Hope you did not waste any time pursuing
that fruitless/pointless direction.


Sparecreative wrote:
&gt; 
&gt; Thanks Mark,
&gt; 
&gt; That’s exactly what I was after. And, just so I’m clear, with the Workbook
&gt; factory, I just check if the Workbook is an instance of either HSSF or
&gt; XSSF
&gt; and process accordingly.
&gt; 
&gt; On a related topic it would be great if the specifics for the two event
&gt; based readers (for HSSF and XSSF) could be abstracted away so the we could
&gt; use one set of methods regardless of the document type. Much like the user
&gt; model.
&gt; 
&gt; Z.
&gt;&gt; 
&gt;&gt; So, to be clear, all you want to do is identify which files use the
&gt;&gt; OpenXML
&gt;&gt; file format and which are binary?
&gt;&gt; 
&gt;&gt; If so, then take a look at the
&gt;&gt; org.apache.poi.ss.usermodel.WorkbookFactory
&gt;&gt; (http://poi.eu.apache.org/apidocs/org/apache/poi/ss/usermodel/WorkbookFactory.
&gt;&gt; html)
&gt;&gt; class. All you need to do is call the static create method pasing an
&gt;&gt; InputStream and you will receive back an instance of either the HSSF or
&gt;&gt; XSSFWorkbook class depending upon the type of the file. Myself, I have
&gt;&gt; never
&gt;&gt; tried using it with files that lack extensions but it ought to work and I
&gt;&gt; would certainly suggest giving it a try. Alternatively, you can simply
&gt;&gt; catch
&gt;&gt; exceptions; i.e. try to open the file as an HSSFWorkbook, catch the
&gt;&gt; exception if the format is not correct and try to open it as an
&gt;&gt; XSSFWorkbook
&gt;&gt; then catch and handle the exception thrown if the format is again
&gt;&gt; invalid.
&gt;&gt; Finally, you could open an InputStream onto the file and examine the
&gt;&gt; first
&gt;&gt; few bytes - I think it is safe to assume that the xml header would be the
&gt;&gt; first thing you read from an OpenXML based file.
&gt;&gt; 
&gt;&gt; Yours
&gt;&gt; 
&gt;&gt; Mark B
&gt;&gt; 
&gt;&gt; 
&gt;&gt; Sparecreative wrote:
&gt;&gt;&gt; &gt; 
&gt;&gt;&gt; &gt; We¹re currently successfully using poi in a webapp to read from
&gt;&gt;&gt; uploaded
&gt;&gt;&gt; &gt; excel files.
&gt;&gt;&gt; &gt; 
&gt;&gt;&gt; &gt; At present we do a check on the filename extension. If xls we use HSSF
&gt;&gt;&gt; and
&gt;&gt;&gt; &gt; if xslx we use XSSF and this is working reasonably well.
&gt;&gt;&gt; &gt; 
&gt;&gt;&gt; &gt; The problem we have is that some of our users are uploading files with
&gt;&gt;&gt; no
&gt;&gt;&gt; &gt; extension. Is there a way to determine the type of excel file that we
&gt;&gt;&gt; are
&gt;&gt;&gt; &gt; dealing with programmatically?
&gt;&gt;&gt; &gt; 
&gt;&gt;&gt; &gt; I¹d appreciate any pointers as I haven¹t had a lot of luck finding
&gt;&gt;&gt; &gt; anything
&gt;&gt;&gt; &gt; on the web.
&gt;&gt;&gt; &gt; 
&gt;&gt;&gt; &gt; Z.
&gt;&gt;&gt; &gt; 
&gt;&gt;&gt; &gt; 
&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://old.nabble.com/Determine-version-of-excel-file-tp26603831p26611959.html
Sent from the POI - User mailing list archive at Nabble.com.


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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Determine version of excel file</title>
<author><name>MSB &lt;markbrdsly@tiscali.co.uk&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c26611823.post@talk.nabble.com%3e"/>
<id>urn:uuid:%3c26611823-post@talk-nabble-com%3e</id>
<updated>2009-12-02T16:27:57Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Thanks for that Chris. I realised what I had said just as we pulled onto site
this morning and have spent hours today calling myself all of the names
under the sun and bewailing (good word) the fact that I could not get to a
PC!! Of course you are correct, the xml is zipped so there will be no xml
header at the start of the file. That will teach me to show off before I
have had two cups of tea in the morning; my apologies to all.

Yours

Mark B


ChrisLott wrote:
&gt; 
&gt; MSB wrote:
&gt;&gt; ..
&gt;&gt; Finally, you could open an InputStream onto the file and examine the
&gt;&gt; first
&gt;&gt; few bytes - I think it is safe to assume that the xml header would be the
&gt;&gt; first thing you read from an OpenXML based file.
&gt; 
&gt; Goodness, no!  :-)  An xlsx file (like a docx file and I suppose a pptx 
&gt; file) is actually a zip archive.  Try opening it with winzip or your 
&gt; favorite zip-file reader and you'll see ("zip -T sheet.xlsx").  Inside 
&gt; you'll see XML files, each of which should have a nice XML header.  I 
&gt; suppose you could reimplement the magic-number check for a zip file done 
&gt; by a unix/linux machine's "file" program, maybe that's what POI's 
&gt; WorkbookFactory does under the covers.
&gt; 
&gt; chris...
&gt; 
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://old.nabble.com/Determine-version-of-excel-file-tp26603831p26611823.html
Sent from the POI - User mailing list archive at Nabble.com.


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



</pre>
</div>
</content>
</entry>
<entry>
<title>HSSFCell short/int</title>
<author><name>&quot;David Law&quot; &lt;david.law@apconsult.de&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c200912021201.nB2C1qJa012274@post.webmailer.de%3e"/>
<id>urn:uuid:%3c200912021201-nB2C1qJa012274@post-webmailer-de%3e</id>
<updated>2009-12-02T12:01:52Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Could it be, the HSSFCell getCell(short cellnum)
method has been rather confusingly deprecated?

Arguably, its laudable to "avoid sign extension",
but as there can only be 256 columns anyway,
I find it really rather misleading.

Regards,
DaveLaw

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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: New hera</title>
<author><name>Mark Davidson &lt;ukdavo@googlemail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3cee2b95370912020337ve088c86n1aa66506512f7b09@mail.gmail.com%3e"/>
<id>urn:uuid:%3cee2b95370912020337ve088c86n1aa66506512f7b09@mail-gmail-com%3e</id>
<updated>2009-12-02T11:37:16Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
I'm very new too. I found a lot of good information on the POI website (
http://poi.eu.apache.org/) and in the examples and unit tests that you get
in the source distribution.

Regards

Mark

2009/12/2 Emeka &lt;emekamicro@gmail.com&gt;

&gt; Hello All,
&gt;
&gt; I am pretty new here, and would like to know where I can get good tutorials
&gt; and other relevant materials to get started.
&gt;
&gt; Regards,
&gt; Janus
&gt;


</pre>
</div>
</content>
</entry>
<entry>
<title>New hera</title>
<author><name>Emeka &lt;emekamicro@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c89c38c820912020301r618d8364ie7e9af4a1fb29b69@mail.gmail.com%3e"/>
<id>urn:uuid:%3c89c38c820912020301r618d8364ie7e9af4a1fb29b69@mail-gmail-com%3e</id>
<updated>2009-12-02T11:01:54Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hello All,

I am pretty new here, and would like to know where I can get good tutorials
and other relevant materials to get started.

Regards,
Janus


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Determine version of excel file</title>
<author><name>Chris Lott &lt;mail09@invest-faq.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c4B1643E1.8090209@invest-faq.com%3e"/>
<id>urn:uuid:%3c4B1643E1-8090209@invest-faq-com%3e</id>
<updated>2009-12-02T10:39:29Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
MSB wrote:
&gt; ..
&gt; Finally, you could open an InputStream onto the file and examine the first
&gt; few bytes - I think it is safe to assume that the xml header would be the
&gt; first thing you read from an OpenXML based file.

Goodness, no!  :-)  An xlsx file (like a docx file and I suppose a pptx 
file) is actually a zip archive.  Try opening it with winzip or your 
favorite zip-file reader and you'll see ("zip -T sheet.xlsx").  Inside 
you'll see XML files, each of which should have a nice XML header.  I 
suppose you could reimplement the magic-number check for a zip file done 
by a unix/linux machine's "file" program, maybe that's what POI's 
WorkbookFactory does under the covers.

chris...

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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Determine version of excel file</title>
<author><name>Zoran Avtarovski &lt;zoran@sparecreative.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3cC73C85FA.C8A0D%25zoran@sparecreative.com%3e"/>
<id>urn:uuid:%3cC73C85FA-C8A0D%25zoran@sparecreative-com%3e</id>
<updated>2009-12-02T10:00:42Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Content-type: text/plain;
	charset="EUC-KR"
Content-transfer-encoding: quoted-printable

Thanks Mark,

That=A1=AFs exactly what I was after. And, just so I=A1=AFm clear, with the Workboo=
k
factory, I just check if the Workbook is an instance of either HSSF or XSSF
and process accordingly.

On a related topic it would be great if the specifics for the two event
based readers (for HSSF and XSSF) could be abstracted away so the we could
use one set of methods regardless of the document type. Much like the user
model.

Z.
&gt;=20
&gt; So, to be clear, all you want to do is identify which files use the OpenX=
ML
&gt; file format and which are binary?
&gt;=20
&gt; If so, then take a look at the org.apache.poi.ss.usermodel.WorkbookFactor=
y
&gt; (http://poi.eu.apache.org/apidocs/org/apache/poi/ss/usermodel/WorkbookFac=
tory.
&gt; html)
&gt; class. All you need to do is call the static create method pasing an
&gt; InputStream and you will receive back an instance of either the HSSF or
&gt; XSSFWorkbook class depending upon the type of the file. Myself, I have ne=
ver
&gt; tried using it with files that lack extensions but it ought to work and I
&gt; would certainly suggest giving it a try. Alternatively, you can simply ca=
tch
&gt; exceptions; i.e. try to open the file as an HSSFWorkbook, catch the
&gt; exception if the format is not correct and try to open it as an XSSFWorkb=
ook
&gt; then catch and handle the exception thrown if the format is again invalid=
.
&gt; Finally, you could open an InputStream onto the file and examine the firs=
t
&gt; few bytes - I think it is safe to assume that the xml header would be the
&gt; first thing you read from an OpenXML based file.
&gt;=20
&gt; Yours
&gt;=20
&gt; Mark B
&gt;=20
&gt;=20
&gt; Sparecreative wrote:
&gt;&gt; &gt;=20
&gt;&gt; &gt; We=A9=F6re currently successfully using poi in a webapp to read from uploa=
ded
&gt;&gt; &gt; excel files.
&gt;&gt; &gt;=20
&gt;&gt; &gt; At present we do a check on the filename extension. If xls we use HSSF=
 and
&gt;&gt; &gt; if xslx we use XSSF and this is working reasonably well.
&gt;&gt; &gt;=20
&gt;&gt; &gt; The problem we have is that some of our users are uploading files with=
 no
&gt;&gt; &gt; extension. Is there a way to determine the type of excel file that we =
are
&gt;&gt; &gt; dealing with programmatically?
&gt;&gt; &gt;=20
&gt;&gt; &gt; I=A9=F6d appreciate any pointers as I haven=A9=F6t had a lot of luck finding
&gt;&gt; &gt; anything
&gt;&gt; &gt; on the web.
&gt;&gt; &gt;=20
&gt;&gt; &gt; Z.
&gt;&gt; &gt;=20
&gt;&gt; &gt;=20



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Determine version of excel file</title>
<author><name>MSB &lt;markbrdsly@tiscali.co.uk&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c26604556.post@talk.nabble.com%3e"/>
<id>urn:uuid:%3c26604556-post@talk-nabble-com%3e</id>
<updated>2009-12-02T07:17:40Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

So, to be clear, all you want to do is identify which files use the OpenXML
file format and which are binary?

If so, then take a look at the org.apache.poi.ss.usermodel.WorkbookFactory
(http://poi.eu.apache.org/apidocs/org/apache/poi/ss/usermodel/WorkbookFactory.html)
class. All you need to do is call the static create method pasing an
InputStream and you will receive back an instance of either the HSSF or
XSSFWorkbook class depending upon the type of the file. Myself, I have never
tried using it with files that lack extensions but it ought to work and I
would certainly suggest giving it a try. Alternatively, you can simply catch
exceptions; i.e. try to open the file as an HSSFWorkbook, catch the
exception if the format is not correct and try to open it as an XSSFWorkbook
then catch and handle the exception thrown if the format is again invalid.
Finally, you could open an InputStream onto the file and examine the first
few bytes - I think it is safe to assume that the xml header would be the
first thing you read from an OpenXML based file.

Yours

Mark B


Sparecreative wrote:
&gt; 
&gt; We¹re currently successfully using poi in a webapp to read from uploaded
&gt; excel files.
&gt; 
&gt; At present we do a check on the filename extension. If xls we use HSSF and
&gt; if xslx we use XSSF and this is working reasonably well.
&gt; 
&gt; The problem we have is that some of our users are uploading files with no
&gt; extension. Is there a way to determine the type of excel file that we are
&gt; dealing with programmatically?
&gt; 
&gt; I¹d appreciate any pointers as I haven¹t had a lot of luck finding
&gt; anything
&gt; on the web.
&gt; 
&gt; Z.
&gt; 
&gt; 

-- 
View this message in context: http://old.nabble.com/Determine-version-of-excel-file-tp26603831p26604556.html
Sent from the POI - User mailing list archive at Nabble.com.


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



</pre>
</div>
</content>
</entry>
<entry>
<title>Determine version of excel file</title>
<author><name>Zoran Avtarovski &lt;zoran@sparecreative.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3cC73C476D.C89E3%25zoran@sparecreative.com%3e"/>
<id>urn:uuid:%3cC73C476D-C89E3%25zoran@sparecreative-com%3e</id>
<updated>2009-12-02T05:33:49Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Content-type: text/plain;
	charset="ISO-8859-1"
Content-transfer-encoding: quoted-printable

We=B9re currently successfully using poi in a webapp to read from uploaded
excel files.

At present we do a check on the filename extension. If xls we use HSSF and
if xslx we use XSSF and this is working reasonably well.

The problem we have is that some of our users are uploading files with no
extension. Is there a way to determine the type of excel file that we are
dealing with programmatically?

I=B9d appreciate any pointers as I haven=B9t had a lot of luck finding anything
on the web.

Z.


</pre>
</div>
</content>
</entry>
<entry>
<title>XSSFCellStyle.setRotation() doesn't work right with negative values</title>
<author><name>&quot;Erick Lichtas&quot; &lt;elichtas@linoma.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c000101ca72f5$cf193490$6d4b9db0$@com%3e"/>
<id>urn:uuid:%3c000101ca72f5$cf193490$6d4b9db0$@com%3e</id>
<updated>2009-12-02T02:18:56Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi all,

 

It appears that setting the rotation on an XSSFCellStyle works fine with
positive short values, but doesn't work with negative values (mainly testing
-45 and -90).  

 

I ran the same tests to write a 2003 document using an HSSFCellStyle and the
negative rotations appear accurately in the resulting spreadsheet.  So my
guess is there is a bug with this setting in XSSF.

 

I am using the latest nightly build from today (20091201) for this test:

 

poi-3.6-beta1-20091201.jar

poi-ooxml-3.6-beta1-20091201.jar

 

Can anyone else confirm this behavior as a bug?

 

Thanks,

 

Erick Lichtas

 

 &lt;http://www.linomasoftware.com/&gt; Linoma-Software-Logo

1409 Silver Street, Ashland, NE 68003

1-800-949-4696 x714

 



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: INDIRECT function</title>
<author><name>Adrian Butnaru &lt;ambutnaru@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c4B1563EB.5050606@gmail.com%3e"/>
<id>urn:uuid:%3c4B1563EB-5050606@gmail-com%3e</id>
<updated>2009-12-01T18:43:55Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Thanks everybody,
During all my tests I had an old poi in the jre directory of the jdk I 
am actually using.
I am programming now with Netbeans and I thought my settings there will 
be enough, but it looks the old settings in jre were overwriting the new 
ones.

Thanks again to everybody!


Hannes Erven schreef:
&gt;&gt; Strange enough this is the output:
&gt;&gt; file:/C:/Program%20Files/Java/jdk1.6.0_03/jre/lib/ext/poi-3.5-beta4-20081128/
&gt;&gt; but this path is not existing!
&gt;&gt;     
&gt;
&gt; In any case, it seems you have some older POI version somewhere in your
&gt; classpath. Have you double-checked your classpath settings? How do you
&gt; invoke the program in question?
&gt;
&gt; -hannes
&gt;
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt;
&gt;
&gt;   


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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: INDIRECT function</title>
<author><name>Hannes Erven &lt;h.e@gmx.at&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c4B155F07.6000704@gmx.at%3e"/>
<id>urn:uuid:%3c4B155F07-6000704@gmx-at%3e</id>
<updated>2009-12-01T18:23:03Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

&gt; Strange enough this is the output:
&gt; file:/C:/Program%20Files/Java/jdk1.6.0_03/jre/lib/ext/poi-3.5-beta4-20081128/
&gt; but this path is not existing!

In any case, it seems you have some older POI version somewhere in your
classpath. Have you double-checked your classpath settings? How do you
invoke the program in question?

-hannes

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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: INDIRECT function</title>
<author><name>Adrian Butnaru &lt;ambutnaru@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c4B155DE8.80505@gmail.com%3e"/>
<id>urn:uuid:%3c4B155DE8-80505@gmail-com%3e</id>
<updated>2009-12-01T18:18:16Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Strange enough this is the output:

file:/C:/Program%20Files/Java/jdk1.6.0_03/jre/lib/ext/poi-3.5-beta4-20081128/

but this path is not existing!



Yegor Kozlov schreef:
&gt; Execute the following code:
&gt;
&gt;         URL url = 
&gt; HSSFWorkbook.class.getProtectionDomain().getCodeSource().getLocation();
&gt;         System.out.println(url);
&gt;
&gt; it will print the path to the POI jar.
&gt;
&gt; nightly builds can be downloaded from 
&gt; http://encore.torchbox.com/poi-svn-build/
&gt;
&gt; Yegor
&gt;
&gt;&gt; Your prediction is good.
&gt;&gt;
&gt;&gt; This was the output:
&gt;&gt; Wrong result type - got 5errCode=-30
&gt;&gt; But how can I get rhe newest poi jar file?
&gt;&gt; I downloaded the one I am using
&gt;&gt;
&gt;&gt; POI-3.5-FINAL-20090928.jar
&gt;&gt;
&gt;&gt; from POI website.
&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt;&gt; Josh Micich schreef:
&gt;&gt;&gt;&gt; I am using POI-3.5-FINAL-20090928.jar.
&gt;&gt;&gt;&gt;     
&gt;&gt;&gt; There's a high chance you're not.
&gt;&gt;&gt;
&gt;&gt;&gt; You can also dump the error code to help diagnose the problem.
&gt;&gt;&gt; Change this line:
&gt;&gt;&gt; System.err.println("Wrong result type - got " + cv.getCellType() + "
&gt;&gt;&gt; errCode=" + cv.getErrorValue());
&gt;&gt;&gt;
&gt;&gt;&gt; I predict the error code will be -30.  Which will mean you are using a
&gt;&gt;&gt; version of POI prior to 3.5-beta4
&gt;&gt;&gt;
&gt;&gt;&gt; If I am mistaken, another thing you can try is to put a breakpoint in
&gt;&gt;&gt; Indirect.java:76, to confirm whether execution gets there.  You can
&gt;&gt;&gt; also look around the variables in the stack frame which might help
&gt;&gt;&gt; explain what is going wrong.
&gt;&gt;&gt;
&gt;&gt;&gt; ---------------------------------------------------------------------
&gt;&gt;&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt;&gt;&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;   
&gt;&gt;
&gt;&gt;
&gt;&gt; ---------------------------------------------------------------------
&gt;&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt;&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt;&gt;
&gt;&gt;
&gt;
&gt;
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt;
&gt;


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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: INDIRECT function</title>
<author><name>Yegor Kozlov &lt;yegor@dinom.ru&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c4B1559CF.7020500@dinom.ru%3e"/>
<id>urn:uuid:%3c4B1559CF-7020500@dinom-ru%3e</id>
<updated>2009-12-01T18:00:47Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Execute the following code:

         URL url = HSSFWorkbook.class.getProtectionDomain().getCodeSource().getLocation();
         System.out.println(url);

it will print the path to the POI jar.

nightly builds can be downloaded from http://encore.torchbox.com/poi-svn-build/

Yegor

&gt; Your prediction is good.
&gt; 
&gt; This was the output:
&gt; Wrong result type - got 5errCode=-30
&gt; But how can I get rhe newest poi jar file?
&gt; I downloaded the one I am using
&gt; 
&gt; POI-3.5-FINAL-20090928.jar
&gt; 
&gt; from POI website.
&gt; 
&gt; 
&gt; 
&gt; 
&gt; Josh Micich schreef:
&gt;&gt;&gt; I am using POI-3.5-FINAL-20090928.jar.
&gt;&gt;&gt;     
&gt;&gt; There's a high chance you're not.
&gt;&gt;
&gt;&gt; You can also dump the error code to help diagnose the problem.
&gt;&gt; Change this line:
&gt;&gt; System.err.println("Wrong result type - got " + cv.getCellType() + "
&gt;&gt; errCode=" + cv.getErrorValue());
&gt;&gt;
&gt;&gt; I predict the error code will be -30.  Which will mean you are using a
&gt;&gt; version of POI prior to 3.5-beta4
&gt;&gt;
&gt;&gt; If I am mistaken, another thing you can try is to put a breakpoint in
&gt;&gt; Indirect.java:76, to confirm whether execution gets there.  You can
&gt;&gt; also look around the variables in the stack frame which might help
&gt;&gt; explain what is going wrong.
&gt;&gt;
&gt;&gt; ---------------------------------------------------------------------
&gt;&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt;&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt;&gt;
&gt;&gt;
&gt;&gt;   
&gt; 
&gt; 
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt; 
&gt; 


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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: INDIRECT function</title>
<author><name>Adrian Butnaru &lt;ambutnaru@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c4B1555C0.1030403@gmail.com%3e"/>
<id>urn:uuid:%3c4B1555C0-1030403@gmail-com%3e</id>
<updated>2009-12-01T17:43:28Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Your prediction is good.

This was the output:
Wrong result type - got 5errCode=-30
But how can I get rhe newest poi jar file?
I downloaded the one I am using

POI-3.5-FINAL-20090928.jar

from POI website.




Josh Micich schreef:
&gt;&gt; I am using POI-3.5-FINAL-20090928.jar.
&gt;&gt;     
&gt; There's a high chance you're not.
&gt;
&gt; You can also dump the error code to help diagnose the problem.
&gt; Change this line:
&gt; System.err.println("Wrong result type - got " + cv.getCellType() + "
&gt; errCode=" + cv.getErrorValue());
&gt;
&gt; I predict the error code will be -30.  Which will mean you are using a
&gt; version of POI prior to 3.5-beta4
&gt;
&gt; If I am mistaken, another thing you can try is to put a breakpoint in
&gt; Indirect.java:76, to confirm whether execution gets there.  You can
&gt; also look around the variables in the stack frame which might help
&gt; explain what is going wrong.
&gt;
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt;
&gt;
&gt;   


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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: INDIRECT function</title>
<author><name>Josh Micich &lt;josh.micich@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3ca644352c0912010027r725c0b4djb297a4dab42922b6@mail.gmail.com%3e"/>
<id>urn:uuid:%3ca644352c0912010027r725c0b4djb297a4dab42922b6@mail-gmail-com%3e</id>
<updated>2009-12-01T08:27:31Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
&gt; I am using POI-3.5-FINAL-20090928.jar.
There's a high chance you're not.

You can also dump the error code to help diagnose the problem.
Change this line:
System.err.println("Wrong result type - got " + cv.getCellType() + "
errCode=" + cv.getErrorValue());

I predict the error code will be -30.  Which will mean you are using a
version of POI prior to 3.5-beta4

If I am mistaken, another thing you can try is to put a breakpoint in
Indirect.java:76, to confirm whether execution gets there.  You can
also look around the variables in the stack frame which might help
explain what is going wrong.

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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: INDIRECT function</title>
<author><name>Adrian Butnaru &lt;ambutnaru@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3c4B14D1DA.90907@gmail.com%3e"/>
<id>urn:uuid:%3c4B14D1DA-90907@gmail-com%3e</id>
<updated>2009-12-01T08:20:42Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi,
I am using POI-3.5-FINAL-20090928.jar.

I changed my code as follows:

public static void main(String[] args) throws IOException {
    HSSFWorkbook wbAA = new HSSFWorkbook(new 
FileInputStream("D:/Book1.xls"));
        wbAA.getSheetAt(0).getRow(1).getCell(0).setCellValue("Sheet2");
        HSSFFormulaEvaluator evalAA = new HSSFFormulaEvaluator(wbAA);
        CellValue cv = 
evalAA.evaluate(wbAA.getSheetAt(0).getRow(3).getCell(0));
        evalAA.clearAllCachedResultValues();
        if (cv.getCellType() != Cell.CELL_TYPE_NUMERIC) {
        System.err.println("Wrong result type - got " + cv.getCellType());
        return;
    }
        System.err.println("Cell A4=" +cv.getNumberValue());
    }

and I get:

Wrong result type - got 5
This means formula error. So INDIRECT is not evaluated corectly. Why?
I really need to make this working. What should I do?

Thanks,
Adrian



Josh Micich schreef:
&gt; You are probably still running a very old version of POI. In those
&gt; versions it was  best practice to check the cell type of the
&gt; evaluation result (rather than just assume CELL_TYPE_NUMERIC).  You
&gt; are probably getting CELL_TYPE_ERROR due to INDIRECT not being
&gt; implemented in your version of POI.  Make a small change to your test
&gt; code to see:
&gt;
&gt; ----------------
&gt; public static void main(String[] args) throws IOException {
&gt; 	HSSFWorkbook wbA = new HSSFWorkbook(new
&gt; FileInputStream("c:/josh/temp/Book1.xls"));
&gt; 	wbA.getSheetAt(0).getRow(1).getCell(0).setCellValue("Sheet2");
&gt; 	HSSFFormulaEvaluator evalA = new HSSFFormulaEvaluator(wbA);
&gt; 	CellValue cv = evalA.evaluate(wbA.getSheetAt(0).getRow(3).getCell(0));
&gt; 	if (cv.getCellType() != Cell.CELL_TYPE_NUMERIC) {
&gt; 		System.err.println("Wrong result type - got " + cv.getCellType());
&gt; 		return;
&gt; 	}
&gt; 	System.err.println("Cell A4=" + cv.getNumberValue());
&gt;   }
&gt; --------------
&gt;
&gt; This change is not required if you are running anything newer than
&gt; version 3.5-beta4.  Since then unimplemented functions cause
&gt; NotImplementedException to be thrown
&gt;
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt;
&gt;
&gt;   


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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: INDIRECT function</title>
<author><name>Josh Micich &lt;josh.micich@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200912.mbox/%3ca644352c0911301856u3477a281n9f8c0fb06c87963b@mail.gmail.com%3e"/>
<id>urn:uuid:%3ca644352c0911301856u3477a281n9f8c0fb06c87963b@mail-gmail-com%3e</id>
<updated>2009-12-01T02:56:05Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
You are probably still running a very old version of POI. In those
versions it was  best practice to check the cell type of the
evaluation result (rather than just assume CELL_TYPE_NUMERIC).  You
are probably getting CELL_TYPE_ERROR due to INDIRECT not being
implemented in your version of POI.  Make a small change to your test
code to see:

----------------
public static void main(String[] args) throws IOException {
	HSSFWorkbook wbA = new HSSFWorkbook(new
FileInputStream("c:/josh/temp/Book1.xls"));
	wbA.getSheetAt(0).getRow(1).getCell(0).setCellValue("Sheet2");
	HSSFFormulaEvaluator evalA = new HSSFFormulaEvaluator(wbA);
	CellValue cv = evalA.evaluate(wbA.getSheetAt(0).getRow(3).getCell(0));
	if (cv.getCellType() != Cell.CELL_TYPE_NUMERIC) {
		System.err.println("Wrong result type - got " + cv.getCellType());
		return;
	}
	System.err.println("Cell A4=" + cv.getNumberValue());
  }
--------------

This change is not required if you are running anything newer than
version 3.5-beta4.  Since then unimplemented functions cause
NotImplementedException to be thrown

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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: INDIRECT function</title>
<author><name>Adrian Butnaru &lt;ambutnaru@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200911.mbox/%3c4B1424E2.4030703@gmail.com%3e"/>
<id>urn:uuid:%3c4B1424E2-4030703@gmail-com%3e</id>
<updated>2009-11-30T20:02:42Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
On my computer does not work!
I restricted the code to:
public static void main(String[] args) throws IOException {
    HSSFWorkbook wbAA = new HSSFWorkbook(new 
FileInputStream("D:/Book1.xls"));
        wbAA.getSheetAt(0).getRow(1).getCell(0).setCellValue("Sheet2");
        HSSFFormulaEvaluator evalAA = new HSSFFormulaEvaluator(wbAA);
        System.err.println("Cell A4=" 
+evalAA.evaluate(wbAA.getSheetAt(0).getRow(3).getCell(0)).getNumberValue());
    }
and the output is:

run:
Cell A4=0.0
BUILD SUCCESSFUL (total time: 1 second)

Regards,
Adrian

Josh Micich schreef:
&gt; I modified your code just slightly to get it to compile and it seems
&gt; to run OK, producing your expected result (100.0).
&gt; The output is: Cell A4=100.0
&gt;
&gt;
&gt; Here is the modified code - please check it to make sure I didn't do
&gt; anything crazy
&gt; ---------------
&gt; public static void main(String[] args) throws IOException {
&gt; 	HSSFWorkbook wbA = new HSSFWorkbook(new FileInputStream("D:/Book1.xls"));
&gt; 	wbA.getSheetAt(0).getRow(1).getCell(0).setCellValue("Sheet2");
&gt; 	HSSFFormulaEvaluator evalA = (HSSFFormulaEvaluator)
&gt; wbA.getCreationHelper().createFormulaEvaluator();
&gt; 	evalA.evaluateFormulaCell(wbA.getSheetAt(0).getRow(3).getCell(0));
&gt; 	printCell(wbA, evalA, 0, "A4");
&gt; }
&gt;
&gt; private static void printCell(HSSFWorkbook wbA, HSSFFormulaEvaluator
&gt; evalA, int sheet, String str) {
&gt; 	CellReference cellReference = new CellReference(str);
&gt; 	Row row = wbA.getSheetAt(sheet).getRow(cellReference.getRow());
&gt; 	Cell cell = row.getCell(cellReference.getCol());
&gt; 	evalA.clearAllCachedResultValues();
&gt; 	evalA.evaluate((HSSFCell) cell);
&gt; 	System.err.println("Cell " + str + "=" +
&gt; evalA.evaluate(cell).getNumberValue());
&gt; }	
&gt; ------------------
&gt;
&gt; &gt;From what I can tell, your sample code could be as simple as this:
&gt;
&gt; HSSFWorkbook wbA = new HSSFWorkbook(new
&gt; FileInputStream("c:/josh/temp/Book1.xls"));
&gt; wbA.getSheetAt(0).getRow(1).getCell(0).setCellValue("Sheet2");
&gt; HSSFFormulaEvaluator evalA = new HSSFFormulaEvaluator(wbA);
&gt; System.err.println("Cell A4=" +
&gt; evalA.evaluate(wbA.getSheetAt(0).getRow(3).getCell(0)).getNumberValue());
&gt;
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt;
&gt;
&gt;   


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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: INDIRECT function</title>
<author><name>Josh Micich &lt;josh.micich@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200911.mbox/%3ca644352c0911301138h7aafea04w5ff0f7c98b47459c@mail.gmail.com%3e"/>
<id>urn:uuid:%3ca644352c0911301138h7aafea04w5ff0f7c98b47459c@mail-gmail-com%3e</id>
<updated>2009-11-30T19:38:08Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
I modified your code just slightly to get it to compile and it seems
to run OK, producing your expected result (100.0).
The output is: Cell A4=100.0


Here is the modified code - please check it to make sure I didn't do
anything crazy
---------------
public static void main(String[] args) throws IOException {
	HSSFWorkbook wbA = new HSSFWorkbook(new FileInputStream("D:/Book1.xls"));
	wbA.getSheetAt(0).getRow(1).getCell(0).setCellValue("Sheet2");
	HSSFFormulaEvaluator evalA = (HSSFFormulaEvaluator)
wbA.getCreationHelper().createFormulaEvaluator();
	evalA.evaluateFormulaCell(wbA.getSheetAt(0).getRow(3).getCell(0));
	printCell(wbA, evalA, 0, "A4");
}

private static void printCell(HSSFWorkbook wbA, HSSFFormulaEvaluator
evalA, int sheet, String str) {
	CellReference cellReference = new CellReference(str);
	Row row = wbA.getSheetAt(sheet).getRow(cellReference.getRow());
	Cell cell = row.getCell(cellReference.getCol());
	evalA.clearAllCachedResultValues();
	evalA.evaluate((HSSFCell) cell);
	System.err.println("Cell " + str + "=" +
evalA.evaluate(cell).getNumberValue());
}	
------------------

&gt;From what I can tell, your sample code could be as simple as this:

HSSFWorkbook wbA = new HSSFWorkbook(new
FileInputStream("c:/josh/temp/Book1.xls"));
wbA.getSheetAt(0).getRow(1).getCell(0).setCellValue("Sheet2");
HSSFFormulaEvaluator evalA = new HSSFFormulaEvaluator(wbA);
System.err.println("Cell A4=" +
evalA.evaluate(wbA.getSheetAt(0).getRow(3).getCell(0)).getNumberValue());

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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: INDIRECT function</title>
<author><name>Adrian Butnaru &lt;ambutnaru@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200911.mbox/%3c4B141A33.6000402@gmail.com%3e"/>
<id>urn:uuid:%3c4B141A33-6000402@gmail-com%3e</id>
<updated>2009-11-30T19:17:07Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
This is the a simple code:

public static void main(String[] args) throws IOException {
        wbA = new HSSFWorkbook(new FileInputStream("D:/Book1.xls"));
        wbA.getSheetAt(0).getRow(1).getCell(0).setCellValue("Sheet2");
        evalA = (HSSFFormulaEvaluator) 
wbA.getCreationHelper().createFormulaEvaluator();
        evalA.evaluateFormulaCell(wbA.getSheetAt(0).getRow(3).getCell(0));
        printCell(0,"A4");
    }

    public static void printCell(int sheet, String str)
    {
        CellReference cellReference = new CellReference(str);
        Row row = wbA.getSheetAt(sheet).getRow(cellReference.getRow());
        Cell cell = row.getCell(cellReference.getCol());
        evalA.clearAllCachedResultValues();
        evalA.evaluate((HSSFCell) cell);
        System.err.println("Cell 
"+str+"="+evalA.evaluate(cell).getNumberValue());
    }

And attached is the file.

The output is: Cell A4=0.0

and I expected 100.0

Regards,
Adrian


Josh Micich schreef:
&gt; Evaluation support for INDIRECT() was added recently:
&gt; https://issues.apache.org/bugzilla/show_bug.cgi?id=47721
&gt;
&gt; This happened before 3.5-final.
&gt;
&gt; Please reply with a  your sample code, but most importantly please
&gt; also include the stack trace of your error.
&gt;
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt;
&gt;
&gt;   



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: INDIRECT function</title>
<author><name>Josh Micich &lt;josh.micich@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200911.mbox/%3ca644352c0911301047r14232492q5e2cc3c0ef0bc98a@mail.gmail.com%3e"/>
<id>urn:uuid:%3ca644352c0911301047r14232492q5e2cc3c0ef0bc98a@mail-gmail-com%3e</id>
<updated>2009-11-30T18:47:51Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Evaluation support for INDIRECT() was added recently:
https://issues.apache.org/bugzilla/show_bug.cgi?id=47721

This happened before 3.5-final.

Please reply with a  your sample code, but most importantly please
also include the stack trace of your error.

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



</pre>
</div>
</content>
</entry>
<entry>
<title>INDIRECT function</title>
<author><name>Adrian Butnaru &lt;ambutnaru@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200911.mbox/%3c4B141120.6080605@gmail.com%3e"/>
<id>urn:uuid:%3c4B141120-6080605@gmail-com%3e</id>
<updated>2009-11-30T18:38:24Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi,
I am trying to read a cell of an Excel sheet containing an INDIRECT 
function. The result is always error.
Is INDIRECT function supported in POI 3.5-final?

Regards,
Adrian

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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: XSSFCell.setCellValue(string) always trims leading and trailing white spaces</title>
<author><name>David Fisher &lt;dfisher@jmlafferty.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200911.mbox/%3c5BADAEAF-2320-478B-BAAA-827FDC8B04EB@jmlafferty.com%3e"/>
<id>urn:uuid:%3c5BADAEAF-2320-478B-BAAA-827FDC8B04EB@jmlafferty-com%3e</id>
<updated>2009-11-30T17:15:43Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi,

This bug was fixed about 4 weeks ago. See https://issues.apache.org/bugzilla/show_bug.cgi?id=48070

You will need to get a nightly build or build from trunk yourself.

Regards,
Dave

On Nov 30, 2009, at 9:03 AM, Erick Lichtas wrote:

&gt; Hi all,
&gt;
&gt;
&gt;
&gt; I am currently using POI 3.5 FINAL to write both XLS and XLSX  
&gt; documents. I am noticing that when writing string data a XSSF cell,  
&gt; the data is always trimmed.  The same process when writing to an  
&gt; HSSFCell preserves the leading and trailing spaces.  Is this a bug  
&gt; or the intended behavior?  Is there a way in the current release to  
&gt; preserve these leading and trailing spaces for string data?
&gt;
&gt;
&gt;
&gt; Thanks!
&gt;
&gt;
&gt;
&gt; Erick Lichtas
&gt;
&gt;
&gt;
&gt; &lt;image003.jpg&gt;
&gt;
&gt; 1409 Silver Street, Ashland, NE 68003
&gt;
&gt; 1-800-949-4696 x714
&gt;
&gt;
&gt;
&gt;
&gt;
&gt; __________ Information from ESET NOD32 Antivirus, version of virus  
&gt; signature database 4649 (20091130) __________
&gt;
&gt; The message was checked by ESET NOD32 Antivirus.
&gt;
&gt; http://www.eset.com



</pre>
</div>
</content>
</entry>
<entry>
<title>XSSFCell.setCellValue(string) always trims leading and trailing white spaces</title>
<author><name>&quot;Erick Lichtas&quot; &lt;elichtas@linoma.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200911.mbox/%3c003601ca71df$172cfb30$4586f190$@com%3e"/>
<id>urn:uuid:%3c003601ca71df$172cfb30$4586f190$@com%3e</id>
<updated>2009-11-30T17:03:49Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi all,

 

I am currently using POI 3.5 FINAL to write both XLS and XLSX documents. I
am noticing that when writing string data a XSSF cell, the data is always
trimmed.  The same process when writing to an HSSFCell preserves the leading
and trailing spaces.  Is this a bug or the intended behavior?  Is there a
way in the current release to preserve these leading and trailing spaces for
string data?

 

Thanks!

 

Erick Lichtas

 

 &lt;http://www.linomasoftware.com/&gt; Linoma-Software-Logo

1409 Silver Street, Ashland, NE 68003

1-800-949-4696 x714

 



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: HSSF workbook print setup margins</title>
<author><name>JochenP &lt;jochen@beta9.be&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200911.mbox/%3c26525831.post@talk.nabble.com%3e"/>
<id>urn:uuid:%3c26525831-post@talk-nabble-com%3e</id>
<updated>2009-11-26T11:20:37Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Hi Mark, 

Thank you for your reply. After writing my initial post I started looking at
the use of template files, and it turns out this was the way to go. Every
feature that was requested succeeded and the final report file is great
:jumping:.

Thanks again,

Jochen  


MSB wrote:
&gt; 
&gt; I must admit that I would use a template file to do this because I am not
&gt; aware of any technique that will allow you to insert pictures into the
&gt; footer using POI. Simply create a new Workbook using Excel, set the
&gt; margins as you want them and save it away. All you need to do then is open
&gt; the workbook using POI and populate the sheet(s).
&gt; 
&gt; Just a word of warning - possibly - pictures in headers and footers were
&gt; not supported in versions prior to 2002 - I think. Before that time, you
&gt; have to use a trick to fool Excel into placing the image into a
&gt; hearder/footer and so you risk creating files that may not - and I
&gt; emphasise the may bit - be completely compatible with older versions (e.g.
&gt; Excel 97/2000) of Excel.
&gt; 
&gt; Yours
&gt; 
&gt; Mark B
&gt; 
&gt; 
&gt; JochenP wrote:
&gt;&gt; 
&gt;&gt; Hello,
&gt;&gt; 
&gt;&gt; I currently trying to figure out if it is possible to set the margins of
&gt;&gt; a workbook or excel document.
&gt;&gt; I know there are two methods to set the footer margin and header margin
&gt;&gt; on the PrintSetup class, on every sheet, but these don't seem to help. 
&gt;&gt; 
&gt;&gt; What I need to do is reduce the top, right, bottom and left margin to
&gt;&gt; it's minimum, so more content can be printed on one page. 
&gt;&gt; 
&gt;&gt; I also tried the the autobreaks and fit-width 1, but then I don't have
&gt;&gt; control over the paging which I need.
&gt;&gt; 
&gt;&gt; One thing I also would like to know: Is it possible to add pictures to
&gt;&gt; the footers? 
&gt;&gt; 
&gt;&gt; Or is there an other way, to start from a template excel file and dump my
&gt;&gt; data in a new copy of the template? Has anyone had experience with this?
&gt;&gt; 
&gt;&gt; Kind regards,
&gt;&gt; 
&gt;&gt; Jochen Punie
&gt;&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://old.nabble.com/HSSF-workbook-print-setup-margins-tp26513632p26525831.html
Sent from the POI - User mailing list archive at Nabble.com.


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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: HSSF workbook print setup margins</title>
<author><name>Hannes Erven &lt;h.e@gmx.at&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200911.mbox/%3cheldou$nt3$1@ger.gmane.org%3e"/>
<id>urn:uuid:%3cheldou$nt3$1@ger-gmane-org%3e</id>
<updated>2009-11-26T08:20:46Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
MSB schrieb:
&gt; Simply create a new Workbook using Excel, set the margins
&gt; as you want them and save it away. All you need to do then is open the
&gt; workbook using POI and populate the sheet(s).

And make sure that your master sheet contains at least one cell of data
-- it seems Excel 2003 does not save margins on totally empty sheets.
(YMMV.)


-hannes


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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: HSSF workbook print setup margins</title>
<author><name>MSB &lt;markbrdsly@tiscali.co.uk&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200911.mbox/%3c26525253.post@talk.nabble.com%3e"/>
<id>urn:uuid:%3c26525253-post@talk-nabble-com%3e</id>
<updated>2009-11-26T07:38:14Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

I must admit that I would use a template file to do this because I am not
aware of any technique that will allow you to insert pictures into the
footer using POI. Simply create a new Workbook using Excel, set the margins
as you want them and save it away. All you need to do then is open the
workbook using POI and populate the sheet(s).

Just a word of warning - possibly - pictures in headers and footers were not
supported in versions prior to 2002 - I think. Before that time, you have to
use a trick to fool Excel into placing the image into a hearder/footer and
so you risk creating files that may not - and I emphasise the may bit - be
completely compatible with older versions (e.g. Excel 97/2000) of Excel.

Yours

Mark B


JochenP wrote:
&gt; 
&gt; Hello,
&gt; 
&gt; I currently trying to figure out if it is possible to set the margins of a
&gt; workbook or excel document.
&gt; I know there are two methods to set the footer margin and header margin on
&gt; the PrintSetup class, on every sheet, but these don't seem to help. 
&gt; 
&gt; What I need to do is reduce the top, right, bottom and left margin to it's
&gt; minimum, so more content can be printed on one page. 
&gt; 
&gt; I also tried the the autobreaks and fit-width 1, but then I don't have
&gt; control over the paging which I need.
&gt; 
&gt; One thing I also would like to know: Is it possible to add pictures to the
&gt; footers? 
&gt; 
&gt; Or is there an other way, to start from a template excel file and dump my
&gt; data in a new copy of the template? Has anyone had experience with this?
&gt; 
&gt; Kind regards,
&gt; 
&gt; Jochen Punie
&gt; 

-- 
View this message in context: http://old.nabble.com/HSSF-workbook-print-setup-margins-tp26513632p26525253.html
Sent from the POI - User mailing list archive at Nabble.com.


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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: HSSF workbook print setup margins</title>
<author><name>MSB &lt;markbrdsly@tiscali.co.uk&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200911.mbox/%3c26525252.post@talk.nabble.com%3e"/>
<id>urn:uuid:%3c26525252-post@talk-nabble-com%3e</id>
<updated>2009-11-26T07:36:23Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

I must admit that I would use a template file to do this because I am not
aware of any technique that will allow you to insert pictures into the
footer using POI. Simply create a new Workbook using Excel, set the margins
as you want them and save it away. All you need to do then is open the
workbook using POI and populate the sheet(s).

Just a word of warning - possibly - pictures in headers and footers were not
supported in versions prior to 2002 - I think. Before that time, you have to
use a trick to fool Excel into placing the image into a hearder/footer and
so you risk creating files that may not - and I emphasise the may bit - be
completely compatible with older versions (e.g. Excel 97/2000) of Excel.

Yours

Mark B


JochenP wrote:
&gt; 
&gt; Hello,
&gt; 
&gt; I currently trying to figure out if it is possible to set the margins of a
&gt; workbook or excel document.
&gt; I know there are two methods to set the footer margin and header margin on
&gt; the PrintSetup class, on every sheet, but these don't seem to help. 
&gt; 
&gt; What I need to do is reduce the top, right, bottom and left margin to it's
&gt; minimum, so more content can be printed on one page. 
&gt; 
&gt; I also tried the the autobreaks and fit-width 1, but then I don't have
&gt; control over the paging which I need.
&gt; 
&gt; One thing I also would like to know: Is it possible to add pictures to the
&gt; footers? 
&gt; 
&gt; Or is there an other way, to start from a template excel file and dump my
&gt; data in a new copy of the template? Has anyone had experience with this?
&gt; 
&gt; Kind regards,
&gt; 
&gt; Jochen Punie
&gt; 

-- 
View this message in context: http://old.nabble.com/HSSF-workbook-print-setup-margins-tp26513632p26525252.html
Sent from the POI - User mailing list archive at Nabble.com.


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



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Excel found unreadable content in filename.xls when using wb.setRepeatingRowsAndColumns()</title>
<author><name>Hannes Erven &lt;h.e@gmx.at&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200911.mbox/%3chek64m$scc$1@ger.gmane.org%3e"/>
<id>urn:uuid:%3chek64m$scc$1@ger-gmane-org%3e</id>
<updated>2009-11-25T21:04:21Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Folks,


sorry to re-activite this thread... I've run into the same issue, but I
could track it down to using workbook.setRepeatingRowsAndColumns() on
the workbook: if used, Excel complains when opening about the same
things as David Hoffer described:

&gt; Errors were detected in file 'C:\filename.xls'
&gt; The following is a list of repairs:
&gt;
&gt; Removed one or more invalid names.

Unfortunately, my Excel is in German, but there is no more info
available anyways.

If I omit that call, the file opens fine.


OpenOffice opens the file without issues and also the repeating rows are
set the way I'd like them to be.


Has anyone any idea what might be going on? If helpful, I can make up
some test files to inspect.


Thanks, best regards

	-hannes

PS: I was surprised that I have to use
workbook.setRepeatingRowsAndColumns() at all since I'm wb.cloneSheet() a
sheet that already has repeating rows/columns set... is this by design?


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



</pre>
</div>
</content>
</entry>
<entry>
<title>RE: Modify word document</title>
<author><name>MSB &lt;markbrdsly@tiscali.co.uk&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/poi-user/200911.mbox/%3c26514349.post@talk.nabble.com%3e"/>
<id>urn:uuid:%3c26514349-post@talk-nabble-com%3e</id>
<updated>2009-11-25T15:10:03Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Thanks for that, I have seen people asking for just this sort of information
before on the list. Can I assume you have been able to get something to
work?

Yours

Mark B


Fabián Avilés Martínez wrote:
&gt; 
&gt; Hi Mark, version 3.2-FINAL is accesible in public maven repositories,
&gt; these are the dependencies:
&gt; 
&gt; &lt;dependency&gt;
&gt;     &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
&gt;     &lt;artifactId&gt;poi&lt;/artifactId&gt;
&gt;     &lt;version&gt;3.2-FINAL&lt;/version&gt;
&gt; &lt;/dependency&gt;
&gt; &lt;dependency&gt;
&gt;     &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
&gt;     &lt;artifactId&gt;poi-scratchpad&lt;/artifactId&gt;
&gt;     &lt;version&gt;3.2-FINAL&lt;/version&gt;
&gt; &lt;/dependency&gt;
&gt; 
&gt; 
&gt; Thanks, Fabi.
&gt; 
&gt; -----Mensaje original-----
&gt; De: MSB [mailto:markbrdsly@tiscali.co.uk]
&gt; Enviado el: martes, 24 de noviembre de 2009 17:27
&gt; Para: user@poi.apache.org
&gt; Asunto: RE: Modify word document
&gt; 
&gt; 
&gt; You are welcome.
&gt; 
&gt; If you do not have access to 3.2 FINAL of the API, it is possible to
&gt; download older releases from here -
&gt; http://archive.apache.org/dist/poi/release/bin/. Must admit that I do not
&gt; know what changes were made to HWPF between 3.2 and 3.5 so cannot say why
&gt; the formatting information is being lost and can only hope that you will
&gt; ne
&gt; able to revert to using 3.2 FINAL for this project.
&gt; 
&gt; All that you will need to do is to ensure that both the scratchpad and POI
&gt; archives are in your classpath and you should be able to successfully
&gt; compile and run the code. Any problems, just let me know.
&gt; 
&gt; Yours
&gt; 
&gt; Mark B
&gt; 
&gt; 
&gt; 
&gt; Fabián Avilés Martínez wrote:
&gt;&gt;
&gt;&gt; Wow, thats great. At least I have new direction to work with. I have been
&gt;&gt; struggling myself for at least three days. I can not try it today, but
&gt;&gt; tomorrow wil be the first thing I am going to do. I will told you the
&gt;&gt; results.
&gt;&gt;
&gt;&gt; Thank you so nuch.
&gt;&gt;
&gt;&gt; -----Mensaje original-----
&gt;&gt; De: MSB [mailto:markbrdsly@tiscali.co.uk]
&gt;&gt; Enviado el: martes, 24 de noviembre de 2009 16:51
&gt;&gt; Para: user@poi.apache.org
&gt;&gt; Asunto: RE: Modify word document
&gt;&gt;
&gt;&gt;
&gt;&gt; I have had the chance to play around with some code and I have to admit
&gt;&gt; that
&gt;&gt; I was wrong, on two counts.
&gt;&gt;
&gt;&gt; Firstly, if you do drill down to the level of the CharacterRun and
&gt;&gt; perform
&gt;&gt; a
&gt;&gt; replacement operation there, you will not retain the formatting applied
&gt;&gt; to
&gt;&gt; the text, further more, it seems to fail completely; no replacements will
&gt;&gt; be
&gt;&gt; made in the document at all. To have the search term be successfully
&gt;&gt; replaced, you DO need to operate at the Pargraph level.
&gt;&gt;
&gt;&gt; Secondly, if the search term is shorter than the replacement term, then
&gt;&gt; HWPF
&gt;&gt; will throw an exception. It seems quite happy to work if the replacement
&gt;&gt; term is equal to or longer - in terms of the number of characters - than
&gt;&gt; the
&gt;&gt; search term.
&gt;&gt;
&gt;&gt; Please see the code I have attached below;
&gt;&gt;
&gt;&gt; /* ====================================================================
&gt;&gt;    Licensed to the Apache Software Foundation (ASF) under one or more
&gt;&gt;    contributor license agreements.  See the NOTICE file distributed with
&gt;&gt;    this work for additional information regarding copyright ownership.
&gt;&gt;    The ASF licenses this file to You under the Apache License, Version
&gt;&gt; 2.0
&gt;&gt;    (the "License"); you may not use this file except in compliance with
&gt;&gt;    the License.  You may obtain a copy of the License at
&gt;&gt;
&gt;&gt;        http://www.apache.org/licenses/LICENSE-2.0
&gt;&gt;
&gt;&gt;    Unless required by applicable law or agreed to in writing, software
&gt;&gt;    distributed under the License is distributed on an "AS IS" BASIS,
&gt;&gt;    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
&gt;&gt; implied.
&gt;&gt;    See the License for the specific language governing permissions and
&gt;&gt;    limitations under the License.
&gt;&gt; ==================================================================== */
&gt;&gt;
&gt;&gt; package newsearchreplace;
&gt;&gt;
&gt;&gt; import java.io.File;
&gt;&gt; import java.io.FileInputStream;
&gt;&gt; import java.io.FileOutputStream;
&gt;&gt; import java.io.FileNotFoundException;
&gt;&gt; import java.io.IOException;
&gt;&gt; import java.util.HashMap;
&gt;&gt; import java.util.Set;
&gt;&gt;
&gt;&gt; import org.apache.poi.hwpf.HWPFDocument;
&gt;&gt; import org.apache.poi.hwpf.usermodel.Range;
&gt;&gt; import org.apache.poi.hwpf.usermodel.Paragraph;
&gt;&gt; import org.apache.poi.hwpf.usermodel.CharacterRun;
&gt;&gt;
&gt;&gt;
&gt;&gt; /**
&gt;&gt;  *
&gt;&gt;  * @author win Mark Beardsley [msb at apache.org]
&gt;&gt;  * @version 1.00
&gt;&gt;  */
&gt;&gt; public class SearchReplace {
&gt;&gt;
&gt;&gt;     private HashMap&lt;String, String&gt; searchTerms = null;
&gt;&gt;     private Set&lt;String&gt; searchKeys = null;
&gt;&gt;     private HWPFDocument wordDocument = null;
&gt;&gt;
&gt;&gt;     public SearchReplace() {
&gt;&gt;         searchTerms = new HashMap&lt;String, String&gt;();
&gt;&gt;         // The first String is the text that will be searched for, the
&gt;&gt; second is what will be used to
&gt;&gt;         // replace it. Of course, it is possible to create more than one
&gt;&gt; search term, replacement text
&gt;&gt;         // pairing.
&gt;&gt;         searchTerms.put("replace", "tester");
&gt;&gt;         searchKeys = searchTerms.keySet();
&gt;&gt;     }
&gt;&gt;
&gt;&gt;     public void openTemplate(String filename) throws
&gt;&gt; FileNotFoundException,
&gt;&gt; IOException {
&gt;&gt;         File file = null;
&gt;&gt;         FileInputStream fis = null;
&gt;&gt;         try {
&gt;&gt;             file = new File(filename);
&gt;&gt;             fis = new FileInputStream(file);
&gt;&gt;             this.wordDocument = new HWPFDocument(fis);
&gt;&gt;         }
&gt;&gt;         finally {
&gt;&gt;             if(fis != null) {
&gt;&gt;                 try {
&gt;&gt;                     fis.close();
&gt;&gt;                     fis = null;
&gt;&gt;                 }
&gt;&gt;                 catch(Exception ex) {
&gt;&gt;                     // I G N O R E
&gt;&gt;                 }
&gt;&gt;             }
&gt;&gt;         }
&gt;&gt;     }
&gt;&gt;
&gt;&gt;     public void searchAndReplace() {
&gt;&gt;         Range docRange = this.wordDocument.getRange();
&gt;&gt;         int numParas = docRange.numParagraphs();
&gt;&gt;         for(int i = 0; i &lt; numParas; i++) {
&gt;&gt;             Paragraph para = docRange.getParagraph(i);
&gt;&gt;             int numCharRuns = para.numCharacterRuns();
&gt;&gt;             for(int j = 0; j &lt; numCharRuns; j++) {
&gt;&gt;                 CharacterRun charRun = para.getCharacterRun(j);
&gt;&gt;                 String text = charRun.text();
&gt;&gt;                 for(String key : this.searchKeys) {
&gt;&gt;                     if(text.contains(key)) {
&gt;&gt;                         String replacementTerm =
&gt;&gt; this.searchTerms.get(key);
&gt;&gt;                         charRun.replaceText(replacementTerm, key);
&gt;&gt;                         System.out.println("Found: " + key + " in " +
&gt;&gt; text
&gt;&gt; +
&gt;&gt; ". Will replace with: " + replacementTerm);
&gt;&gt;                     }
&gt;&gt;                 }
&gt;&gt;             }
&gt;&gt;         }
&gt;&gt;
&gt;&gt;     }
&gt;&gt;
&gt;&gt;     public void searchReplace() {
&gt;&gt;         Range docRange = this.wordDocument.getRange();
&gt;&gt;         int numParas = docRange.numParagraphs();
&gt;&gt;         for(int i = 0; i &lt; numParas; i++) {
&gt;&gt;             Paragraph para = docRange.getParagraph(i);
&gt;&gt;             String text = para.text();
&gt;&gt;             for(String key : this.searchKeys) {
&gt;&gt;                 if(text.contains(key)) {
&gt;&gt;                     String replacementTerm = this.searchTerms.get(key);
&gt;&gt;                     para.replaceText(key, replacementTerm);
&gt;&gt;                 }
&gt;&gt;             }
&gt;&gt;         }
&gt;&gt;     }
&gt;&gt;
&gt;&gt;     public void saveResults(String filename) throws
&gt;&gt; FileNotFoundException,
&gt;&gt; IOException {
&gt;&gt;         File file = null;
&gt;&gt;         FileOutputStream fos = null;
&gt;&gt;         try {
&gt;&gt;             file = new File(filename);
&gt;&gt;             fos = new FileOutputStream(file);
&gt;&gt;             this.wordDocument.write(fos);
&gt;&gt;         }
&gt;&gt;         finally {
&gt;&gt;             if(fos != null) {
&gt;&gt;                 try {
&gt;&gt;                     fos.close();
&gt;&gt;                     fos = null;
&gt;&gt;                 }
&gt;&gt;                 catch(Exception ex) {
&gt;&gt;                     // I G N O R E
&gt;&gt;                 }
&gt;&gt;             }
&gt;&gt;         }
&gt;&gt;     }
&gt;&gt;
&gt;&gt;     /**
&gt;&gt;      * @param args the command line arguments
&gt;&gt;      */
&gt;&gt;     public static void main(String[] args) {
&gt;&gt;         try {
&gt;&gt;             SearchReplace sr = new SearchReplace();
&gt;&gt;             sr.openTemplate("C:/temp/Test Document.doc");
&gt;&gt;             sr.searchAndReplace();
&gt;&gt;             //sr.searchReplace();
&gt;&gt;             sr.saveResults("C:/temp/New Updated Document.doc");
&gt;&gt;         }
&gt;&gt;         catch(Exception ex) {
&gt;&gt;             System.out.println("Caught an: " + ex.getClass().getName());
&gt;&gt;             System.out.println("Message: " + ex.getMessage());
&gt;&gt;             System.out.println("Stacktrace follows............");
&gt;&gt;             ex.printStackTrace(System.out);
&gt;&gt;         }
&gt;&gt;     }
&gt;&gt; }
&gt;&gt;
&gt;&gt; More particularly, look at the main method. If you comment out the
&gt;&gt; sr.searchAndReplace() and un-comment the sr.searchReplace() line, then
&gt;&gt; the
&gt;&gt; code will work successfully. But, and this is a BIG but, it will only
&gt;&gt; work
&gt;&gt; if you compile and run it against 3.2 FINAL of the API. I have found that
&gt;&gt; later versions seem to 'drop' or lose the formatting information
&gt;&gt; completely;
&gt;&gt; to convince yourself of this, just modify the main method so that it
&gt;&gt; contains only these lines of code;
&gt;&gt;
&gt;&gt; SearchReplace sr = new SearchReplace();
&gt;&gt; sr.openTemplate("C:/temp/Test Document.doc");
&gt;&gt; sr.saveResults("C:/temp/New Updated Document.doc");
&gt;&gt;
&gt;&gt; If you run that against versions later than 3.2 FINAL, you should see
&gt;&gt; that
&gt;&gt; the copy of the original document that this produces loses all of it's
&gt;&gt; formatting.
&gt;&gt;
&gt;&gt; Yours
&gt;&gt;
&gt;&gt; Mark B
&gt;&gt;
&gt;&gt; PS. I guess that it should go without saying, you will need to replace
&gt;&gt; the
&gt;&gt; paths to and document names passed to the openTemplate() and
&gt;&gt; saveResults()
&gt;&gt; methods to point to locations and files that exist on your machine.
&gt;&gt;
&gt;&gt; PPS Forgive the lack of comments please. I hope that the it is apparant
&gt;&gt; just
&gt;&gt; what the methods do.
&gt;&gt;
&gt;&gt;
&gt;&gt; Fabián Avilés Martínez wrote:
&gt;&gt;&gt;
&gt;&gt;&gt; Hi, as I told you, I have tried it, but with the same result, the
&gt;&gt;&gt; resulting file is corrupted, that is what MSWord says. My next approach
&gt;&gt;&gt; is
&gt;&gt;&gt; to create a copy file, and do modifications within this file. My problem
&gt;&gt;&gt; is that I do not know how to save modifications done in the charRuns of
&gt;&gt;&gt; the paragraphs, what I mean is to persist modifications done in the
&gt;&gt;&gt; resulting file, without have to coopy it, calling
&gt;&gt;&gt; document.write(outputStream)
&gt;&gt;&gt;
&gt;&gt;&gt; My code is:
&gt;&gt;&gt;
&gt;&gt;&gt; public File processFile(final InputStream is, final Map&lt;String, String&gt;
&gt;&gt;&gt; replacementText) throws IOException {
&gt;&gt;&gt;         Set&lt;String&gt; keys = replacementText.keySet();
&gt;&gt;&gt;         try {
&gt;&gt;&gt;             // Makes a copy of the file.
&gt;&gt;&gt;             File res = copyfile(is);
&gt;&gt;&gt;             InputStream auxIs = new FileInputStream(res);
&gt;&gt;&gt;             POIFSFileSystem poifs = new POIFSFileSystem(auxIs);
&gt;&gt;&gt;             HWPFDocument document = new HWPFDocument(poifs);
&gt;&gt;&gt;             Range range = document.getRange();
&gt;&gt;&gt;
&gt;&gt;&gt;             for (int i = 0; i &lt; range.numParagraphs(); i++) {
&gt;&gt;&gt;                 Paragraph paragraph = range.getParagraph(i);
&gt;&gt;&gt;                 int numCharRuns = paragraph.numCharacterRuns();
&gt;&gt;&gt;                 for (int j = 0; j &lt; numCharRuns; j++) {
&gt;&gt;&gt;                     CharacterRun charRun = paragraph.getCharacterRun(j);
&gt;&gt;&gt;                     for (Iterator&lt;String&gt; it = keys.iterator();
&gt;&gt;&gt; it.hasNext();) {
&gt;&gt;&gt;                         String key = it.next();
&gt;&gt;&gt;                         if (charRun.text().contains(key)) {
&gt;&gt;&gt;                             String value = replacementText.get(key);
&gt;&gt;&gt;                             charRun.replaceText(key, value);
&gt;&gt;&gt;                             range = document.getRange();
&gt;&gt;&gt;                             paragraph = range.getParagraph(i);
&gt;&gt;&gt;                             charRun = paragraph.getCharacterRun(j);
&gt;&gt;&gt;                         }
&gt;&gt;&gt;                     }
&gt;&gt;&gt;                 }
&gt;&gt;&gt;             }
&gt;&gt;&gt;             is.close();
&gt;&gt;&gt;             return res;
&gt;&gt;&gt;         } catch (IOException e) {
&gt;&gt;&gt;             logger.error("Error procesando el fichero WORD: " + e);
&gt;&gt;&gt;             throw new IOException("Error procesando el fichero WORD");
&gt;&gt;&gt;         } finally {
&gt;&gt;&gt;             if (is != null) {
&gt;&gt;&gt;                 is.close();
&gt;&gt;&gt;             }
&gt;&gt;&gt;         }
&gt;&gt;&gt;     }
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; Thanks in advance, Fabi.
&gt;&gt;&gt;
&gt;&gt;&gt; -----Mensaje original-----
&gt;&gt;&gt; De: MSB [mailto:markbrdsly@tiscali.co.uk]
&gt;&gt;&gt; Enviado el: martes, 24 de noviembre de 2009 8:43
&gt;&gt;&gt; Para: user@poi.apache.org
&gt;&gt;&gt; Asunto: Re: Modify word document
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; You have not dug down far enough into the structure of the document yet
&gt;&gt;&gt; I
&gt;&gt;&gt; am
&gt;&gt;&gt; afraid - all of the formatting information is stopred (encapsulated)
&gt;&gt;&gt; within
&gt;&gt;&gt; the CharacterRun class and you need to perform the repllacements at that
&gt;&gt;&gt; level.
&gt;&gt;&gt;
&gt;&gt;&gt; I do not have any suitable code at hand as I type this so what follows
&gt;&gt;&gt; will
&gt;&gt;&gt; need to be converted into Java and tested;
&gt;&gt;&gt;
&gt;&gt;&gt; Open the Word document.
&gt;&gt;&gt; Get the overall Range for the document.
&gt;&gt;&gt; Get the number of Paragraph objects the Range contains.
&gt;&gt;&gt; Iterate through the Pargraphs and for each Pargraph
&gt;&gt;&gt;     Get the CharacterRun(s) the Paragraph contains.
&gt;&gt;&gt;     Call the method to replace the search term with the replacement text
&gt;&gt;&gt; on
&gt;&gt;&gt; the CharacterRun
&gt;&gt;&gt; Save the modified document away again.
&gt;&gt;&gt;
&gt;&gt;&gt; You do however face a couple of problems with this. It has been a long
&gt;&gt;&gt; time
&gt;&gt;&gt; since I tried to write a search and replace routine using HWPF and I
&gt;&gt;&gt; could
&gt;&gt;&gt; not get it to work if the replacement text was longer that the search
&gt;&gt;&gt; term.
&gt;&gt;&gt; In that case, HWPF threw an exception and would not allow me to complete
&gt;&gt;&gt; the
&gt;&gt;&gt; process; but that problem could well have been addressed by now as it
&gt;&gt;&gt; was
&gt;&gt;&gt; well known and caused by faulty bounds checking within the Range class.
&gt;&gt;&gt; Only
&gt;&gt;&gt; testing will prove or disprove this for you I am afraid.
&gt;&gt;&gt;
&gt;&gt;&gt; Secondly, the CharacterRun class encapsulates a piece of text with
&gt;&gt;&gt; common
&gt;&gt;&gt; properties. So, imagine that we are searching for the phrase 'search
&gt;&gt;&gt; term'
&gt;&gt;&gt; and that the word 'search' has been emboldened whilst the word 'term'
&gt;&gt;&gt; has
&gt;&gt;&gt; been left as normal text, then my suggested approach will not work. That
&gt;&gt;&gt; is
&gt;&gt;&gt; because the words search and term will be held in different
&gt;&gt;&gt; CharacterRun(s).
&gt;&gt;&gt; If you do hit this problem, then I am afraid you will have to write code
&gt;&gt;&gt; that searches for the term at the Paragraph level and that identifies
&gt;&gt;&gt; where
&gt;&gt;&gt; the search terms can be found and recovers the CharacterRun(s) that
&gt;&gt;&gt; encapsulate them. Once you have these, you can modify the runs or create
&gt;&gt;&gt; and
&gt;&gt;&gt; substitute new ones but I have to admit that I have never tried to do
&gt;&gt;&gt; this
&gt;&gt;&gt; myself. Instead I chose to automate Word using OLE and to explore the
&gt;&gt;&gt; possibilities offered by OpenOffices UNO interface. Both options did
&gt;&gt;&gt; work
&gt;&gt;&gt; but threw up other problems that proved more limiting (in terms of
&gt;&gt;&gt; architecture and platform). If you can get it to work, HWPF offers the
&gt;&gt;&gt; better solution IMO.
&gt;&gt;&gt;
&gt;&gt;&gt; Yours
&gt;&gt;&gt;
&gt;&gt;&gt; Mark B
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; Fabián Avilés Martínez wrote:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Hi all,
&gt;&gt;&gt;&gt;      I have a Word document, as a template: In this template there are
&gt;&gt;&gt;&gt; some
&gt;&gt;&gt;&gt; tokenized words, which have to be modified and the result has to be
&gt;&gt;&gt;&gt; saved
&gt;&gt;&gt;&gt; into another file. The original file has some properties, like header
&gt;&gt;&gt;&gt; and
&gt;&gt;&gt;&gt; footer, images, etc. The resulting file has to be the same, but with
&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt; modified words. I am trying it with the code below, but it does not
&gt;&gt;&gt;&gt; work.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public ByteArrayOutputStream processFile(final InputStream is, final
&gt;&gt;&gt;&gt; Map&lt;String, String&gt; replacementText)
&gt;&gt;&gt;&gt;         throws IOException {
&gt;&gt;&gt;&gt;         Set&lt;String&gt; keys = replacementText.keySet();
&gt;&gt;&gt;&gt;         try {
&gt;&gt;&gt;&gt;             POIFSFileSystem poifs = new POIFSFileSystem(is);
&gt;&gt;&gt;&gt;             HWPFDocument document = new HWPFDocument(poifs);
&gt;&gt;&gt;&gt;             Range range = document.getRange();
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;             for (int i = 0; i &lt; range.numParagraphs(); i++) {
&gt;&gt;&gt;&gt;                 String newTxt = range.getParagraph(i).text();
&gt;&gt;&gt;&gt;                 String oldTxt = range.getParagraph(i).text();
&gt;&gt;&gt;&gt;                 for (Iterator&lt;String&gt; it = keys.iterator();
&gt;&gt;&gt;&gt; it.hasNext();)
&gt;&gt;&gt;&gt; {
&gt;&gt;&gt;&gt;                     String key = it.next();
&gt;&gt;&gt;&gt;                     if (newTxt.contains(key)) {
&gt;&gt;&gt;&gt;                         newTxt = replacePlaceholders(key,
&gt;&gt;&gt;&gt; replacementText.get(key), newTxt);
&gt;&gt;&gt;&gt;                     }
&gt;&gt;&gt;&gt;                 }
&gt;&gt;&gt;&gt;                 if (!oldTxt.equals(newTxt)) {
&gt;&gt;&gt;&gt;                     range.getParagraph(i).replaceText(oldTxt, newTxt);
&gt;&gt;&gt;&gt;                 }
&gt;&gt;&gt;&gt;             }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;             // Save the document away.
&gt;&gt;&gt;&gt;             ByteArrayOutputStream bos = new ByteArrayOutputStream();
&gt;&gt;&gt;&gt;             document.write(bos);
&gt;&gt;&gt;&gt;             bos.flush();
&gt;&gt;&gt;&gt;             bos.close();
&gt;&gt;&gt;&gt;             return bos;
&gt;&gt;&gt;&gt;         } catch (IOException e) {
&gt;&gt;&gt;&gt;             logger.error("Error procesando el fichero WORD: " + e);
&gt;&gt;&gt;&gt;             throw new IOException("Error procesando el fichero WORD");
&gt;&gt;&gt;&gt;         } finally {
&gt;&gt;&gt;&gt;             if (is != null) {
&gt;&gt;&gt;&gt;                 is.close();
&gt;&gt;&gt;&gt;             }
&gt;&gt;&gt;&gt;         }
&gt;&gt;&gt;&gt;     }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Any help, please?
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Thanks in advance, Fabi.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; ______________________
&gt;&gt;&gt;&gt; This message including any attachments may contain confidential
&gt;&gt;&gt;&gt; information, according to our Information Security Management System,
&gt;&gt;&gt;&gt;  and intended solely for a specific individual to whom they are
&gt;&gt;&gt;&gt; addressed.
&gt;&gt;&gt;&gt;  Any unauthorised copy, disclosure or distribution of this message
&gt;&gt;&gt;&gt;  is strictly forbidden. If you have received this transmission in
&gt;&gt;&gt;&gt; error,
&gt;&gt;&gt;&gt;  please notify the sender immediately and delete it.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; ______________________
&gt;&gt;&gt;&gt; Este mensaje, y en su caso, cualquier fichero anexo al mismo,
&gt;&gt;&gt;&gt;  puede contener informacion clasificada por su emisor como confidencial
&gt;&gt;&gt;&gt;  en el marco de su Sistema de Gestion de Seguridad de la
&gt;&gt;&gt;&gt; Informacion siendo para uso exclusivo del destinatario, quedando
&gt;&gt;&gt;&gt; prohibida su divulgacion copia o distribucion a terceros sin la
&gt;&gt;&gt;&gt; autorizacion expresa del remitente. Si Vd. ha recibido este mensaje
&gt;&gt;&gt;&gt;  erroneamente, se ruega lo notifique al remitente y proceda a su
&gt;&gt;&gt;&gt; borrado.
&gt;&gt;&gt;&gt; Gracias por su colaboracion.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; ______________________
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; ---------------------------------------------------------------------
&gt;&gt;&gt;&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt;&gt;&gt;&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; --
&gt;&gt;&gt; View this message in context:
&gt;&gt;&gt; http://old.nabble.com/Modify-word-document-tp26480450p26491636.html
&gt;&gt;&gt; Sent from the POI - User mailing list archive at Nabble.com.
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; ---------------------------------------------------------------------
&gt;&gt;&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt;&gt;&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; ______________________
&gt;&gt;&gt; This message including any attachments may contain confidential
&gt;&gt;&gt; information, according to our Information Security Management System,
&gt;&gt;&gt;  and intended solely for a specific individual to whom they are
&gt;&gt;&gt; addressed.
&gt;&gt;&gt;  Any unauthorised copy, disclosure or distribution of this message
&gt;&gt;&gt;  is strictly forbidden. If you have received this transmission in error,
&gt;&gt;&gt;  please notify the sender immediately and delete it.
&gt;&gt;&gt;
&gt;&gt;&gt; ______________________
&gt;&gt;&gt; Este mensaje, y en su caso, cualquier fichero anexo al mismo,
&gt;&gt;&gt;  puede contener informacion clasificada por su emisor como confidencial
&gt;&gt;&gt;  en el marco de su Sistema de Gestion de Seguridad de la
&gt;&gt;&gt; Informacion siendo para uso exclusivo del destinatario, quedando
&gt;&gt;&gt; prohibida su divulgacion copia o distribucion a terceros sin la
&gt;&gt;&gt; autorizacion expresa del remitente. Si Vd. ha recibido este mensaje
&gt;&gt;&gt;  erroneamente, se ruega lo notifique al remitente y proceda a su
&gt;&gt;&gt; borrado.
&gt;&gt;&gt; Gracias por su colaboracion.
&gt;&gt;&gt;
&gt;&gt;&gt; ______________________
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;
&gt;&gt; --
&gt;&gt; View this message in context:
&gt;&gt; http://old.nabble.com/Modify-word-document-tp26480450p26498333.html
&gt;&gt; Sent from the POI - User mailing list archive at Nabble.com.
&gt;&gt;
&gt;&gt;
&gt;&gt; ---------------------------------------------------------------------
&gt;&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt;&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt;&gt;
&gt;&gt;
&gt;&gt; ______________________
&gt;&gt; This message including any attachments may contain confidential
&gt;&gt; information, according to our Information Security Management System,
&gt;&gt;  and intended solely for a specific individual to whom they are
&gt;&gt; addressed.
&gt;&gt;  Any unauthorised copy, disclosure or distribution of this message
&gt;&gt;  is strictly forbidden. If you have received this transmission in error,
&gt;&gt;  please notify the sender immediately and delete it.
&gt;&gt;
&gt;&gt; ______________________
&gt;&gt; Este mensaje, y en su caso, cualquier fichero anexo al mismo,
&gt;&gt;  puede contener informacion clasificada por su emisor como confidencial
&gt;&gt;  en el marco de su Sistema de Gestion de Seguridad de la
&gt;&gt; Informacion siendo para uso exclusivo del destinatario, quedando
&gt;&gt; prohibida su divulgacion copia o distribucion a terceros sin la
&gt;&gt; autorizacion expresa del remitente. Si Vd. ha recibido este mensaje
&gt;&gt;  erroneamente, se ruega lo notifique al remitente y proceda a su borrado.
&gt;&gt; Gracias por su colaboracion.
&gt;&gt;
&gt;&gt; ______________________
&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt; 
&gt; --
&gt; View this message in context:
&gt; http://old.nabble.com/Modify-word-document-tp26480450p26498547.html
&gt; Sent from the POI - User mailing list archive at Nabble.com.
&gt; 
&gt; 
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
&gt; For additional commands, e-mail: user-help@poi.apache.org
&gt; 
&gt; 
&gt; ______________________
&gt; This message including any attachments may contain confidential 
&gt; information, according to our Information Security Management System,
&gt;  and intended solely for a specific individual to whom they are addressed.
&gt;  Any unauthorised copy, disclosure or distribution of this message
&gt;  is strictly forbidden. If you have received this transmission in error,
&gt;  please notify the sender immediately and delete it.
&gt; 
&gt; ______________________
&gt; Este mensaje, y en su caso, cualquier fichero anexo al mismo,
&gt;  puede contener informacion clasificada por su emisor como confidencial
&gt;  en el marco de su Sistema de Gestion de Seguridad de la 
&gt; Informacion siendo para uso exclusivo del destinatario, quedando 
&gt; prohibida su divulgacion copia o distribucion a terceros sin la 
&gt; autorizacion expresa del remitente. Si Vd. ha recibido este mensaje 
&gt;  erroneamente, se ruega lo notifique al remitente y proceda a su borrado. 
&gt; Gracias por su colaboracion.
&gt; 
&gt; ______________________
&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://old.nabble.com/Modify-word-document-tp26480450p26514349.html
Sent from the POI - User mailing list archive at Nabble.com.


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



</pre>
</div>
</content>
</entry>
</feed>
