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: [email protected]
> For additional commands, e-mail: [email protected]
> 
> 
> 

-- 
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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to