You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by JSpence <js...@mproducegroup.com> on 2009/05/29 13:14:50 UTC

Busy Developers' Guide to HSSF and XSSF Features Example One

Hello,

   I have a question about line one in example one, entitled "New Workbook"
here is line one:

  // Workbook wb = new HSSFWorkbook();

My compiler complained about the declaration "Workbook", and suggested that
I change it to HSSFWorkbook, which I did and it worked fine.

My questions is about the the statement. I have seen a similar pattern in
another example that I was studying. Such as:

  // protected final List<ItemFile> dataList = new ArrayList<ItemFile>();

Where the declaration is farther up the hierarchy and the instantiation lower.
I don't understand why one would do this.

Can someone please point me in the right direction?

Thanks,
JSpence.



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


Re: Busy Developers' Guide to HSSF and XSSF Features Example One

Posted by TimShiu <ti...@ssc-ltd.com>.
I have your problem before which is due to using of POI 3.2 Final for the
library.
The XSSF library is introduced in POI 3.5. Please check if your build path
is pointed to the right jar file.


Jeff Spence wrote:
> 
>> Having said that the Workbook interface is defined in the ss.usermodel
>> package. Both the XSSFWorkbook and HSSFWorkbook classes implement it.
> 
> Ok, I tried the following with success:
> 
>     HSSFWorkbook wb = new HSSFWorkbook();
>     FileOutputStream fileOut = new FileOutputStream("C:\\workbook.xls");
>     wb.write(fileOut);
>     fileOut.close();
> 
> But the following without success (narrowed down to this line I think). 
> 
>     XSSFWorkbook wb = new XSSFWorkbook();
> 
> ...this error message.
> 
> java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException
> 
> ...tried these imports.
> 
> import org.apache.poi.xssf.usermodel.XSSFWorkbook;
> import org.apache.poi.xssf.usermodel.*;
> 
> I don't think it's the path because, as stated above, they both
> derive from ss.usermodel.
> 
> Anyone have a suggestion?
> 
> Thanks, 
> Jeff.
> 
> 
> 
> 
> 
> 
> MSB <markbrdsly <at> tiscali.co.uk> writes:
> 
>> 
>> 
>> I did not contribute to the guide Jeff so must admit that this is a
>> guess.
>> Having said that the Workbook interface is defined in the ss.usermodel
>> package. Both the XSSFWorkbook and HSSFWorkbook classes implement it and
>> it
>> - the interface - contains a number of common method declarations. The
>> reason - at least as far as I am aware - that it was added to the API is
>> to
>> allow developers to support both binary and OpenXML based Excel files
>> from a
>> common code set.
>> 
>> It may be the case that the application cannot 'know' until runtime
>> exactly
>> which file format it is dealing with. So, you declare a variable of the
>> interface type in the knowledge that a reference to an instance of either
>> the HSSFWorkbook or XSSFWorkbook can be stored into it. The
>> WorkbookFactory
>> class is the key to all of this; it can accept an InputStream and work
>> out
>> from that stream whether the application is processing an OpenXML or
>> binary
>> file, returning an instance of the appropriate class.
>> 
>> Hope that heps.
>> 
>> Mark B
>> 
>> Jeff Spence wrote:
>> > 
>> > Hello,
>> > 
>> >    I have a question about line one in example one, entitled "New
>> > Workbook"
>> > here is line one:
>> > 
>> >   // Workbook wb = new HSSFWorkbook();
>> > 
>> > My compiler complained about the declaration "Workbook", and suggested
>> > that
>> > I change it to HSSFWorkbook, which I did and it worked fine.
>> > 
>> > My questions is about the the statement. I have seen a similar pattern
>> in
>> > another example that I was studying. Such as:
>> > 
>> >   // protected final List<ItemFile> dataList = new
>> ArrayList<ItemFile>();
>> > 
>> > Where the declaration is farther up the hierarchy and the instantiation
>> > lower.
>> > I don't understand why one would do this.
>> > 
>> > Can someone please point me in the right direction?
>> > 
>> > Thanks,
>> > JSpence.
>> > 
>> > 
>> > 
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe <at> poi.apache.org
>> > For additional commands, e-mail: user-help <at> poi.apache.org
>> > 
>> > 
>> > 
>> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Busy-Developers%27-Guide-to-HSSF-and-XSSF-Features--Example-One-tp23778163p23993815.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


Re: Busy Developers' Guide to HSSF and XSSF Features Example One

Posted by JSpence <js...@mproducegroup.com>.
> Having said that the Workbook interface is defined in the ss.usermodel
> package. Both the XSSFWorkbook and HSSFWorkbook classes implement it.

Ok, I tried the following with success:

    HSSFWorkbook wb = new HSSFWorkbook();
    FileOutputStream fileOut = new FileOutputStream("C:\\workbook.xls");
    wb.write(fileOut);
    fileOut.close();

But the following without success (narrowed down to this line I think). 

    XSSFWorkbook wb = new XSSFWorkbook();

...this error message.

java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException

...tried these imports.

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.*;

I don't think it's the path because, as stated above, they both
derive from ss.usermodel.

Anyone have a suggestion?

Thanks, 
Jeff.






MSB <markbrdsly <at> tiscali.co.uk> writes:

> 
> 
> I did not contribute to the guide Jeff so must admit that this is a guess.
> Having said that the Workbook interface is defined in the ss.usermodel
> package. Both the XSSFWorkbook and HSSFWorkbook classes implement it and it
> - the interface - contains a number of common method declarations. The
> reason - at least as far as I am aware - that it was added to the API is to
> allow developers to support both binary and OpenXML based Excel files from a
> common code set.
> 
> It may be the case that the application cannot 'know' until runtime exactly
> which file format it is dealing with. So, you declare a variable of the
> interface type in the knowledge that a reference to an instance of either
> the HSSFWorkbook or XSSFWorkbook can be stored into it. The WorkbookFactory
> class is the key to all of this; it can accept an InputStream and work out
> from that stream whether the application is processing an OpenXML or binary
> file, returning an instance of the appropriate class.
> 
> Hope that heps.
> 
> Mark B
> 
> Jeff Spence wrote:
> > 
> > Hello,
> > 
> >    I have a question about line one in example one, entitled "New
> > Workbook"
> > here is line one:
> > 
> >   // Workbook wb = new HSSFWorkbook();
> > 
> > My compiler complained about the declaration "Workbook", and suggested
> > that
> > I change it to HSSFWorkbook, which I did and it worked fine.
> > 
> > My questions is about the the statement. I have seen a similar pattern in
> > another example that I was studying. Such as:
> > 
> >   // protected final List<ItemFile> dataList = new ArrayList<ItemFile>();
> > 
> > Where the declaration is farther up the hierarchy and the instantiation
> > lower.
> > I don't understand why one would do this.
> > 
> > Can someone please point me in the right direction?
> > 
> > Thanks,
> > JSpence.
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe <at> poi.apache.org
> > For additional commands, e-mail: user-help <at> poi.apache.org
> > 
> > 
> > 
> 





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


Re: Busy Developers' Guide to HSSF and XSSF Features Example One

Posted by MSB <ma...@tiscali.co.uk>.
I did not contribute to the guide Jeff so must admit that this is a guess.
Having said that the Workbook interface is defined in the ss.usermodel
package. Both the XSSFWorkbook and HSSFWorkbook classes implement it and it
- the interface - contains a number of common method declarations. The
reason - at least as far as I am aware - that it was added to the API is to
allow developers to support both binary and OpenXML based Excel files from a
common code set.

It may be the case that the application cannot 'know' until runtime exactly
which file format it is dealing with. So, you declare a variable of the
interface type in the knowledge that a reference to an instance of either
the HSSFWorkbook or XSSFWorkbook can be stored into it. The WorkbookFactory
class is the key to all of this; it can accept an InputStream and work out
from that stream whether the application is processing an OpenXML or binary
file, returning an instance of the appropriate class.

Hope that heps.

Mark B



Jeff Spence wrote:
> 
> Hello,
> 
>    I have a question about line one in example one, entitled "New
> Workbook"
> here is line one:
> 
>   // Workbook wb = new HSSFWorkbook();
> 
> My compiler complained about the declaration "Workbook", and suggested
> that
> I change it to HSSFWorkbook, which I did and it worked fine.
> 
> My questions is about the the statement. I have seen a similar pattern in
> another example that I was studying. Such as:
> 
>   // protected final List<ItemFile> dataList = new ArrayList<ItemFile>();
> 
> Where the declaration is farther up the hierarchy and the instantiation
> lower.
> I don't understand why one would do this.
> 
> Can someone please point me in the right direction?
> 
> Thanks,
> JSpence.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Busy-Developers%27-Guide-to-HSSF-and-XSSF-Features--Example-One-tp23778163p23778451.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