biz.c24.io.api.presentation.stream
Class SpreadSheetWriter

java.lang.Object
  extended by biz.c24.io.api.presentation.stream.SpreadSheet
      extended by biz.c24.io.api.presentation.stream.SpreadSheetWriter

public class SpreadSheetWriter
extends SpreadSheet

SpreadSheet broker implementation for writing.

Represents the functional part for writing the bounded object tree back to the SpreadSheet. (Provides the inverse for SpreadSheet reader broker.) Additionally to the generic SpreadSheet broker it provides the variety methods for writing the values with respect of their type definitions:

Formula support
The textual data may be interpreted as usual text or as SpreadSheet formula depends on its content. If textual data starts with equal character ("="), it is assumed that text data represents the SpreadSheet formula. So, data will be stored in result workbook as SpreadSheet formula. See also SpreadSheet Formula support disclaimer.

The default sheet resolution procedure creates the sheet "on the fly" if it is not exists. For more details please see the corresponding description.

Version:
$Revision: 18694 $ $Date: 2012-04-10 11:35:16 -0400 (Tue, 10 Apr 2012) $
See Also:
SpreadSheet, SpreadSheetReader

Nested Class Summary
 
Nested classes/interfaces inherited from class biz.c24.io.api.presentation.stream.SpreadSheet
SpreadSheet.Locator
 
Field Summary
static int FORMAT_BIFF
          The BIFF8 format (Office '97) ID.
static int FORMAT_OOXML
          The OOXML format (from Office 2002) ID.
 
Fields inherited from class biz.c24.io.api.presentation.stream.SpreadSheet
ditches, location, workbook
 
Constructor Summary
  SpreadSheetWriter(int format)
          Constructor with format ID.
protected SpreadSheetWriter(org.apache.poi.ss.usermodel.Workbook workbook)
          Constructor with 3rd party workbook instance.
 
Method Summary
protected  org.apache.poi.ss.usermodel.Cell getCellAt(SpreadSheet.Locator position)
          Returns the SpreadSheet cell at specified address.
protected  int resolveSheet(String name)
          Returns the sheet index in workbook used.
 void write(OutputStream stream)
          Sinks the used workbook into output stream.
 void writeBooleanValue(boolean value)
          Writes the boolean data in current cell.
 void writeDateValue(Date value)
          Writes the date data in current cell.
 void writeNullValue()
          Marks the current cell as empty.
 void writeNumericValue(double value)
          Writes the numeric data in current cell.
 void writeStringValue(String value)
          Writes the textual data in current cell.
 
Methods inherited from class biz.c24.io.api.presentation.stream.SpreadSheet
calculateNext, getDitch, getLocation, getSheetName, mark, next, occupy, parse, rollback, setStartLocation, withdraw
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORMAT_BIFF

public static int FORMAT_BIFF
The BIFF8 format (Office '97) ID.


FORMAT_OOXML

public static int FORMAT_OOXML
The OOXML format (from Office 2002) ID.

Constructor Detail

SpreadSheetWriter

public SpreadSheetWriter(int format)
Constructor with format ID.

Constructs the SpreadSheet broker with requested format. The specified format ID is one from allowed.

Parameters:
format - The workbook instance that will be used.

SpreadSheetWriter

protected SpreadSheetWriter(org.apache.poi.ss.usermodel.Workbook workbook)
Constructor with 3rd party workbook instance.

Constructs the SpreadSheet broker instance with provided workbook.

Parameters:
workbook - The workbook implementation that will be used.
Method Detail

writeStringValue

public void writeStringValue(String value)
Writes the textual data in current cell.

Analyse the textual data and write them depends on its value. If value starts from equal character ("="), the value will be written as SpreadSheet formula, otherwise as usual text. See here for details.

Parameters:
value - The text that need to be written.

writeNumericValue

public void writeNumericValue(double value)
Writes the numeric data in current cell.

Parameters:
value - The number that need to be written.

writeDateValue

public void writeDateValue(Date value)
Writes the date data in current cell.

Parameters:
value - The date that need to be written.

writeBooleanValue

public void writeBooleanValue(boolean value)
Writes the boolean data in current cell.

Parameters:
value - The boolean value that need to be written.

writeNullValue

public void writeNullValue()
Marks the current cell as empty.


write

public void write(OutputStream stream)
           throws IOException
Sinks the used workbook into output stream.

Writes the used workbook into provided stream. Client is responsible for resource releasing (stream flush/close).

Parameters:
stream - The output stream for writing the workbook.
Throws:
IOException - If I/O error happened.

getCellAt

protected org.apache.poi.ss.usermodel.Cell getCellAt(SpreadSheet.Locator position)
Returns the SpreadSheet cell at specified address.

Returns the SpreadSheet cell at requested location. If sheet, row or cell is not exist, they will be created.

Parameters:
position - The location (i.e. address) of requested cell.
Returns:
The requested cell instance.

resolveSheet

protected int resolveSheet(String name)
Returns the sheet index in workbook used.

Returns the requested sheet by its name. If provided name is null the current existing sheet index is returned. If requested sheet is not exists, it will be created "on the fly".

Specified by:
resolveSheet in class SpreadSheet
Parameters:
name - The requested sheet name, may be null.
Returns:
The requested sheet index, zero-based.


C24 Technologies © 2002-2012: All Rights Reserved.