adams.core.io
Class ExcelSpreadSheetReader

java.lang.Object
  extended by adams.core.ConsoleObject
      extended by adams.core.option.AbstractOptionHandler
          extended by adams.core.io.AbstractSpreadSheetReader
              extended by adams.core.io.ExcelSpreadSheetReader
All Implemented Interfaces:
adams.core.Debuggable, adams.core.Destroyable, adams.core.option.OptionHandler, adams.core.SizeOfHandler, Serializable

public class ExcelSpreadSheetReader
extends AbstractSpreadSheetReader

Reads MS Excel files.

Valid options are:

-D <int> (property: debugLevel)
    The greater the number the more additional info the scheme may output to
    the console (0 = off).
    default: 0
    minimum: 0
 
-missing <java.lang.String> (property: missingValue)
    The placeholder for missing values.
    default:
 
-sheet <java.lang.String> (property: sheetIndex)
    The index of the sheet to load; An index is a number starting with 1; the
    following placeholders can be used as well: first, second, third, last_2,
     last_1, last
    default: first
 
-no-auto-extend-header (property: autoExtendHeader)
    If enabled, the header gets automatically extended if rows have more cells
    than the header.
 
-text-columns <java.lang.String> (property: textColumns)
    The range of columns to treat as text; A range is a comma-separated list
    of single 1-based indices or sub-ranges of indices ('start-end'); 'inv(..
    .)' inverts the range '...'; the following placeholders can be used as well:
     first, second, third, last_2, last_1, last
    default:
 

Version:
$Revision: 5563 $
Author:
fracpete (fracpete at waikato dot ac dot nz)
See Also:
Serialized Form

Field Summary
protected  boolean m_AutoExtendHeader
          whether to automatically extend the header if rows have more cells than header.
protected  adams.core.Index m_SheetIndex
          the sheet to load.
protected  adams.core.Range m_TextColumns
          the range of columns to force to be text.
 
Fields inherited from class adams.core.io.AbstractSpreadSheetReader
m_MissingValue
 
Fields inherited from class adams.core.option.AbstractOptionHandler
m_DebugLevel, m_OptionManager
 
Constructor Summary
ExcelSpreadSheetReader()
           
 
Method Summary
 String autoExtendHeaderTipText()
          Returns the tip text for this property.
 void defineOptions()
          Adds options to the internal list of options.
protected  SpreadSheet doRead(InputStream in)
          Reads the spreadsheet content from the specified file.
 boolean getAutoExtendHeader()
          Returns whether to extend the header if rows have more cells than the header.
 String getFormatDescription()
          Returns a string describing the format (used in the file chooser).
 String[] getFormatExtensions()
          Returns the extension(s) of the format.
 adams.core.Index getSheetIndex()
          Returns the index of the sheet to load.
 String getTextColumns()
          Returns the range of columns to treat as text.
protected  boolean getUseInputStream()
          Returns whether to read from an InputStream rather than a Reader when using a file name.
 String globalInfo()
          Returns a string describing the object.
protected  void initialize()
          Initializes the members.
protected  String numericToString(org.apache.poi.ss.usermodel.Cell cell)
          Turns a numeric cell into a string.
 void setAutoExtendHeader(boolean value)
          Sets whether to extend the header if rows have more cells than the header.
 void setSheetIndex(adams.core.Index value)
          Sets the index of the sheet to load.
 void setTextColumns(String value)
          Sets the range of columns to treat as text.
 String sheetIndexTipText()
          Returns the tip text for this property.
 String textColumnsTipText()
          Returns the tip text for this property.
 
Methods inherited from class adams.core.io.AbstractSpreadSheetReader
doRead, getMissingValue, getReaders, missingValueTipText, read, read, read, read, setMissingValue
 
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, debug, debug, debugLevelTipText, destroy, finishInit, getDebugLevel, getOptionManager, isDebugOn, newOptionManager, reset, setDebugLevel, toCommandLine, toString
 
Methods inherited from class adams.core.ConsoleObject
getDebugging, getSystemErr, getSystemOut, sizeOf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_SheetIndex

protected adams.core.Index m_SheetIndex
the sheet to load.


m_AutoExtendHeader

protected boolean m_AutoExtendHeader
whether to automatically extend the header if rows have more cells than header.


m_TextColumns

protected adams.core.Range m_TextColumns
the range of columns to force to be text.

Constructor Detail

ExcelSpreadSheetReader

public ExcelSpreadSheetReader()
Method Detail

globalInfo

public String globalInfo()
Returns a string describing the object.

Specified by:
globalInfo in class adams.core.option.AbstractOptionHandler
Returns:
a description suitable for displaying in the gui

defineOptions

public void defineOptions()
Adds options to the internal list of options.

Specified by:
defineOptions in interface adams.core.option.OptionHandler
Overrides:
defineOptions in class AbstractSpreadSheetReader

initialize

protected void initialize()
Initializes the members.

Overrides:
initialize in class adams.core.option.AbstractOptionHandler

getFormatDescription

public String getFormatDescription()
Returns a string describing the format (used in the file chooser).

Specified by:
getFormatDescription in class AbstractSpreadSheetReader
Returns:
a description suitable for displaying in the file chooser

getFormatExtensions

public String[] getFormatExtensions()
Returns the extension(s) of the format.

Specified by:
getFormatExtensions in class AbstractSpreadSheetReader
Returns:
the extension (without the dot!)

setSheetIndex

public void setSheetIndex(adams.core.Index value)
Sets the index of the sheet to load.

Parameters:
value - the index (1-based)

getSheetIndex

public adams.core.Index getSheetIndex()
Returns the index of the sheet to load.

Returns:
the index (1-based)

sheetIndexTipText

public String sheetIndexTipText()
Returns the tip text for this property.

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

setAutoExtendHeader

public void setAutoExtendHeader(boolean value)
Sets whether to extend the header if rows have more cells than the header.

Parameters:
value - if true then the header gets extended if necessary

getAutoExtendHeader

public boolean getAutoExtendHeader()
Returns whether to extend the header if rows have more cells than the header.

Returns:
true if the header gets extended if necessary

autoExtendHeaderTipText

public String autoExtendHeaderTipText()
Returns the tip text for this property.

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

setTextColumns

public void setTextColumns(String value)
Sets the range of columns to treat as text.

Parameters:
value - the range of columns

getTextColumns

public String getTextColumns()
Returns the range of columns to treat as text.

Returns:
the range of columns

textColumnsTipText

public String textColumnsTipText()
Returns the tip text for this property.

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

getUseInputStream

protected boolean getUseInputStream()
Returns whether to read from an InputStream rather than a Reader when using a file name.

Specified by:
getUseInputStream in class AbstractSpreadSheetReader
Returns:
true if to read from an InputStream

numericToString

protected String numericToString(org.apache.poi.ss.usermodel.Cell cell)
Turns a numeric cell into a string. Tries to use "long" representation if possible.

Parameters:
cell - the cell to process
Returns:
the string representation

doRead

protected SpreadSheet doRead(InputStream in)
Reads the spreadsheet content from the specified file.

Overrides:
doRead in class AbstractSpreadSheetReader
Parameters:
in - the input stream to read from
Returns:
the spreadsheet or null in case of an error


Copyright © 2012 University of Waikato, Hamilton, NZ. All Rights Reserved.