xelem.3.0

nl.fountain.xelem.excel.ss
Class XLWorkbook

java.lang.Object
  extended by nl.fountain.xelem.excel.AbstractXLElement
      extended by nl.fountain.xelem.excel.ss.XLWorkbook
All Implemented Interfaces:
Workbook, XLElement

public class XLWorkbook
extends AbstractXLElement
implements Workbook

An implementation of the XLElement Workbook, the root of a SpreadsheetML document.

Typically, the XLWorkbook is at the start of creating an Excel workbook in SpreadsheetML. Mostly all of the other objects in xelem can be obtained from it or through it by one of the addXxx- methods.

After setting up the workbook, you can obtain the org.w3c.dom.Document from it (see createDocument()) or serialize the workbook by means of one of the serialize-methods of the XSerializer.class, which was included in xelem for convenience.

Worksheets are displayed in Excel in the order that they were added to the workbook. The methods removeSheet(String) and addSheet(Worksheet) may savely be applied to change this order. A more convenient way is to obtain the list of sheet names with getSheetNames() and manupulating this list.

See Also:
overview

Field Summary
 
Fields inherited from interface nl.fountain.xelem.excel.XLElement
PREFIX_HTML, PREFIX_O, PREFIX_SS, PREFIX_X, XMLNS, XMLNS_HTML, XMLNS_O, XMLNS_SS, XMLNS_X
 
Constructor Summary
XLWorkbook()
          Creates a new XLWorkbook.
XLWorkbook(String name)
          Creates a new XLWorkbook with the given name.
 
Method Summary
 NamedRange addNamedRange(NamedRange nr)
          Adds a new NamedRange to this workbook.
 NamedRange addNamedRange(String name, String refersTo)
          Adds a new NamedRange to this workbook.
 Worksheet addSheet()
          Adds a new Worksheet to this workbook.
 Worksheet addSheet(String name)
          Adds a new Worksheet to this workbook with the given name as name.
 Worksheet addSheet(Worksheet sheet)
          Adds the given Worksheet to this workbook.
 void appendInfoSheet()
          Appends a Worksheet with general information to this Workbook.
 Element assemble(Element root, GIO gio)
          Assembles the state of this XLElement and all of it's children into an Element.
 Document createDocument()
          Creates a Document, the structure that holds this Workbook and all of it's children.
 DocumentProperties getDocumentProperties()
          Gets the DocumentProperties of this workbook.
 ExcelWorkbook getExcelWorkbook()
          Gets the ExcelWorkbook of this workbook.
 String getFileName()
          Gets the filename of this Workbook.
 String getName()
          Gets the name of this Workbook.
 Map<String,NamedRange> getNamedRanges()
          Gets all the NamedRanges that were added to this workbook.
 String getNameSpace()
          Gets the namespace of this XLElement.
 String getPrefix()
          Gets the prefix of this XLElement.
 List<String> getSheetNames()
          Gets a list of all the names of worksheets in this workbook in display order.
 String getTagName()
          Gets the tagname (localName) of this XLElement.
 List<String> getWarnings()
          Gets a list of warnings (Strings) that were registered during assembly of this workbook after a call to Workbook.createDocument().
 Worksheet getWorksheet(String name)
          Gets the worksheet with the given name.
 Worksheet getWorksheetAt(int index)
          Gets the worksheet at the given index.
 List<Worksheet> getWorksheets()
          Gets a list of all the worksheets in this workbook in display order.
 boolean hasDocumentProperties()
          Specifies whether this workbook has DocumentProperties.
 boolean hasExcelWorkbook()
          Specifies whether this workbook has an ExcelWorkbook.
 boolean isPrintingDocComments()
          Specifies whether this Workbook's Workbook.createDocument()-method will include docComments.
 boolean isPrintingElementComments()
          Specifies whether this Workbook's Workbook.createDocument()-method will include comments.
 void mergeStyles(String newID, String id1, String id2)
          Merges two SpreadsheetML Style elements.
 Worksheet removeSheet(String name)
          Removes the sheet with the given name.
 void setDocumentProperties(DocumentProperties docProps)
          Set the DocumentProperties of this workbook or, if this workbook allready had DocumentProperties, replace it.
 void setExcelWorkbook(ExcelWorkbook excelWb)
          Set the ExcelWorkbook of this workbook or, if this workbook allready had an ExcelWorkbook, replace it.
 void setFileName(String filename)
          Sets the filename of this Workbook.
 void setName(String name)
          Sets the name of this Workbook.
 void setPrintDocComments(boolean print)
          Sets whether this Workbook's Workbook.createDocument()-method will include docComments.
 void setPrintElementComments(boolean print)
          Sets whether this Workbook's Workbook.createDocument()-method will print comments which were set with XLElement.addElementComment(String).
 
Methods inherited from class nl.fountain.xelem.excel.AbstractXLElement
addElementComment, assemble, createAttributeNS, createAttributeNS, createElementNS, createElementNS, createElementNS, createElementNS, getElementComments, setAttributes, setChildElement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface nl.fountain.xelem.excel.XLElement
addElementComment, getElementComments, setAttributes, setChildElement
 

Constructor Detail

XLWorkbook

public XLWorkbook()
Creates a new XLWorkbook.


XLWorkbook

public XLWorkbook(String name)
Creates a new XLWorkbook with the given name.

Method Detail

setName

public void setName(String name)
Description copied from interface: Workbook
Sets the name of this Workbook.

Specified by:
setName in interface Workbook

getName

public String getName()
Description copied from interface: Workbook
Gets the name of this Workbook.

Specified by:
getName in interface Workbook

setFileName

public void setFileName(String filename)
Description copied from interface: Workbook
Sets the filename of this Workbook.

Specified by:
setFileName in interface Workbook

getFileName

public String getFileName()
Description copied from interface: Workbook
Gets the filename of this Workbook. If no filename was supplied with Workbook.setFileName(String) the name of the workbook is returned with the extension '.xls'.

Specified by:
getFileName in interface Workbook

mergeStyles

public void mergeStyles(String newID,
                        String id1,
                        String id2)
                 throws UnsupportedStyleException
Description copied from interface: Workbook
Merges two SpreadsheetML Style elements.

Specified by:
mergeStyles in interface Workbook
Parameters:
newID - the ss:ID of the new merged style
id1 - the ss:ID of the copied style
id2 - the ss:ID of the appended style
Throws:
UnsupportedStyleException - if either of the styles mentioned with id1 or id2 are unknown to the factory.
See Also:
XFactory.mergeStyles(String, String, String)

appendInfoSheet

public void appendInfoSheet()
Description copied from interface: Workbook
Appends a Worksheet with general information to this Workbook. The infoSheet is allways displayed as the last worksheet.

Specified by:
appendInfoSheet in interface Workbook

setDocumentProperties

public void setDocumentProperties(DocumentProperties docProps)
Description copied from interface: Workbook
Set the DocumentProperties of this workbook or, if this workbook allready had DocumentProperties, replace it.

Specified by:
setDocumentProperties in interface Workbook
Parameters:
docProps - the DocumentProperties for this workbook

getDocumentProperties

public DocumentProperties getDocumentProperties()
Description copied from interface: Workbook
Gets the DocumentProperties of this workbook.

Specified by:
getDocumentProperties in interface Workbook
Returns:
The DocumentProperties of this workbook. Never null.

hasDocumentProperties

public boolean hasDocumentProperties()
Description copied from interface: Workbook
Specifies whether this workbook has DocumentProperties.

Specified by:
hasDocumentProperties in interface Workbook

setExcelWorkbook

public void setExcelWorkbook(ExcelWorkbook excelWb)
Description copied from interface: Workbook
Set the ExcelWorkbook of this workbook or, if this workbook allready had an ExcelWorkbook, replace it.

Specified by:
setExcelWorkbook in interface Workbook
Parameters:
excelWb - The ExcelWorkbook for this workbook

getExcelWorkbook

public ExcelWorkbook getExcelWorkbook()
Description copied from interface: Workbook
Gets the ExcelWorkbook of this workbook.

Specified by:
getExcelWorkbook in interface Workbook
Returns:
The ExcelWorkbook of this workbook. Never null.

hasExcelWorkbook

public boolean hasExcelWorkbook()
Description copied from interface: Workbook
Specifies whether this workbook has an ExcelWorkbook.

Specified by:
hasExcelWorkbook in interface Workbook

addNamedRange

public NamedRange addNamedRange(NamedRange nr)
Description copied from interface: Workbook
Adds a new NamedRange to this workbook. If this workbook allready contained a NamedRange with an equal name, replaces it.

Specified by:
addNamedRange in interface Workbook
Parameters:
nr - the NamedRange to be added to this workbook
Returns:
the given NamedRange

addNamedRange

public NamedRange addNamedRange(String name,
                                String refersTo)
Description copied from interface: Workbook
Adds a new NamedRange to this workbook. Named ranges are usefull when working with formulas.

The string refersTo should be of format [worksheet name]!R1C1:R1C1. If this workbook allready contained a NamedRange with the given name, replaces it.

Specified by:
addNamedRange in interface Workbook
Parameters:
name - The name to apply to the range.
refersTo - A String of R1C1 reference style, including worksheet name.
Returns:
New NamedRange.

getNamedRanges

public Map<String,NamedRange> getNamedRanges()
Description copied from interface: Workbook
Gets all the NamedRanges that were added to this workbook. The map-keys are equal to their names.

Specified by:
getNamedRanges in interface Workbook
Returns:
a map with NamedRanges

addSheet

public Worksheet addSheet()
Description copied from interface: Workbook
Adds a new Worksheet to this workbook. The new sheet will have the name "Sheet[x]", where [x] is a sequential number to prevent the duplication of sheet names. The worksheets cellpointer will be at position row 1, column 1.

Specified by:
addSheet in interface Workbook
Returns:
A new Worksheet.

addSheet

public Worksheet addSheet(String name)
Description copied from interface: Workbook
Adds a new Worksheet to this workbook with the given name as name. The worksheets cellpointer will be at position row 1, column 1.

Specified by:
addSheet in interface Workbook
Parameters:
name - The name that is to be given to the new worksheet.
Returns:
A new Worksheet.

addSheet

public Worksheet addSheet(Worksheet sheet)
Description copied from interface: Workbook
Adds the given Worksheet to this workbook.

Specified by:
addSheet in interface Workbook
Parameters:
sheet - The worksheet to be added.
Returns:
The passed Worksheet.

getWorksheets

public List<Worksheet> getWorksheets()
Description copied from interface: Workbook
Gets a list of all the worksheets in this workbook in display order.

Specified by:
getWorksheets in interface Workbook
Returns:
A list of worksheets.

getSheetNames

public List<String> getSheetNames()
Description copied from interface: Workbook
Gets a list of all the names of worksheets in this workbook in display order. This list may be used to manipulate the display order of sheets. For instance:
              Collections.swap(workbook.getSheetNames(), 0, 2);
will display the first worksheet added to this workbook at position 3.

No objects should be added to this list.

Specified by:
getSheetNames in interface Workbook
Returns:
A list of sheet names.

getWorksheet

public Worksheet getWorksheet(String name)
Description copied from interface: Workbook
Gets the worksheet with the given name.

Specified by:
getWorksheet in interface Workbook
Parameters:
name - The name of the worksheet.
Returns:
The worksheet with the given name or null if no worksheet with that name was in this workbook.

getWorksheetAt

public Worksheet getWorksheetAt(int index)
Description copied from interface: Workbook
Gets the worksheet at the given index. The worksheet index is 0-based.

Specified by:
getWorksheetAt in interface Workbook
Parameters:
index - the worksheet index number
Returns:
the worksheet at the given index or null if no worksheet was at that index

removeSheet

public Worksheet removeSheet(String name)
Description copied from interface: Workbook
Removes the sheet with the given name.

Specified by:
removeSheet in interface Workbook
Parameters:
name - The name of the worksheet to remove.
Returns:
The removed worksheet or null if a worksheet with the given name was not in this workbook.

setPrintElementComments

public void setPrintElementComments(boolean print)
Description copied from interface: Workbook
Sets whether this Workbook's Workbook.createDocument()-method will print comments which were set with XLElement.addElementComment(String).

The default is true.

Specified by:
setPrintElementComments in interface Workbook
See Also:
XLElement.addElementComment(String)

setPrintDocComments

public void setPrintDocComments(boolean print)
Description copied from interface: Workbook
Sets whether this Workbook's Workbook.createDocument()-method will include docComments. DocComments are the comments that will be passed in at the start of the Workbook document, just after the processing instruction.

DocComments can be configured in the configuration file, standard at config/xelem.xml.

The default is true.

Specified by:
setPrintDocComments in interface Workbook
See Also:
XFactory.getDocComments()

isPrintingElementComments

public boolean isPrintingElementComments()
Description copied from interface: Workbook
Specifies whether this Workbook's Workbook.createDocument()-method will include comments.

Specified by:
isPrintingElementComments in interface Workbook

isPrintingDocComments

public boolean isPrintingDocComments()
Description copied from interface: Workbook
Specifies whether this Workbook's Workbook.createDocument()-method will include docComments.

Specified by:
isPrintingDocComments in interface Workbook

getTagName

public String getTagName()
Description copied from interface: XLElement
Gets the tagname (localName) of this XLElement.

Specified by:
getTagName in interface XLElement
Returns:
qualified name

getNameSpace

public String getNameSpace()
Description copied from interface: XLElement
Gets the namespace of this XLElement.

Specified by:
getNameSpace in interface XLElement
Returns:
namespace

getPrefix

public String getPrefix()
Description copied from interface: XLElement
Gets the prefix of this XLElement.

Specified by:
getPrefix in interface XLElement
Returns:
prefix

createDocument

public Document createDocument()
                        throws ParserConfigurationException
Description copied from interface: Workbook
Creates a Document, the structure that holds this Workbook and all of it's children.

During assembly non fatal-errors will be registered as warnings. See Workbook.getWarnings(). A new call to createDocument erases all previous warnings.

Non fatal-errors could be:

Specified by:
createDocument in interface Workbook
Returns:
A Document, representing this workbook.
Throws:
ParserConfigurationException - if the document could not be created.

assemble

public Element assemble(Element root,
                        GIO gio)
Description copied from interface: XLElement
Assembles the state of this XLElement and all of it's children into an Element. Attaches the new element to it's parent-element if needed.

Specified by:
assemble in interface XLElement
Parameters:
root - the parent-element to which the new formed element will be appended
gio - a global information object
Returns:
the newly assembled element. may be null.

getWarnings

public List<String> getWarnings()
Description copied from interface: Workbook
Gets a list of warnings (Strings) that were registered during assembly of this workbook after a call to Workbook.createDocument().

Specified by:
getWarnings in interface Workbook
Returns:
A list of warnings. The list may be empty if no warnings were generated.

xelem.3.0