Some OOXML implementation and interface code, just some basic Row and Cell-level functionality.

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@612495 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ugo Cei 2008-01-16 16:08:22 +00:00
parent 290aa0c9f4
commit 0859571ede
26 changed files with 5610 additions and 0 deletions

View File

@ -0,0 +1,264 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
import java.util.Calendar;
import java.util.Date;
public interface Cell {
/**
* Numeric Cell type (0)
* @see #setCellType(int)
* @see #getCellType()
*/
public final static int CELL_TYPE_NUMERIC = 0;
/**
* String Cell type (1)
* @see #setCellType(int)
* @see #getCellType()
*/
public final static int CELL_TYPE_STRING = 1;
/**
* Formula Cell type (2)
* @see #setCellType(int)
* @see #getCellType()
*/
public final static int CELL_TYPE_FORMULA = 2;
/**
* Blank Cell type (3)
* @see #setCellType(int)
* @see #getCellType()
*/
public final static int CELL_TYPE_BLANK = 3;
/**
* Boolean Cell type (4)
* @see #setCellType(int)
* @see #getCellType()
*/
public final static int CELL_TYPE_BOOLEAN = 4;
/**
* Error Cell type (5)
* @see #setCellType(int)
* @see #getCellType()
*/
public final static int CELL_TYPE_ERROR = 5;
/**
* set the cell's number within the row (0 based)
* @param num short the cell number
*/
void setCellNum(short num);
/**
* get the cell's number within the row
* @return short reperesenting the column number (logical!)
*/
short getCellNum();
/**
* set the cells type (numeric, formula or string)
* @see #CELL_TYPE_NUMERIC
* @see #CELL_TYPE_STRING
* @see #CELL_TYPE_FORMULA
* @see #CELL_TYPE_BLANK
* @see #CELL_TYPE_BOOLEAN
* @see #CELL_TYPE_ERROR
*/
void setCellType(int cellType);
/**
* get the cells type (numeric, formula or string)
* @see #CELL_TYPE_STRING
* @see #CELL_TYPE_NUMERIC
* @see #CELL_TYPE_FORMULA
* @see #CELL_TYPE_BOOLEAN
* @see #CELL_TYPE_ERROR
*/
int getCellType();
/**
* set a numeric value for the cell
*
* @param value the numeric value to set this cell to. For formulas we'll set the
* precalculated value, for numerics we'll set its value. For other types we
* will change the cell to a numeric cell and set its value.
*/
void setCellValue(double value);
/**
* set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as
* a date.
*
* @param value the date value to set this cell to. For formulas we'll set the
* precalculated value, for numerics we'll set its value. For other types we
* will change the cell to a numeric cell and set its value.
*/
void setCellValue(Date value);
/**
* set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as
* a date.
*
* @param value the date value to set this cell to. For formulas we'll set the
* precalculated value, for numerics we'll set its value. For othertypes we
* will change the cell to a numeric cell and set its value.
*/
void setCellValue(Calendar value);
/**
* set a string value for the cell. Please note that if you are using
* full 16 bit unicode you should call <code>setEncoding()</code> first.
*
* @param value value to set the cell to. For formulas we'll set the formula
* string, for String cells we'll set its value. For other types we will
* change the cell to a string cell and set its value.
* If value is null then we will change the cell to a Blank cell.
*/
void setCellValue(RichTextString value);
void setCellFormula(String formula);
String getCellFormula();
/**
* get the value of the cell as a number. For strings we throw an exception.
* For blank cells we return a 0.
*/
double getNumericCellValue();
/**
* get the value of the cell as a date. For strings we throw an exception.
* For blank cells we return a null.
*/
Date getDateCellValue();
/**
* get the value of the cell as a string - for numeric cells we throw an exception.
* For blank cells we return an empty string.
* For formulaCells that are not string Formulas, we return empty String
*/
RichTextString getRichStringCellValue();
/**
* set a boolean value for the cell
*
* @param value the boolean value to set this cell to. For formulas we'll set the
* precalculated value, for booleans we'll set its value. For other types we
* will change the cell to a boolean cell and set its value.
*/
void setCellValue(boolean value);
/**
* set a error value for the cell
*
* @param value the error value to set this cell to. For formulas we'll set the
* precalculated value ??? IS THIS RIGHT??? , for errors we'll set
* its value. For other types we will change the cell to an error
* cell and set its value.
*/
void setCellErrorValue(byte value);
/**
* get the value of the cell as a boolean. For strings, numbers, and errors, we throw an exception.
* For blank cells we return a false.
*/
boolean getBooleanCellValue();
/**
* get the value of the cell as an error code. For strings, numbers, and booleans, we throw an exception.
* For blank cells we return a 0.
*/
byte getErrorCellValue();
/**
* set the style for the cell. The style should be an HSSFCellStyle created/retreived from
* the HSSFWorkbook.
*
* @param style reference contained in the workbook
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createCellStyle()
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getCellStyleAt(short)
*/
void setCellStyle(CellStyle style);
/**
* get the style for the cell. This is a reference to a cell style contained in the workbook
* object.
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getCellStyleAt(short)
*/
CellStyle getCellStyle();
/**
* Sets this cell as the active cell for the worksheet
*/
void setAsActiveCell();
/**
* Returns a string representation of the cell
*
* This method returns a simple representation,
* anthing more complex should be in user code, with
* knowledge of the semantics of the sheet being processed.
*
* Formula cells return the formula string,
* rather than the formula result.
* Dates are displayed in dd-MMM-yyyy format
* Errors are displayed as #ERR&lt;errIdx&gt;
*/
String toString();
/**
* Assign a comment to this cell
*
* @param comment comment associated with this cell
*/
void setCellComment(Comment comment);
/**
* Returns comment associated with this cell
*
* @return comment associated with this cell
*/
Comment getCellComment();
}

View File

@ -0,0 +1,704 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
public interface CellStyle {
/**
* general (normal) horizontal alignment
*/
public final static short ALIGN_GENERAL = 0x0;
/**
* left-justified horizontal alignment
*/
public final static short ALIGN_LEFT = 0x1;
/**
* center horizontal alignment
*/
public final static short ALIGN_CENTER = 0x2;
/**
* right-justified horizontal alignment
*/
public final static short ALIGN_RIGHT = 0x3;
/**
* fill? horizontal alignment
*/
public final static short ALIGN_FILL = 0x4;
/**
* justified horizontal alignment
*/
public final static short ALIGN_JUSTIFY = 0x5;
/**
* center-selection? horizontal alignment
*/
public final static short ALIGN_CENTER_SELECTION = 0x6;
/**
* top-aligned vertical alignment
*/
public final static short VERTICAL_TOP = 0x0;
/**
* center-aligned vertical alignment
*/
public final static short VERTICAL_CENTER = 0x1;
/**
* bottom-aligned vertical alignment
*/
public final static short VERTICAL_BOTTOM = 0x2;
/**
* vertically justified vertical alignment
*/
public final static short VERTICAL_JUSTIFY = 0x3;
/**
* No border
*/
public final static short BORDER_NONE = 0x0;
/**
* Thin border
*/
public final static short BORDER_THIN = 0x1;
/**
* Medium border
*/
public final static short BORDER_MEDIUM = 0x2;
/**
* dash border
*/
public final static short BORDER_DASHED = 0x3;
/**
* dot border
*/
public final static short BORDER_HAIR = 0x4;
/**
* Thick border
*/
public final static short BORDER_THICK = 0x5;
/**
* double-line border
*/
public final static short BORDER_DOUBLE = 0x6;
/**
* hair-line border
*/
public final static short BORDER_DOTTED = 0x7;
/**
* Medium dashed border
*/
public final static short BORDER_MEDIUM_DASHED = 0x8;
/**
* dash-dot border
*/
public final static short BORDER_DASH_DOT = 0x9;
/**
* medium dash-dot border
*/
public final static short BORDER_MEDIUM_DASH_DOT = 0xA;
/**
* dash-dot-dot border
*/
public final static short BORDER_DASH_DOT_DOT = 0xB;
/**
* medium dash-dot-dot border
*/
public final static short BORDER_MEDIUM_DASH_DOT_DOT = 0xC;
/**
* slanted dash-dot border
*/
public final static short BORDER_SLANTED_DASH_DOT = 0xD;
/** No background */
public final static short NO_FILL = 0;
/** Solidly filled */
public final static short SOLID_FOREGROUND = 1;
/** Small fine dots */
public final static short FINE_DOTS = 2;
/** Wide dots */
public final static short ALT_BARS = 3;
/** Sparse dots */
public final static short SPARSE_DOTS = 4;
/** Thick horizontal bands */
public final static short THICK_HORZ_BANDS = 5;
/** Thick vertical bands */
public final static short THICK_VERT_BANDS = 6;
/** Thick backward facing diagonals */
public final static short THICK_BACKWARD_DIAG = 7;
/** Thick forward facing diagonals */
public final static short THICK_FORWARD_DIAG = 8;
/** Large spots */
public final static short BIG_SPOTS = 9;
/** Brick-like layout */
public final static short BRICKS = 10;
/** Thin horizontal bands */
public final static short THIN_HORZ_BANDS = 11;
/** Thin vertical bands */
public final static short THIN_VERT_BANDS = 12;
/** Thin backward diagonal */
public final static short THIN_BACKWARD_DIAG = 13;
/** Thin forward diagonal */
public final static short THIN_FORWARD_DIAG = 14;
/** Squares */
public final static short SQUARES = 15;
/** Diamonds */
public final static short DIAMONDS = 16;
/** Less Dots */
public final static short LESS_DOTS = 17;
/** Least Dots */
public final static short LEAST_DOTS = 18;
/**
* get the index within the HSSFWorkbook (sequence within the collection of ExtnededFormat objects)
* @return unique index number of the underlying record this style represents (probably you don't care
* unless you're comparing which one is which)
*/
short getIndex();
/**
* set the data format (must be a valid format)
* @see org.apache.poi.hssf.usermodel.HSSFDataFormat
*/
void setDataFormat(short fmt);
/**
* get the index of the format
* @see org.apache.poi.hssf.usermodel.HSSFDataFormat
*/
short getDataFormat();
/**
* Get the contents of the format string, by looking up
* the DataFormat against the supplied workbook
* @see org.apache.poi.hssf.usermodel.HSSFDataFormat
* XXX Commented out because it uses internal implementation Workbook class.
*
String getDataFormatString(Workbook workbook);
*/
/**
* set the font for this style
* @param font a font object created or retreived from the HSSFWorkbook object
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createFont()
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)
*/
void setFont(Font font);
/**
* gets the index of the font for this style
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)
*/
short getFontIndex();
/**
* gets the font for this style
* @param parentWorkbook The HSSFWorkbook that this style belongs to
* @see org.apache.poi.hssf.usermodel.HSSFCellStyle#getFontIndex()
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)
*/
Font getFont(Workbook parentWorkbook);
/**
* set the cell's using this style to be hidden
* @param hidden - whether the cell using this style should be hidden
*/
void setHidden(boolean hidden);
/**
* get whether the cell's using this style are to be hidden
* @return hidden - whether the cell using this style should be hidden
*/
boolean getHidden();
/**
* set the cell's using this style to be locked
* @param locked - whether the cell using this style should be locked
*/
void setLocked(boolean locked);
/**
* get whether the cell's using this style are to be locked
* @return hidden - whether the cell using this style should be locked
*/
boolean getLocked();
/**
* set the type of horizontal alignment for the cell
* @param align - the type of alignment
* @see #ALIGN_GENERAL
* @see #ALIGN_LEFT
* @see #ALIGN_CENTER
* @see #ALIGN_RIGHT
* @see #ALIGN_FILL
* @see #ALIGN_JUSTIFY
* @see #ALIGN_CENTER_SELECTION
*/
void setAlignment(short align);
/**
* get the type of horizontal alignment for the cell
* @return align - the type of alignment
* @see #ALIGN_GENERAL
* @see #ALIGN_LEFT
* @see #ALIGN_CENTER
* @see #ALIGN_RIGHT
* @see #ALIGN_FILL
* @see #ALIGN_JUSTIFY
* @see #ALIGN_CENTER_SELECTION
*/
short getAlignment();
/**
* set whether the text should be wrapped
* @param wrapped wrap text or not
*/
void setWrapText(boolean wrapped);
/**
* get whether the text should be wrapped
* @return wrap text or not
*/
boolean getWrapText();
/**
* set the type of vertical alignment for the cell
* @param align the type of alignment
* @see #VERTICAL_TOP
* @see #VERTICAL_CENTER
* @see #VERTICAL_BOTTOM
* @see #VERTICAL_JUSTIFY
*/
void setVerticalAlignment(short align);
/**
* get the type of vertical alignment for the cell
* @return align the type of alignment
* @see #VERTICAL_TOP
* @see #VERTICAL_CENTER
* @see #VERTICAL_BOTTOM
* @see #VERTICAL_JUSTIFY
*/
short getVerticalAlignment();
/**
* set the degree of rotation for the text in the cell
* @param rotation degrees (between -90 and 90 degrees)
*/
void setRotation(short rotation);
/**
* get the degree of rotation for the text in the cell
* @return rotation degrees (between -90 and 90 degrees)
*/
short getRotation();
/**
* set the number of spaces to indent the text in the cell
* @param indent - number of spaces
*/
void setIndention(short indent);
/**
* get the number of spaces to indent the text in the cell
* @return indent - number of spaces
*/
short getIndention();
/**
* set the type of border to use for the left border of the cell
* @param border type
* @see #BORDER_NONE
* @see #BORDER_THIN
* @see #BORDER_MEDIUM
* @see #BORDER_DASHED
* @see #BORDER_DOTTED
* @see #BORDER_THICK
* @see #BORDER_DOUBLE
* @see #BORDER_HAIR
* @see #BORDER_MEDIUM_DASHED
* @see #BORDER_DASH_DOT
* @see #BORDER_MEDIUM_DASH_DOT
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
*/
void setBorderLeft(short border);
/**
* get the type of border to use for the left border of the cell
* @return border type
* @see #BORDER_NONE
* @see #BORDER_THIN
* @see #BORDER_MEDIUM
* @see #BORDER_DASHED
* @see #BORDER_DOTTED
* @see #BORDER_THICK
* @see #BORDER_DOUBLE
* @see #BORDER_HAIR
* @see #BORDER_MEDIUM_DASHED
* @see #BORDER_DASH_DOT
* @see #BORDER_MEDIUM_DASH_DOT
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
*/
short getBorderLeft();
/**
* set the type of border to use for the right border of the cell
* @param border type
* @see #BORDER_NONE
* @see #BORDER_THIN
* @see #BORDER_MEDIUM
* @see #BORDER_DASHED
* @see #BORDER_DOTTED
* @see #BORDER_THICK
* @see #BORDER_DOUBLE
* @see #BORDER_HAIR
* @see #BORDER_MEDIUM_DASHED
* @see #BORDER_DASH_DOT
* @see #BORDER_MEDIUM_DASH_DOT
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
*/
void setBorderRight(short border);
/**
* get the type of border to use for the right border of the cell
* @return border type
* @see #BORDER_NONE
* @see #BORDER_THIN
* @see #BORDER_MEDIUM
* @see #BORDER_DASHED
* @see #BORDER_DOTTED
* @see #BORDER_THICK
* @see #BORDER_DOUBLE
* @see #BORDER_HAIR
* @see #BORDER_MEDIUM_DASHED
* @see #BORDER_DASH_DOT
* @see #BORDER_MEDIUM_DASH_DOT
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
*/
short getBorderRight();
/**
* set the type of border to use for the top border of the cell
* @param border type
* @see #BORDER_NONE
* @see #BORDER_THIN
* @see #BORDER_MEDIUM
* @see #BORDER_DASHED
* @see #BORDER_DOTTED
* @see #BORDER_THICK
* @see #BORDER_DOUBLE
* @see #BORDER_HAIR
* @see #BORDER_MEDIUM_DASHED
* @see #BORDER_DASH_DOT
* @see #BORDER_MEDIUM_DASH_DOT
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
*/
void setBorderTop(short border);
/**
* get the type of border to use for the top border of the cell
* @return border type
* @see #BORDER_NONE
* @see #BORDER_THIN
* @see #BORDER_MEDIUM
* @see #BORDER_DASHED
* @see #BORDER_DOTTED
* @see #BORDER_THICK
* @see #BORDER_DOUBLE
* @see #BORDER_HAIR
* @see #BORDER_MEDIUM_DASHED
* @see #BORDER_DASH_DOT
* @see #BORDER_MEDIUM_DASH_DOT
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
*/
short getBorderTop();
/**
* set the type of border to use for the bottom border of the cell
* @param border type
* @see #BORDER_NONE
* @see #BORDER_THIN
* @see #BORDER_MEDIUM
* @see #BORDER_DASHED
* @see #BORDER_DOTTED
* @see #BORDER_THICK
* @see #BORDER_DOUBLE
* @see #BORDER_HAIR
* @see #BORDER_MEDIUM_DASHED
* @see #BORDER_DASH_DOT
* @see #BORDER_MEDIUM_DASH_DOT
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
*/
void setBorderBottom(short border);
/**
* get the type of border to use for the bottom border of the cell
* @return border type
* @see #BORDER_NONE
* @see #BORDER_THIN
* @see #BORDER_MEDIUM
* @see #BORDER_DASHED
* @see #BORDER_DOTTED
* @see #BORDER_THICK
* @see #BORDER_DOUBLE
* @see #BORDER_HAIR
* @see #BORDER_MEDIUM_DASHED
* @see #BORDER_DASH_DOT
* @see #BORDER_MEDIUM_DASH_DOT
* @see #BORDER_DASH_DOT_DOT
* @see #BORDER_MEDIUM_DASH_DOT_DOT
* @see #BORDER_SLANTED_DASH_DOT
*/
short getBorderBottom();
/**
* set the color to use for the left border
* @param color The index of the color definition
*/
void setLeftBorderColor(short color);
/**
* get the color to use for the left border
* @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
* @param color The index of the color definition
*/
short getLeftBorderColor();
/**
* set the color to use for the right border
* @param color The index of the color definition
*/
void setRightBorderColor(short color);
/**
* get the color to use for the left border
* @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
* @param color The index of the color definition
*/
short getRightBorderColor();
/**
* set the color to use for the top border
* @param color The index of the color definition
*/
void setTopBorderColor(short color);
/**
* get the color to use for the top border
* @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
* @param color The index of the color definition
*/
short getTopBorderColor();
/**
* set the color to use for the bottom border
* @param color The index of the color definition
*/
void setBottomBorderColor(short color);
/**
* get the color to use for the left border
* @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
* @param color The index of the color definition
*/
short getBottomBorderColor();
/**
* setting to one fills the cell with the foreground color... No idea about
* other values
*
* @see #NO_FILL
* @see #SOLID_FOREGROUND
* @see #FINE_DOTS
* @see #ALT_BARS
* @see #SPARSE_DOTS
* @see #THICK_HORZ_BANDS
* @see #THICK_VERT_BANDS
* @see #THICK_BACKWARD_DIAG
* @see #THICK_FORWARD_DIAG
* @see #BIG_SPOTS
* @see #BRICKS
* @see #THIN_HORZ_BANDS
* @see #THIN_VERT_BANDS
* @see #THIN_BACKWARD_DIAG
* @see #THIN_FORWARD_DIAG
* @see #SQUARES
* @see #DIAMONDS
*
* @param fp fill pattern (set to 1 to fill w/foreground color)
*/
void setFillPattern(short fp);
/**
* get the fill pattern (??) - set to 1 to fill with foreground color
* @return fill pattern
*/
short getFillPattern();
/**
* set the background fill color.
* <p>
* For example:
* <pre>
* cs.setFillPattern(HSSFCellStyle.FINE_DOTS );
* cs.setFillBackgroundColor(new HSSFColor.RED().getIndex());
* </pre>
* optionally a Foreground and background fill can be applied:
* <i>Note: Ensure Foreground color is set prior to background</i>
* <pre>
* cs.setFillPattern(HSSFCellStyle.FINE_DOTS );
* cs.setFillForegroundColor(new HSSFColor.BLUE().getIndex());
* cs.setFillBackgroundColor(new HSSFColor.RED().getIndex());
* </pre>
* or, for the special case of SOLID_FILL:
* <pre>
* cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND );
* cs.setFillForegroundColor(new HSSFColor.RED().getIndex());
* </pre>
* It is necessary to set the fill style in order
* for the color to be shown in the cell.
*
* @param bg color
*/
void setFillBackgroundColor(short bg);
/**
* get the background fill color
* @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
* @return fill color
*/
short getFillBackgroundColor();
/**
* set the foreground fill color
* <i>Note: Ensure Foreground color is set prior to background color.</i>
* @param bg color
*/
void setFillForegroundColor(short bg);
/**
* get the foreground fill color
* @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
* @return fill color
*/
short getFillForegroundColor();
}

View File

@ -0,0 +1,40 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
public interface Color {
/**
* @return index to the standard palette
*/
short getIndex();
/**
* @return triplet representation like that in Excel
*/
short[] getTriplet();
/**
* @return a hex string exactly like a gnumeric triplet
*/
String getHexString();
}

View File

@ -0,0 +1,86 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
public interface Comment {
/**
* Returns whether this comment is visible.
*
* @param visible <code>true</code> if the comment is visible, <code>false</code> otherwise
*/
void setVisible(boolean visible);
/**
* Sets whether this comment is visible.
*
* @return <code>true</code> if the comment is visible, <code>false</code> otherwise
*/
boolean isVisible();
/**
* Return the row of the cell that contains the comment
*
* @return the 0-based row of the cell that contains the comment
*/
int getRow();
/**
* Set the row of the cell that contains the comment
*
* @param row the 0-based row of the cell that contains the comment
*/
void setRow(int row);
/**
* Return the column of the cell that contains the comment
*
* @return the 0-based column of the cell that contains the comment
*/
short getColumn();
/**
* Set the column of the cell that contains the comment
*
* @param col the 0-based column of the cell that contains the comment
*/
void setColumn(short col);
/**
* Name of the original comment author
*
* @return the name of the original author of the comment
*/
String getAuthor();
/**
* Name of the original comment author
*
* @param author the name of the original author of the comment
*/
void setAuthor(String author);
/**
* Sets the rich text string used by this comment.
*
* @param string Sets the rich text string used by this object.
*/
void setString(RichTextString string);
}

View File

@ -0,0 +1,39 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
public interface DataFormat {
/**
* get the format index that matches the given format string.
* Creates a new format if one is not found. Aliases text to the proper format.
* @param format string matching a built in format
* @return index of format.
*/
short getFormat(String format);
/**
* get the format string that matches the given format index
* @param index of a format
* @return string represented at index of format or null if there is not a format at that index
*/
String getFormat(short index);
}

View File

@ -0,0 +1,301 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
public interface Font {
/**
* Arial font
*/
public final static String FONT_ARIAL = "Arial";
/**
* Normal boldness (not bold)
*/
public final static short BOLDWEIGHT_NORMAL = 0x190;
/**
* Bold boldness (bold)
*/
public final static short BOLDWEIGHT_BOLD = 0x2bc;
/**
* normal type of black color.
*/
public final static short COLOR_NORMAL = 0x7fff;
/**
* Dark Red color
*/
public final static short COLOR_RED = 0xa;
/**
* no type offsetting (not super or subscript)
*/
public final static short SS_NONE = 0;
/**
* superscript
*/
public final static short SS_SUPER = 1;
/**
* subscript
*/
public final static short SS_SUB = 2;
/**
* not underlined
*/
public final static byte U_NONE = 0;
/**
* single (normal) underline
*/
public final static byte U_SINGLE = 1;
/**
* double underlined
*/
public final static byte U_DOUBLE = 2;
/**
* accounting style single underline
*/
public final static byte U_SINGLE_ACCOUNTING = 0x21;
/**
* accounting style double underline
*/
public final static byte U_DOUBLE_ACCOUNTING = 0x22;
/**
* ANSI character set
*/
public final static byte ANSI_CHARSET = 0;
/**
* Default character set.
*/
public final static byte DEFAULT_CHARSET = 1;
/**
* Symbol character set
*/
public final static byte SYMBOL_CHARSET = 2;
/**
* set the name for the font (i.e. Arial)
* @param name String representing the name of the font to use
* @see #FONT_ARIAL
*/
void setFontName(String name);
/**
* get the name for the font (i.e. Arial)
* @return String representing the name of the font to use
* @see #FONT_ARIAL
*/
String getFontName();
/**
* get the index within the HSSFWorkbook (sequence within the collection of Font objects)
* @return unique index number of the underlying record this Font represents (probably you don't care
* unless you're comparing which one is which)
*/
short getIndex();
/**
* set the font height in unit's of 1/20th of a point. Maybe you might want to
* use the setFontHeightInPoints which matches to the familiar 10, 12, 14 etc..
* @param height height in 1/20ths of a point
* @see #setFontHeightInPoints(short)
*/
void setFontHeight(short height);
/**
* set the font height
* @param height height in the familiar unit of measure - points
* @see #setFontHeight(short)
*/
void setFontHeightInPoints(short height);
/**
* get the font height in unit's of 1/20th of a point. Maybe you might want to
* use the getFontHeightInPoints which matches to the familiar 10, 12, 14 etc..
* @return short - height in 1/20ths of a point
* @see #getFontHeightInPoints()
*/
short getFontHeight();
/**
* get the font height
* @return short - height in the familiar unit of measure - points
* @see #getFontHeight()
*/
short getFontHeightInPoints();
/**
* set whether to use italics or not
* @param italic italics or not
*/
void setItalic(boolean italic);
/**
* get whether to use italics or not
* @return italics or not
*/
boolean getItalic();
/**
* set whether to use a strikeout horizontal line through the text or not
* @param strikeout or not
*/
void setStrikeout(boolean strikeout);
/**
* get whether to use a strikeout horizontal line through the text or not
* @return strikeout or not
*/
boolean getStrikeout();
/**
* set the color for the font
* @param color to use
* @see #COLOR_NORMAL Note: Use this rather than HSSFColor.AUTOMATIC for default font color
* @see #COLOR_RED
*/
void setColor(short color);
/**
* get the color for the font
* @return color to use
* @see #COLOR_NORMAL
* @see #COLOR_RED
* @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
*/
short getColor();
/**
* set the boldness to use
* @param boldweight
* @see #BOLDWEIGHT_NORMAL
* @see #BOLDWEIGHT_BOLD
*/
void setBoldweight(short boldweight);
/**
* get the boldness to use
* @return boldweight
* @see #BOLDWEIGHT_NORMAL
* @see #BOLDWEIGHT_BOLD
*/
short getBoldweight();
/**
* set normal,super or subscript.
* @param offset type to use (none,super,sub)
* @see #SS_NONE
* @see #SS_SUPER
* @see #SS_SUB
*/
void setTypeOffset(short offset);
/**
* get normal,super or subscript.
* @return offset type to use (none,super,sub)
* @see #SS_NONE
* @see #SS_SUPER
* @see #SS_SUB
*/
short getTypeOffset();
/**
* set type of text underlining to use
* @param underline type
* @see #U_NONE
* @see #U_SINGLE
* @see #U_DOUBLE
* @see #U_SINGLE_ACCOUNTING
* @see #U_DOUBLE_ACCOUNTING
*/
void setUnderline(byte underline);
/**
* get type of text underlining to use
* @return underlining type
* @see #U_NONE
* @see #U_SINGLE
* @see #U_DOUBLE
* @see #U_SINGLE_ACCOUNTING
* @see #U_DOUBLE_ACCOUNTING
*/
byte getUnderline();
/**
* get character-set to use.
* @return character-set
* @see #ANSI_CHARSET
* @see #DEFAULT_CHARSET
* @see #SYMBOL_CHARSET
*/
byte getCharSet();
/**
* set character-set to use.
* @see #ANSI_CHARSET
* @see #DEFAULT_CHARSET
* @see #SYMBOL_CHARSET
*/
void setCharSet(byte charset);
String toString();
}

View File

@ -0,0 +1,58 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
public interface Footer {
/**
* Get the left side of the footer.
* @return The string representing the left side.
*/
String getLeft();
/**
* Sets the left string.
* @param newLeft The string to set as the left side.
*/
void setLeft(String newLeft);
/**
* Get the center of the footer.
* @return The string representing the center.
*/
String getCenter();
/**
* Sets the center string.
* @param newCenter The string to set as the center.
*/
void setCenter(String newCenter);
/**
* Get the right side of the footer.
* @return The string representing the right side.
*/
String getRight();
/**
* Sets the right string.
* @param newRight The string to set as the right side.
*/
void setRight(String newRight);
}

View File

@ -0,0 +1,64 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
public interface Header {
/**
* Get the left side of the header.
*
* @return The string representing the left side.
*/
String getLeft();
/**
* Sets the left string.
*
* @param newLeft The string to set as the left side.
*/
void setLeft(String newLeft);
/**
* Get the center of the header.
*
* @return The string representing the center.
*/
String getCenter();
/**
* Sets the center string.
*
* @param newCenter The string to set as the center.
*/
void setCenter(String newCenter);
/**
* Get the right side of the header.
*
* @return The string representing the right side.
*/
String getRight();
/**
* Sets the right string.
*
* @param newRight The string to set as the right side.
*/
void setRight(String newRight);
}

View File

@ -0,0 +1,56 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
public interface Name {
/** Get the sheets name which this named range is referenced to
* @return sheet name, which this named range refered to
*/
String getSheetName();
/**
* gets the name of the named range
* @return named range name
*/
String getNameName();
/**
* sets the name of the named range
* @param nameName named range name to set
*/
void setNameName(String nameName);
/**
* gets the reference of the named range
* @return reference of the named range
*/
String getReference();
/**
* sets the reference of this named range
* @param ref the reference to set
*/
void setReference(String ref);
}

View File

@ -0,0 +1,75 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
public interface Palette {
/**
* Retrieves the color at a given index
*
* @param index the palette index, between 0x8 to 0x40 inclusive
* @return the color, or null if the index is not populated
*/
Color getColor(short index);
/**
* Finds the first occurance of a given color
*
* @param red the RGB red component, between 0 and 255 inclusive
* @param green the RGB green component, between 0 and 255 inclusive
* @param blue the RGB blue component, between 0 and 255 inclusive
* @return the color, or null if the color does not exist in this palette
*/
Color findColor(byte red, byte green, byte blue);
/**
* Finds the closest matching color in the custom palette. The
* method for finding the distance between the colors is fairly
* primative.
*
* @param red The red component of the color to match.
* @param green The green component of the color to match.
* @param blue The blue component of the color to match.
* @return The closest color or null if there are no custom
* colors currently defined.
*/
Color findSimilarColor(byte red, byte green, byte blue);
/**
* Sets the color at the given offset
*
* @param index the palette index, between 0x8 to 0x40 inclusive
* @param red the RGB red component, between 0 and 255 inclusive
* @param green the RGB green component, between 0 and 255 inclusive
* @param blue the RGB blue component, between 0 and 255 inclusive
*/
void setColorAtIndex(short index, byte red, byte green, byte blue);
/**
* Adds a new color into an empty color slot.
* @param red The red component
* @param green The green component
* @param blue The blue component
*
* @return The new custom color.
*
* @throws RuntimeException if there are more more free color indexes.
*/
Color addColor(byte red, byte green, byte blue);
}

View File

@ -0,0 +1,124 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFAnchor;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFComment;
import org.apache.poi.hssf.usermodel.HSSFPicture;
import org.apache.poi.hssf.usermodel.HSSFPolygon;
import org.apache.poi.hssf.usermodel.HSSFShapeGroup;
import org.apache.poi.hssf.usermodel.HSSFSimpleShape;
import org.apache.poi.hssf.usermodel.HSSFTextbox;
public interface Patriarch {
/**
* Creates a new group record stored under this patriarch.
*
* @param anchor the client anchor describes how this group is attached
* to the sheet.
* @return the newly created group.
*/
HSSFShapeGroup createGroup(HSSFClientAnchor anchor);
/**
* Creates a simple shape. This includes such shapes as lines, rectangles,
* and ovals.
*
* @param anchor the client anchor describes how this group is attached
* to the sheet.
* @return the newly created shape.
*/
HSSFSimpleShape createSimpleShape(HSSFClientAnchor anchor);
/**
* Creates a picture.
*
* @param anchor the client anchor describes how this group is attached
* to the sheet.
* @return the newly created shape.
*/
HSSFPicture createPicture(HSSFClientAnchor anchor, int pictureIndex);
/**
* Creates a polygon
*
* @param anchor the client anchor describes how this group is attached
* to the sheet.
* @return the newly created shape.
*/
HSSFPolygon createPolygon(HSSFClientAnchor anchor);
/**
* Constructs a textbox under the patriarch.
*
* @param anchor the client anchor describes how this group is attached
* to the sheet.
* @return the newly created textbox.
*/
HSSFTextbox createTextbox(HSSFClientAnchor anchor);
/**
* Constructs a cell comment.
*
* @param anchor the client anchor describes how this comment is attached
* to the sheet.
* @return the newly created comment.
*/
HSSFComment createComment(HSSFAnchor anchor);
/**
* Returns a list of all shapes contained by the patriarch.
*/
List getChildren();
/**
* Total count of all children and their children's children.
*/
int countOfAllChildren();
/**
* Sets the coordinate space of this group. All children are contrained
* to these coordinates.
*/
void setCoordinates(int x1, int y1, int x2, int y2);
/**
* The top left x coordinate of this group.
*/
int getX1();
/**
* The top left y coordinate of this group.
*/
int getY1();
/**
* The bottom right x coordinate of this group.
*/
int getX2();
/**
* The bottom right y coordinate of this group.
*/
int getY2();
}

View File

@ -0,0 +1,268 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
public interface PrintSetup {
public static final short LETTER_PAPERSIZE = 1;
public static final short LEGAL_PAPERSIZE = 5;
public static final short EXECUTIVE_PAPERSIZE = 7;
public static final short A4_PAPERSIZE = 9;
public static final short A5_PAPERSIZE = 11;
public static final short ENVELOPE_10_PAPERSIZE = 20;
public static final short ENVELOPE_DL_PAPERSIZE = 27;
public static final short ENVELOPE_CS_PAPERSIZE = 28;
public static final short ENVELOPE_MONARCH_PAPERSIZE = 37;
/**
* Set the paper size.
* @param size the paper size.
*/
void setPaperSize(short size);
/**
* Set the scale.
* @param scale the scale to use
*/
void setScale(short scale);
/**
* Set the page numbering start.
* @param start the page numbering start
*/
void setPageStart(short start);
/**
* Set the number of pages wide to fit the sheet in
* @param width the number of pages
*/
void setFitWidth(short width);
/**
* Set the number of pages high to fit the sheet in
* @param height the number of pages
*/
void setFitHeight(short height);
/**
* Sets the options flags. Not advisable to do it directly.
* @param options The bit flags for the options
*/
void setOptions(short options);
/**
* Set whether to go left to right or top down in ordering
* @param ltor left to right
*/
void setLeftToRight(boolean ltor);
/**
* Set whether to print in landscape
* @param ls landscape
*/
void setLandscape(boolean ls);
/**
* Valid settings. I'm not for sure.
* @param valid Valid
*/
void setValidSettings(boolean valid);
/**
* Set whether it is black and white
* @param mono Black and white
*/
void setNoColor(boolean mono);
/**
* Set whether it is in draft mode
* @param d draft
*/
void setDraft(boolean d);
/**
* Print the include notes
* @param printnotes print the notes
*/
void setNotes(boolean printnotes);
/**
* Set no orientation. ?
* @param orientation Orientation.
*/
void setNoOrientation(boolean orientation);
/**
* Set whether to use page start
* @param page Use page start
*/
void setUsePage(boolean page);
/**
* Sets the horizontal resolution.
* @param resolution horizontal resolution
*/
void setHResolution(short resolution);
/**
* Sets the vertical resolution.
* @param resolution vertical resolution
*/
void setVResolution(short resolution);
/**
* Sets the header margin.
* @param headermargin header margin
*/
void setHeaderMargin(double headermargin);
/**
* Sets the footer margin.
* @param footermargin footer margin
*/
void setFooterMargin(double footermargin);
/**
* Sets the number of copies.
* @param copies number of copies
*/
void setCopies(short copies);
/**
* Returns the paper size.
* @return paper size
*/
short getPaperSize();
/**
* Returns the scale.
* @return scale
*/
short getScale();
/**
* Returns the page start.
* @return page start
*/
short getPageStart();
/**
* Returns the number of pages wide to fit sheet in.
* @return number of pages wide to fit sheet in
*/
short getFitWidth();
/**
* Returns the number of pages high to fit the sheet in.
* @return number of pages high to fit the sheet in
*/
short getFitHeight();
/**
* Returns the bit flags for the options.
* @return bit flags for the options
*/
short getOptions();
/**
* Returns the left to right print order.
* @return left to right print order
*/
boolean getLeftToRight();
/**
* Returns the landscape mode.
* @return landscape mode
*/
boolean getLandscape();
/**
* Returns the valid settings.
* @return valid settings
*/
boolean getValidSettings();
/**
* Returns the black and white setting.
* @return black and white setting
*/
boolean getNoColor();
/**
* Returns the draft mode.
* @return draft mode
*/
boolean getDraft();
/**
* Returns the print notes.
* @return print notes
*/
boolean getNotes();
/**
* Returns the no orientation.
* @return no orientation
*/
boolean getNoOrientation();
/**
* Returns the use page numbers.
* @return use page numbers
*/
boolean getUsePage();
/**
* Returns the horizontal resolution.
* @return horizontal resolution
*/
short getHResolution();
/**
* Returns the vertical resolution.
* @return vertical resolution
*/
short getVResolution();
/**
* Returns the header margin.
* @return header margin
*/
double getHeaderMargin();
/**
* Returns the footer margin.
* @return footer margin
*/
double getFooterMargin();
/**
* Returns the number of copies.
* @return number of copies
*/
short getCopies();
}

View File

@ -0,0 +1,117 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
public interface RichTextString {
/** Place holder for indicating that NO_FONT has been applied here */
public static final short NO_FONT = 0;
/**
* Applies a font to the specified characters of a string.
*
* @param startIndex The start index to apply the font to (inclusive)
* @param endIndex The end index to apply the font to (exclusive)
* @param fontIndex The font to use.
*/
void applyFont(int startIndex, int endIndex, short fontIndex);
/**
* Applies a font to the specified characters of a string.
*
* @param startIndex The start index to apply the font to (inclusive)
* @param endIndex The end index to apply to font to (exclusive)
* @param font The index of the font to use.
*/
void applyFont(int startIndex, int endIndex, Font font);
/**
* Sets the font of the entire string.
* @param font The font to use.
*/
void applyFont(Font font);
/**
* Removes any formatting that may have been applied to the string.
*/
void clearFormatting();
/**
* Returns the plain string representation.
*/
String getString();
/**
* @return the number of characters in the font.
*/
int length();
/**
* Returns the font in use at a particular index.
*
* @param index The index.
* @return The font that's currently being applied at that
* index or null if no font is being applied or the
* index is out of range.
*/
short getFontAtIndex(int index);
/**
* @return The number of formatting runs used. There will always be at
* least one of font NO_FONT.
*
* @see #NO_FONT
*/
int numFormattingRuns();
/**
* The index within the string to which the specified formatting run applies.
* @param index the index of the formatting run
* @return the index within the string.
*/
int getIndexOfFormattingRun(int index);
/**
* Gets the font used in a particular formatting run.
*
* @param index the index of the formatting run
* @return the font number used.
*/
short getFontOfFormattingRun(int index);
/**
* Compares one rich text string to another.
*/
int compareTo(Object o);
boolean equals(Object o);
/**
* @return the plain text representation of this string.
*/
String toString();
/**
* Applies the specified font to the entire string.
*
* @param fontIndex the font to apply.
*/
void applyFont(short fontIndex);
}

View File

@ -0,0 +1,158 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
import java.util.Iterator;
public interface Row {
// used for collections
public final static int INITIAL_CAPACITY = 5;
/**
* Use this to create new cells within the row and return it.
* <p>
* The cell that is returned is a CELL_TYPE_BLANK. The type can be changed
* either through calling <code>setCellValue</code> or <code>setCellType</code>.
*
* @param column - the column number this cell represents
*
* @return HSSFCell a high level representation of the created cell.
*/
Cell createCell(short column);
/**
* Use this to create new cells within the row and return it.
* <p>
* The cell that is returned is a CELL_TYPE_BLANK. The type can be changed
* either through calling setCellValue or setCellType.
*
* @param column - the column number this cell represents
*
* @return HSSFCell a high level representation of the created cell.
*/
Cell createCell(short column, int type);
/**
* remove the HSSFCell from this row.
* @param cell to remove
*/
void removeCell(Cell cell);
/**
* set the row number of this row.
* @param rowNum the row number (0-based)
* @throws IndexOutOfBoundsException if the row number is not within the range 0-65535.
*/
void setRowNum(int rowNum);
/**
* get row number this row represents
* @return the row number (0 based)
*/
int getRowNum();
/**
* get the hssfcell representing a given column (logical cell) 0-based. If you
* ask for a cell that is not defined....you get a null.
*
* @param cellnum 0 based column number
* @return HSSFCell representing that column or null if undefined.
*/
Cell getCell(short cellnum);
/**
* get the number of the first cell contained in this row.
* @return short representing the first logical cell in the row, or -1 if the row does not contain any cells.
*/
short getFirstCellNum();
/**
* gets the number of the last cell contained in this row <b>PLUS ONE</b>.
* @return short representing the last logical cell in the row <b>PLUS ONE</b>, or -1 if the row does not contain any cells.
*/
short getLastCellNum();
/**
* gets the number of defined cells (NOT number of cells in the actual row!).
* That is to say if only columns 0,4,5 have values then there would be 3.
* @return int representing the number of defined cells in the row.
*/
int getPhysicalNumberOfCells();
/**
* set the row's height or set to ff (-1) for undefined/default-height. Set the height in "twips" or
* 1/20th of a point.
* @param height rowheight or 0xff for undefined (use sheet default)
*/
void setHeight(short height);
/**
* set whether or not to display this row with 0 height
* @param zHeight height is zero or not.
*/
void setZeroHeight(boolean zHeight);
/**
* get whether or not to display this row with 0 height
* @return - zHeight height is zero or not.
*/
boolean getZeroHeight();
/**
* set the row's height in points.
* @param height row height in points
*/
void setHeightInPoints(float height);
/**
* get the row's height or ff (-1) for undefined/default-height in twips (1/20th of a point)
* @return rowheight or 0xff for undefined (use sheet default)
*/
short getHeight();
/**
* get the row's height or ff (-1) for undefined/default-height in points (20*getHeight())
* @return rowheight or 0xff for undefined (use sheet default)
*/
float getHeightInPoints();
/**
* @return cell iterator of the physically defined cells. Note element 4 may
* actually be row cell depending on how many are defined!
*/
Iterator cellIterator();
int compareTo(Object obj);
boolean equals(Object obj);
}

View File

@ -0,0 +1,40 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
/**
* Allows the getting and saving of shared strings
*/
public interface SharedStringSource {
/**
* Return the string at position <code>idx</idx> (0-based) in this source.
*
* @param idx String position.
* @return The string, or null if not found.
*/
public String getSharedStringAt(int idx);
/**
* Store a string in this source.
*
* @param s The string to store.
* @return The 0-based position of the newly added string.
*/
public int putSharedString(String s);
}

View File

@ -0,0 +1,727 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
import java.util.Iterator;
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
import org.apache.poi.hssf.util.PaneInformation;
import org.apache.poi.hssf.util.Region;
public interface Sheet {
/* Constants for margins */
public static final short LeftMargin = Sheet.LeftMargin;
public static final short RightMargin = Sheet.RightMargin;
public static final short TopMargin = Sheet.TopMargin;
public static final short BottomMargin = Sheet.BottomMargin;
public static final byte PANE_LOWER_RIGHT = (byte) 0;
public static final byte PANE_UPPER_RIGHT = (byte) 1;
public static final byte PANE_LOWER_LEFT = (byte) 2;
public static final byte PANE_UPPER_LEFT = (byte) 3;
/**
* Used for compile-time optimization. This is the initial size for the collection of
* rows. It is currently set to 20. If you generate larger sheets you may benefit
* by setting this to a higher number and recompiling a custom edition of HSSFSheet.
*/
public final static int INITIAL_CAPACITY = 20;
/**
* Create a new row within the sheet and return the high level representation
*
* @param rownum row number
* @return High level HSSFRow object representing a row in the sheet
* @see org.apache.poi.hssf.usermodel.HSSFRow
* @see #removeRow(HSSFRow)
*/
Row createRow(int rownum);
/**
* Remove a row from this sheet. All cells contained in the row are removed as well
*
* @param row representing a row to remove.
*/
void removeRow(Row row);
/**
* Returns the logical row (not physical) 0-based. If you ask for a row that is not
* defined you get a null. This is to say row 4 represents the fifth row on a sheet.
* @param rownum row to get
* @return HSSFRow representing the rownumber or null if its not defined on the sheet
*/
Row getRow(int rownum);
/**
* Returns the number of phsyically defined rows (NOT the number of rows in the sheet)
*/
int getPhysicalNumberOfRows();
/**
* gets the first row on the sheet
* @return the number of the first logical row on the sheet
*/
int getFirstRowNum();
/**
* gets the last row on the sheet
* @return last row contained n this sheet.
*/
int getLastRowNum();
/**
* Get the visibility state for a given column.
* @param column - the column to get (0-based)
* @param hidden - the visiblity state of the column
*/
void setColumnHidden(short column, boolean hidden);
/**
* Get the hidden state for a given column.
* @param column - the column to set (0-based)
* @return hidden - the visiblity state of the column
*/
boolean isColumnHidden(short column);
/**
* set the width (in units of 1/256th of a character width)
* @param column - the column to set (0-based)
* @param width - the width in units of 1/256th of a character width
*/
void setColumnWidth(short column, short width);
/**
* get the width (in units of 1/256th of a character width )
* @param column - the column to set (0-based)
* @return width - the width in units of 1/256th of a character width
*/
short getColumnWidth(short column);
/**
* get the default column width for the sheet (if the columns do not define their own width) in
* characters
* @return default column width
*/
short getDefaultColumnWidth();
/**
* get the default row height for the sheet (if the rows do not define their own height) in
* twips (1/20 of a point)
* @return default row height
*/
short getDefaultRowHeight();
/**
* get the default row height for the sheet (if the rows do not define their own height) in
* points.
* @return default row height in points
*/
float getDefaultRowHeightInPoints();
/**
* set the default column width for the sheet (if the columns do not define their own width) in
* characters
* @param width default column width
*/
void setDefaultColumnWidth(short width);
/**
* set the default row height for the sheet (if the rows do not define their own height) in
* twips (1/20 of a point)
* @param height default row height
*/
void setDefaultRowHeight(short height);
/**
* set the default row height for the sheet (if the rows do not define their own height) in
* points
* @param height default row height
*/
void setDefaultRowHeightInPoints(float height);
/**
* get whether gridlines are printed.
* @return true if printed
*/
boolean isGridsPrinted();
/**
* set whether gridlines printed.
* @param value false if not printed.
*/
void setGridsPrinted(boolean value);
/**
* adds a merged region of cells (hence those cells form one)
* @param region (rowfrom/colfrom-rowto/colto) to merge
* @return index of this region
*/
int addMergedRegion(Region region);
/**
* determines whether the output is vertically centered on the page.
* @param value true to vertically center, false otherwise.
*/
void setVerticallyCenter(boolean value);
/**
* Determine whether printed output for this sheet will be vertically centered.
*/
boolean getVerticallyCenter(boolean value);
/**
* determines whether the output is horizontally centered on the page.
* @param value true to horizontally center, false otherwise.
*/
void setHorizontallyCenter(boolean value);
/**
* Determine whether printed output for this sheet will be horizontally centered.
*/
boolean getHorizontallyCenter();
/**
* removes a merged region of cells (hence letting them free)
* @param index of the region to unmerge
*/
void removeMergedRegion(int index);
/**
* returns the number of merged regions
* @return number of merged regions
*/
int getNumMergedRegions();
/**
* gets the region at a particular index
* @param index of the region to fetch
* @return the merged region (simple eh?)
*/
Region getMergedRegionAt(int index);
/**
* @return an iterator of the PHYSICAL rows. Meaning the 3rd element may not
* be the third row if say for instance the second row is undefined.
*/
Iterator rowIterator();
/**
* whether alternate expression evaluation is on
* @param b alternative expression evaluation or not
*/
void setAlternativeExpression(boolean b);
/**
* whether alternative formula entry is on
* @param b alternative formulas or not
*/
void setAlternativeFormula(boolean b);
/**
* show automatic page breaks or not
* @param b whether to show auto page breaks
*/
void setAutobreaks(boolean b);
/**
* set whether sheet is a dialog sheet or not
* @param b isDialog or not
*/
void setDialog(boolean b);
/**
* set whether to display the guts or not
*
* @param b guts or no guts (or glory)
*/
void setDisplayGuts(boolean b);
/**
* fit to page option is on
* @param b fit or not
*/
void setFitToPage(boolean b);
/**
* set if row summaries appear below detail in the outline
* @param b below or not
*/
void setRowSumsBelow(boolean b);
/**
* set if col summaries appear right of the detail in the outline
* @param b right or not
*/
void setRowSumsRight(boolean b);
/**
* whether alternate expression evaluation is on
* @return alternative expression evaluation or not
*/
boolean getAlternateExpression();
/**
* whether alternative formula entry is on
* @return alternative formulas or not
*/
boolean getAlternateFormula();
/**
* show automatic page breaks or not
* @return whether to show auto page breaks
*/
boolean getAutobreaks();
/**
* get whether sheet is a dialog sheet or not
* @return isDialog or not
*/
boolean getDialog();
/**
* get whether to display the guts or not
*
* @return guts or no guts (or glory)
*/
boolean getDisplayGuts();
/**
* fit to page option is on
* @return fit or not
*/
boolean getFitToPage();
/**
* get if row summaries appear below detail in the outline
* @return below or not
*/
boolean getRowSumsBelow();
/**
* get if col summaries appear right of the detail in the outline
* @return right or not
*/
boolean getRowSumsRight();
/**
* Returns whether gridlines are printed.
* @return Gridlines are printed
*/
boolean isPrintGridlines();
/**
* Turns on or off the printing of gridlines.
* @param newPrintGridlines boolean to turn on or off the printing of
* gridlines
*/
void setPrintGridlines(boolean newPrintGridlines);
/**
* Gets the print setup object.
* @return The user model for the print setup object.
*/
PrintSetup getPrintSetup();
/**
* Gets the user model for the document header.
* @return The Document header.
*/
Header getHeader();
/**
* Gets the user model for the document footer.
* @return The Document footer.
*/
Footer getFooter();
/**
* Sets whether sheet is selected.
* @param sel Whether to select the sheet or deselect the sheet.
*/
void setSelected(boolean sel);
/**
* Gets the size of the margin in inches.
* @param margin which margin to get
* @return the size of the margin
*/
double getMargin(short margin);
/**
* Sets the size of the margin in inches.
* @param margin which margin to get
* @param size the size of the margin
*/
void setMargin(short margin, double size);
/**
* Answer whether protection is enabled or disabled
* @return true => protection enabled; false => protection disabled
*/
boolean getProtect();
/**
* @return hashed password
*/
short getPassword();
/**
* Answer whether object protection is enabled or disabled
* @return true => protection enabled; false => protection disabled
*/
boolean getObjectProtect();
/**
* Answer whether scenario protection is enabled or disabled
* @return true => protection enabled; false => protection disabled
*/
boolean getScenarioProtect();
/**
* Sets the protection on enabled or disabled
* @param protect true => protection enabled; false => protection disabled
* @deprecated use protectSheet(String, boolean, boolean)
*/
void setProtect(boolean protect);
/**
* Sets the protection enabled as well as the password
* @param password to set for protection
*/
void protectSheet(String password);
/**
* Sets the zoom magnication for the sheet. The zoom is expressed as a
* fraction. For example to express a zoom of 75% use 3 for the numerator
* and 4 for the denominator.
*
* @param numerator The numerator for the zoom magnification.
* @param denominator The denominator for the zoom magnification.
*/
void setZoom(int numerator, int denominator);
/**
* The top row in the visible view when the sheet is
* first viewed after opening it in a viewer
* @return short indicating the rownum (0 based) of the top row
*/
short getTopRow();
/**
* The left col in the visible view when the sheet is
* first viewed after opening it in a viewer
* @return short indicating the rownum (0 based) of the top row
*/
short getLeftCol();
/**
* Sets desktop window pane display area, when the
* file is first opened in a viewer.
* @param toprow the top row to show in desktop window pane
* @param leftcol the left column to show in desktop window pane
*/
void showInPane(short toprow, short leftcol);
/**
* Shifts rows between startRow and endRow n number of rows.
* If you use a negative number, it will shift rows up.
* Code ensures that rows don't wrap around.
*
* Calls shiftRows(startRow, endRow, n, false, false);
*
* <p>
* Additionally shifts merged regions that are completely defined in these
* rows (ie. merged 2 cells on a row to be shifted).
* @param startRow the row to start shifting
* @param endRow the row to end shifting
* @param n the number of rows to shift
*/
void shiftRows(int startRow, int endRow, int n);
/**
* Shifts rows between startRow and endRow n number of rows.
* If you use a negative number, it will shift rows up.
* Code ensures that rows don't wrap around
*
* <p>
* Additionally shifts merged regions that are completely defined in these
* rows (ie. merged 2 cells on a row to be shifted).
* <p>
* TODO Might want to add bounds checking here
* @param startRow the row to start shifting
* @param endRow the row to end shifting
* @param n the number of rows to shift
* @param copyRowHeight whether to copy the row height during the shift
* @param resetOriginalRowHeight whether to set the original row's height to the default
*/
void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight);
/**
* Creates a split (freezepane). Any existing freezepane or split pane is overwritten.
* @param colSplit Horizonatal position of split.
* @param rowSplit Vertical position of split.
* @param topRow Top row visible in bottom pane
* @param leftmostColumn Left column visible in right pane.
*/
void createFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow);
/**
* Creates a split (freezepane). Any existing freezepane or split pane is overwritten.
* @param colSplit Horizonatal position of split.
* @param rowSplit Vertical position of split.
*/
void createFreezePane(int colSplit, int rowSplit);
/**
* Creates a split pane. Any existing freezepane or split pane is overwritten.
* @param xSplitPos Horizonatal position of split (in 1/20th of a point).
* @param ySplitPos Vertical position of split (in 1/20th of a point).
* @param topRow Top row visible in bottom pane
* @param leftmostColumn Left column visible in right pane.
* @param activePane Active pane. One of: PANE_LOWER_RIGHT,
* PANE_UPPER_RIGHT, PANE_LOWER_LEFT, PANE_UPPER_LEFT
* @see #PANE_LOWER_LEFT
* @see #PANE_LOWER_RIGHT
* @see #PANE_UPPER_LEFT
* @see #PANE_UPPER_RIGHT
*/
void createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane);
/**
* Returns the information regarding the currently configured pane (split or freeze).
* @return null if no pane configured, or the pane information.
*/
PaneInformation getPaneInformation();
/**
* Sets whether the gridlines are shown in a viewer.
* @param show whether to show gridlines or not
*/
void setDisplayGridlines(boolean show);
/**
* Returns if gridlines are displayed.
* @return whether gridlines are displayed
*/
boolean isDisplayGridlines();
/**
* Sets whether the formulas are shown in a viewer.
* @param show whether to show formulas or not
*/
void setDisplayFormulas(boolean show);
/**
* Returns if formulas are displayed.
* @return whether formulas are displayed
*/
boolean isDisplayFormulas();
/**
* Sets whether the RowColHeadings are shown in a viewer.
* @param show whether to show RowColHeadings or not
*/
void setDisplayRowColHeadings(boolean show);
/**
* Returns if RowColHeadings are displayed.
* @return whether RowColHeadings are displayed
*/
boolean isDisplayRowColHeadings();
/**
* Sets a page break at the indicated row
* @param row FIXME: Document this!
*/
void setRowBreak(int row);
/**
* Determines if there is a page break at the indicated row
* @param row FIXME: Document this!
* @return FIXME: Document this!
*/
boolean isRowBroken(int row);
/**
* Removes the page break at the indicated row
* @param row
*/
void removeRowBreak(int row);
/**
* Retrieves all the horizontal page breaks
* @return all the horizontal page breaks, or null if there are no row page breaks
*/
int[] getRowBreaks();
/**
* Retrieves all the vertical page breaks
* @return all the vertical page breaks, or null if there are no column page breaks
*/
short[] getColumnBreaks();
/**
* Sets a page break at the indicated column
* @param column
*/
void setColumnBreak(short column);
/**
* Determines if there is a page break at the indicated column
* @param column FIXME: Document this!
* @return FIXME: Document this!
*/
boolean isColumnBroken(short column);
/**
* Removes a page break at the indicated column
* @param column
*/
void removeColumnBreak(short column);
/**
* Aggregates the drawing records and dumps the escher record hierarchy
* to the standard output.
*/
void dumpDrawingRecords(boolean fat);
/**
* Creates the toplevel drawing patriarch. This will have the effect of
* removing any existing drawings on this sheet.
*
* @return The new patriarch.
*/
Patriarch createDrawingPatriarch();
/**
* Expands or collapses a column group.
*
* @param columnNumber One of the columns in the group.
* @param collapsed true = collapse group, false = expand group.
*/
void setColumnGroupCollapsed(short columnNumber, boolean collapsed);
/**
* Create an outline for the provided column range.
*
* @param fromColumn beginning of the column range.
* @param toColumn end of the column range.
*/
void groupColumn(short fromColumn, short toColumn);
void ungroupColumn(short fromColumn, short toColumn);
void groupRow(int fromRow, int toRow);
void ungroupRow(int fromRow, int toRow);
void setRowGroupCollapsed(int row, boolean collapse);
/**
* Sets the default column style for a given column. POI will only apply this style to new cells added to the sheet.
*
* @param column the column index
* @param style the style to set
*/
void setDefaultColumnStyle(short column, CellStyle style);
/**
* Adjusts the column width to fit the contents.
*
* This process can be relatively slow on large sheets, so this should
* normally only be called once per column, at the end of your
* processing.
*
* @param column the column index
*/
void autoSizeColumn(short column);
/**
* Returns cell comment for the specified row and column
*
* @return cell comment or <code>null</code> if not found
*/
Comment getCellComment(int row, int column);
}

View File

@ -0,0 +1,74 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
public interface Textbox {
public final static short OBJECT_TYPE_TEXT = 6;
/**
* @return the rich text string for this textbox.
*/
RichTextString getString();
/**
* @param string Sets the rich text string used by this object.
*/
void setString(RichTextString string);
/**
* @return Returns the left margin within the textbox.
*/
int getMarginLeft();
/**
* Sets the left margin within the textbox.
*/
void setMarginLeft(int marginLeft);
/**
* @return returns the right margin within the textbox.
*/
int getMarginRight();
/**
* Sets the right margin within the textbox.
*/
void setMarginRight(int marginRight);
/**
* @return returns the top margin within the textbox.
*/
int getMarginTop();
/**
* Sets the top margin within the textbox.
*/
void setMarginTop(int marginTop);
/**
* Gets the bottom margin within the textbox.
*/
int getMarginBottom();
/**
* Sets the bottom margin within the textbox.
*/
void setMarginBottom(int marginBottom);
}

View File

@ -0,0 +1,458 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
public interface Workbook {
/**
* used for compile-time performance/memory optimization. This determines the
* initial capacity for the sheet collection. Its currently set to 3.
* Changing it in this release will decrease performance
* since you're never allowed to have more or less than three sheets!
*/
public final static int INITIAL_CAPACITY = 3;
/** Extended windows meta file */
public static final int PICTURE_TYPE_EMF = 2;
/** Windows Meta File */
public static final int PICTURE_TYPE_WMF = 3;
/** Mac PICT format */
public static final int PICTURE_TYPE_PICT = 4;
/** JPEG format */
public static final int PICTURE_TYPE_JPEG = 5;
/** PNG format */
public static final int PICTURE_TYPE_PNG = 6;
/** Device independant bitmap */
public static final int PICTURE_TYPE_DIB = 7;
/**
* sets the order of appearance for a given sheet.
*
* @param sheetname the name of the sheet to reorder
* @param pos the position that we want to insert the sheet into (0 based)
*/
void setSheetOrder(String sheetname, int pos);
/**
* sets the tab whose data is actually seen when the sheet is opened.
* This may be different from the "selected sheet" since excel seems to
* allow you to show the data of one sheet when another is seen "selected"
* in the tabs (at the bottom).
* @see org.apache.poi.hssf.usermodel.HSSFSheet#setSelected(boolean)
* @param index
*/
void setSelectedTab(short index);
/**
* gets the tab whose data is actually seen when the sheet is opened.
* This may be different from the "selected sheet" since excel seems to
* allow you to show the data of one sheet when another is seen "selected"
* in the tabs (at the bottom).
* @see org.apache.poi.hssf.usermodel.HSSFSheet#setSelected(boolean)
*/
short getSelectedTab();
/**
* sets the first tab that is displayed in the list of tabs
* in excel.
* @param index
*/
void setDisplayedTab(short index);
/**
* sets the first tab that is displayed in the list of tabs
* in excel.
*/
short getDisplayedTab();
/**
* @deprecated POI will now properly handle unicode strings without
* forceing an encoding
*/
public final static byte ENCODING_COMPRESSED_UNICODE = 0;
/**
* @deprecated POI will now properly handle unicode strings without
* forceing an encoding
*/
public final static byte ENCODING_UTF_16 = 1;
/**
* set the sheet name.
* Will throw IllegalArgumentException if the name is greater than 31 chars
* or contains /\?*[]
* @param sheet number (0 based)
*/
void setSheetName(int sheet, String name);
/**
* set the sheet name forcing the encoding. Forcing the encoding IS A BAD IDEA!!!
* @deprecated 3-Jan-2006 POI now automatically detects unicode and sets the encoding
* appropriately. Simply use setSheetName(int sheet, String encoding)
* @throws IllegalArgumentException if the name is greater than 31 chars
* or contains /\?*[]
* @param sheet number (0 based)
*/
void setSheetName(int sheet, String name, short encoding);
/**
* get the sheet name
* @param sheet Number
* @return Sheet name
*/
String getSheetName(int sheet);
/** Returns the index of the sheet by his name
* @param name the sheet name
* @return index of the sheet (0 based)
*/
int getSheetIndex(String name);
/** Returns the index of the given sheet
* @param sheet the sheet to look up
* @return index of the sheet (0 based)
*/
int getSheetIndex(Sheet sheet);
/**
* create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns
* the high level representation. Use this to create new sheets.
*
* @return HSSFSheet representing the new sheet.
*/
Sheet createSheet();
/**
* create an HSSFSheet from an existing sheet in the HSSFWorkbook.
*
* @return HSSFSheet representing the cloned sheet.
*/
Sheet cloneSheet(int sheetNum);
/**
* create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns
* the high level representation. Use this to create new sheets.
*
* @param sheetname sheetname to set for the sheet.
* @return HSSFSheet representing the new sheet.
*/
Sheet createSheet(String sheetname);
/**
* get the number of spreadsheets in the workbook (this will be three after serialization)
* @return number of sheets
*/
int getNumberOfSheets();
/**
* Get the HSSFSheet object at the given index.
* @param index of the sheet number (0-based physical & logical)
* @return HSSFSheet at the provided index
*/
Sheet getSheetAt(int index);
/**
* Get sheet with the given name
* @param name of the sheet
* @return HSSFSheet with the name provided or null if it does not exist
*/
Sheet getSheet(String name);
/**
* removes sheet at the given index
* @param index of the sheet (0-based)
*/
void removeSheetAt(int index);
/**
* determine whether the Excel GUI will backup the workbook when saving.
*
* @param backupValue true to indicate a backup will be performed.
*/
void setBackupFlag(boolean backupValue);
/**
* determine whether the Excel GUI will backup the workbook when saving.
*
* @return the current setting for backups.
*/
boolean getBackupFlag();
/**
* Sets the repeating rows and columns for a sheet (as found in
* File->PageSetup->Sheet). This is function is included in the workbook
* because it creates/modifies name records which are stored at the
* workbook level.
* <p>
* To set just repeating columns:
* <pre>
* workbook.setRepeatingRowsAndColumns(0,0,1,-1-1);
* </pre>
* To set just repeating rows:
* <pre>
* workbook.setRepeatingRowsAndColumns(0,-1,-1,0,4);
* </pre>
* To remove all repeating rows and columns for a sheet.
* <pre>
* workbook.setRepeatingRowsAndColumns(0,-1,-1,-1,-1);
* </pre>
*
* @param sheetIndex 0 based index to sheet.
* @param startColumn 0 based start of repeating columns.
* @param endColumn 0 based end of repeating columns.
* @param startRow 0 based start of repeating rows.
* @param endRow 0 based end of repeating rows.
*/
void setRepeatingRowsAndColumns(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow);
/**
* create a new Font and add it to the workbook's font table
* @return new font object
*/
Font createFont();
/**
* Finds a font that matches the one with the supplied attributes
*/
Font findFont(short boldWeight, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline);
/**
* get the number of fonts in the font table
* @return number of fonts
*/
short getNumberOfFonts();
/**
* get the font at the given index number
* @param idx index number
* @return HSSFFont at the index
*/
Font getFontAt(short idx);
/**
* create a new Cell style and add it to the workbook's style table
* @return the new Cell Style object
*/
CellStyle createCellStyle();
/**
* get the number of styles the workbook contains
* @return count of cell styles
*/
short getNumCellStyles();
/**
* get the cell style object at the given index
* @param idx index within the set of styles
* @return HSSFCellStyle object at the index
*/
CellStyle getCellStyleAt(short idx);
/**
* Method write - write out this workbook to an Outputstream. Constructs
* a new POI POIFSFileSystem, passes in the workbook binary representation and
* writes it out.
*
* @param stream - the java OutputStream you wish to write the XLS to
*
* @exception IOException if anything can't be written.
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
*/
void write(OutputStream stream) throws IOException;
/**
* Method getBytes - get the bytes of just the HSSF portions of the XLS file.
* Use this to construct a POI POIFSFileSystem yourself.
*
*
* @return byte[] array containing the binary representation of this workbook and all contained
* sheets, rows, cells, etc.
*
* @see org.apache.poi.hssf.model.Workbook
* @see org.apache.poi.hssf.model.Sheet
*/
byte[] getBytes();
/** @deprecated Do not call this method from your applications. Use the methods
* available in the HSSFRow to add string HSSFCells
*/
int addSSTString(String string);
/** @deprecated Do not call this method from your applications. Use the methods
* available in the HSSFRow to get string HSSFCells
*/
String getSSTString(int index);
/** gets the total number of named ranges in the workboko
* @return number of named ranges
*/
int getNumberOfNames();
/** gets the Named range
* @param index position of the named range
* @return named range high level
*/
Name getNameAt(int index);
/** gets the named range name
* @param index the named range index (0 based)
* @return named range name
*/
String getNameName(int index);
/**
* Sets the printarea for the sheet provided
* <p>
* i.e. Reference = $A$1:$B$2
* @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
* @param reference Valid name Reference for the Print Area
*/
void setPrintArea(int sheetIndex, String reference);
/**
* For the Convenience of Java Programmers maintaining pointers.
* @see #setPrintArea(int, String)
* @param sheetIndex Zero-based sheet index (0 = First Sheet)
* @param startColumn Column to begin printarea
* @param endColumn Column to end the printarea
* @param startRow Row to begin the printarea
* @param endRow Row to end the printarea
*/
void setPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow);
/**
* Retrieves the reference for the printarea of the specified sheet, the sheet name is appended to the reference even if it was not specified.
* @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
* @return String Null if no print area has been defined
*/
String getPrintArea(int sheetIndex);
/**
* Delete the printarea for the sheet specified
* @param sheetIndex Zero-based sheet index (0 = First Sheet)
*/
void removePrintArea(int sheetIndex);
/** creates a new named range and add it to the model
* @return named range high level
*/
Name createName();
/** gets the named range index by his name
* <i>Note:</i>Excel named ranges are case-insensitive and
* this method performs a case-insensitive search.
*
* @param name named range name
* @return named range index
*/
int getNameIndex(String name);
/** remove the named range by his index
* @param index named range index (0 based)
*/
void removeName(int index);
/**
* Returns the instance of HSSFDataFormat for this workbook.
* @return the HSSFDataFormat object
* @see org.apache.poi.hssf.record.FormatRecord
* @see org.apache.poi.hssf.record.Record
*/
DataFormat createDataFormat();
/** remove the named range by his name
* @param name named range name
*/
void removeName(String name);
Palette getCustomPalette();
/** Test only. Do not use */
void insertChartRecord();
/**
* Spits out a list of all the drawing records in the workbook.
*/
void dumpDrawingGroupRecords(boolean fat);
/**
* Adds a picture to the workbook.
*
* @param pictureData The bytes of the picture
* @param format The format of the picture. One of <code>PICTURE_TYPE_*</code>
*
* @return the index to this picture (1 based).
*/
int addPicture(byte[] pictureData, int format);
/**
* Gets all pictures from the Workbook.
*
* @return the list of pictures (a list of {@link HSSFPictureData} objects.)
*/
List getAllPictures();
/**
* protect a workbook with a password (not encypted, just sets writeprotect
* flags and the password.
* @param password to set
*/
void writeProtectWorkbook(String password, String username);
/**
* removes the write protect flag
*/
void unwriteProtectWorkbook();
/**
* Gets all embedded OLE2 objects from the Workbook.
*
* @return the list of embedded objects (a list of {@link HSSFObjectData} objects.)
*/
List getAllEmbeddedObjects();
}

View File

@ -0,0 +1,126 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.xssf.strings;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.LinkedList;
import org.apache.poi.ss.usermodel.SharedStringSource;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlOptions;
import org.openxml4j.opc.PackagePart;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSst;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.SstDocument;
/**
* Table of strings shared across all sheets in a workbook.
*
* FIXME: I don't like having a dependency on PackagePart (from OpenXML4J) in model classes.
* I'd rather let Workbook keep track of all part-document relationships and keep all other
* classes clean. -- Ugo
*
* @version $Id$
*/
public class SharedStringsTable implements SharedStringSource {
private final LinkedList<String> strings = new LinkedList<String>();
private PackagePart part;
/**
* Create a new SharedStringsTable by reading it from a PackagePart.
*
* @param part The PackagePart to read.
* @throws IOException if an error occurs while reading.
*/
public SharedStringsTable(PackagePart part) throws IOException {
this.part = part;
InputStream is = part.getInputStream();
try {
readFrom(is);
} finally {
if (is != null) is.close();
}
}
/**
* Read this shared strings table from an XML file.
*
* @param is The input stream containing the XML document.
* @throws IOException if an error occurs while reading.
*/
public void readFrom(InputStream is) throws IOException {
try {
SstDocument doc = SstDocument.Factory.parse(is);
for (CTRst rst : doc.getSst().getSiArray()) {
strings.add(rst.getT());
}
} catch (XmlException e) {
throw new IOException(e.getLocalizedMessage());
}
}
public String getSharedStringAt(int idx) {
return strings.get(idx);
}
public synchronized int putSharedString(String s) {
if (strings.contains(s)) {
return strings.indexOf(s);
}
strings.add(s);
return strings.size() - 1;
}
/**
* Save this table to its own PackagePart.
*
* @throws IOException if an error occurs while writing.
*/
public void save() throws IOException {
OutputStream out = this.part.getOutputStream();
try {
writeTo(out);
} finally {
out.close();
}
}
/**
* Write this table out as XML.
*
* @param out The stream to write to.
* @throws IOException if an error occurs while writing.
*/
public void writeTo(OutputStream out) throws IOException {
XmlOptions options = new XmlOptions();
options.setSaveOuter();
SstDocument doc = SstDocument.Factory.newInstance(options);
CTSst sst = doc.addNewSst();
sst.setCount(strings.size());
sst.setUniqueCount(strings.size());
for (String s : strings) {
sst.addNewSi().setT(s);
}
doc.save(out);
}
}

View File

@ -0,0 +1,268 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.xssf.usermodel;
import java.util.Calendar;
import java.util.Date;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.usermodel.SharedStringSource;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType;
public class XSSFCell implements Cell {
private static final String FALSE_AS_STRING = "0";
private static final String TRUE_AS_STRING = "1";
private final CTCell cell;
private final XSSFRow row;
private SharedStringSource sharedStringSource;
private short cellNum;
/**
* Create a new XSSFCell. This method is protected to be used only by
* tests.
*/
protected XSSFCell(XSSFRow row) {
this(row, CTCell.Factory.newInstance());
}
public XSSFCell(XSSFRow row, CTCell cell) {
this.cell = cell;
this.row = row;
}
protected void setSharedStringSource(SharedStringSource sharedStringSource) {
this.sharedStringSource = sharedStringSource;
}
public boolean getBooleanCellValue() {
if (STCellType.B != cell.getT()) {
throw new NumberFormatException("You cannot get a boolean value from a non-boolean cell");
}
if (cell.isSetV()) {
return (TRUE_AS_STRING.equals(this.cell.getV()));
}
return false;
}
public Comment getCellComment() {
// TODO Auto-generated method stub
return null;
}
public String getCellFormula() {
if (STCellType.STR != cell.getT()) {
throw new NumberFormatException("You cannot get a formula from a non-formula cell");
}
return this.cell.getF().getStringValue();
}
public short getCellNum() {
return this.cellNum;
}
public CellStyle getCellStyle() {
// TODO Auto-generated method stub
return null;
}
public int getCellType() {
switch (this.cell.getT().intValue()) {
case STCellType.INT_B:
return CELL_TYPE_BOOLEAN;
case STCellType.INT_N:
return CELL_TYPE_NUMERIC;
case STCellType.INT_E:
return CELL_TYPE_ERROR;
case STCellType.INT_S: // String is in shared strings
case STCellType.INT_INLINE_STR: // String is inline in cell
return CELL_TYPE_STRING;
case STCellType.INT_STR:
return CELL_TYPE_FORMULA;
default:
throw new IllegalStateException("Illegal cell type: " + this.cell.getT());
}
}
public Date getDateCellValue() {
if (STCellType.N == this.cell.getT() || STCellType.STR == this.cell.getT()) {
double value = this.getNumericCellValue();
if (false /* book.isUsing1904DateWindowing() */) { // FIXME
return HSSFDateUtil.getJavaDate(value,true);
}
else {
return HSSFDateUtil.getJavaDate(value,false);
}
}
throw new NumberFormatException("You cannot get a date value from a cell of type " + this.cell.getT());
}
public byte getErrorCellValue() {
if (STCellType.E != cell.getT()) {
throw new NumberFormatException("You cannot get a error value from a non-error cell");
}
if (this.cell.isSetV()) {
return Byte.parseByte(this.cell.getV());
}
return 0;
}
public double getNumericCellValue() {
if (STCellType.N != cell.getT() && STCellType.STR != cell.getT()) {
throw new NumberFormatException("You cannot get a numeric value from a non-numeric cell");
}
if (this.cell.isSetV()) {
return Double.parseDouble(this.cell.getV());
}
return Double.NaN;
}
public RichTextString getRichStringCellValue() {
if(this.cell.getT() == STCellType.INLINE_STR) {
if(this.cell.isSetV()) {
return new XSSFRichTextString(this.cell.getV());
} else {
return new XSSFRichTextString("");
}
}
if(this.cell.getT() == STCellType.S) {
if(this.cell.isSetV()) {
int sRef = Integer.parseInt(this.cell.getV());
return new XSSFRichTextString(sharedStringSource.getSharedStringAt(sRef));
} else {
return new XSSFRichTextString("");
}
}
throw new NumberFormatException("You cannot get a string value from a non-string cell");
}
public void setAsActiveCell() {
// TODO Auto-generated method stub
}
public void setCellComment(Comment comment) {
// TODO Auto-generated method stub
}
public void setCellErrorValue(byte value) {
if ((this.cell.getT() != STCellType.E) && (this.cell.getT() != STCellType.STR))
{
this.cell.setT(STCellType.E);
}
this.cell.setV(String.valueOf(value));
}
public void setCellFormula(String formula) {
if (this.cell.getT() != STCellType.STR)
{
this.cell.setT(STCellType.STR);
}
CTCellFormula f = CTCellFormula.Factory.newInstance();
f.setStringValue(formula);
this.cell.setF(f);
// XXX: is this correct? Should we recompute the value when the formula changes?
if (this.cell.isSetV()) {
this.cell.unsetV();
}
}
public void setCellNum(short num) {
this.cellNum = num;
}
public void setCellStyle(CellStyle style) {
// TODO Auto-generated method stub
}
public void setCellType(int cellType) {
switch (cellType) {
case CELL_TYPE_BOOLEAN:
this.cell.setT(STCellType.B);
break;
case CELL_TYPE_NUMERIC:
this.cell.setT(STCellType.N);
break;
case CELL_TYPE_ERROR:
this.cell.setT(STCellType.E);
break;
case CELL_TYPE_STRING:
this.cell.setT(STCellType.S);
break;
default:
throw new IllegalArgumentException("Illegal type: " + cellType);
}
}
public void setCellValue(double value) {
if ((this.cell.getT() != STCellType.N) && (this.cell.getT() != STCellType.STR))
{
this.cell.setT(STCellType.N);
}
this.cell.setV(String.valueOf(value));
}
public void setCellValue(Date value) {
setCellValue(HSSFDateUtil.getExcelDate(value, false /*this.book.isUsing1904DateWindowing()*/)); // FIXME
}
public void setCellValue(Calendar value) {
// TODO Auto-generated method stub
}
public void setCellValue(RichTextString value) {
if(this.cell.getT() == STCellType.INLINE_STR) {
this.cell.setV(value.getString());
return;
}
if(this.cell.getT() != STCellType.S) {
this.cell.setT(STCellType.S);
}
int sRef = sharedStringSource.putSharedString(value.getString());
this.cell.setV(Integer.toString(sRef));
}
public void setCellValue(boolean value) {
if ((this.cell.getT() != STCellType.B) && (this.cell.getT() != STCellType.STR))
{
this.cell.setT(STCellType.B);
}
this.cell.setV(value ? TRUE_AS_STRING : FALSE_AS_STRING);
}
@Override
public String toString() {
return "[" + this.row.getRowNum() + "," + this.getCellNum() + "] " + this.cell.getV();
}
}

View File

@ -0,0 +1,91 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.RichTextString;
/**
* TODO - the rich part
*/
public class XSSFRichTextString implements RichTextString {
private String string;
public XSSFRichTextString(String str) {
this.string = str;
}
public void applyFont(int startIndex, int endIndex, short fontIndex) {
// TODO Auto-generated method stub
}
public void applyFont(int startIndex, int endIndex, Font font) {
// TODO Auto-generated method stub
}
public void applyFont(Font font) {
// TODO Auto-generated method stub
}
public void applyFont(short fontIndex) {
// TODO Auto-generated method stub
}
public void clearFormatting() {
// TODO Auto-generated method stub
}
public int compareTo(Object o) {
// TODO Auto-generated method stub
return 0;
}
public short getFontAtIndex(int index) {
// TODO Auto-generated method stub
return 0;
}
public short getFontOfFormattingRun(int index) {
// TODO Auto-generated method stub
return 0;
}
public int getIndexOfFormattingRun(int index) {
// TODO Auto-generated method stub
return 0;
}
public String getString() {
return string;
}
public int length() {
return string.length();
}
public int numFormattingRuns() {
// TODO Auto-generated method stub
return 0;
}
}

View File

@ -0,0 +1,200 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.xssf.usermodel;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
public class XSSFRow implements Row {
private CTRow row;
private List<Cell> cells;
/**
* Create a new XSSFRow. This method is protected to be used only by
* tests.
*/
protected XSSFRow() {
this(CTRow.Factory.newInstance());
}
public XSSFRow(CTRow row) {
this.row = row;
this.cells = new LinkedList<Cell>();
for (CTCell c : row.getCArray()) {
this.cells.add(new XSSFCell(this, c));
}
}
public Iterator<Cell> cellIterator() {
return cells.iterator();
}
public int compareTo(Object obj) {
// TODO Auto-generated method stub
return 0;
}
public Cell createCell(short column) {
return createCell(column, Cell.CELL_TYPE_BLANK);
}
/**
* Add a new empty cell to this row.
*
* @param column Cell column number.
* @param index Position where to insert cell.
* @param type TODO
* @return The new cell.
*/
protected XSSFCell addCell(short column, int index, int type) {
CTCell ctcell = row.insertNewC(index);
XSSFCell xcell = new XSSFCell(this, ctcell);
xcell.setCellNum(column);
if (type != Cell.CELL_TYPE_BLANK) {
xcell.setCellType(type);
}
return xcell;
}
public Cell createCell(short column, int type) {
int index = 0;
for (Cell c : this.cells) {
if (c.getCellNum() == column) {
// Replace c with new Cell
XSSFCell xcell = addCell(column, index, type);
cells.set(index, xcell);
return xcell;
}
if (c.getCellNum() > column) {
XSSFCell xcell = addCell(column, index, type);
cells.add(index, xcell);
return xcell;
}
++index;
}
XSSFCell xcell = addCell(column, index, type);
cells.add(xcell);
return xcell;
}
public Cell getCell(short cellnum) {
Iterator<Cell> it = cellIterator();
for ( ; it.hasNext() ; ) {
Cell cell = it.next();
if (cell.getCellNum() == cellnum) {
return cell;
}
}
return null;
}
public short getFirstCellNum() {
for (Iterator<Cell> it = cellIterator() ; it.hasNext() ; ) {
Cell cell = it.next();
if (cell != null) {
return cell.getCellNum();
}
}
return -1;
}
public short getHeight() {
// TODO Auto-generated method stub
return 0;
}
public float getHeightInPoints() {
// TODO Auto-generated method stub
return 0;
}
public short getLastCellNum() {
short lastCellNum = -1;
for (Iterator<Cell> it = cellIterator() ; it.hasNext() ; ) {
Cell cell = it.next();
if (cell != null) {
lastCellNum = cell.getCellNum();
}
}
return lastCellNum;
}
public int getPhysicalNumberOfCells() {
int count = 0;
for (Iterator<Cell> it = cellIterator() ; it.hasNext() ; ) {
if (it.next() != null) {
count++;
}
}
return count;
}
public int getRowNum() {
// TODO Auto-generated method stub
return 0;
}
public boolean getZeroHeight() {
// TODO Auto-generated method stub
return false;
}
public void removeCell(Cell cell) {
int counter = 0;
for (Iterator<Cell> it = cellIterator(); it.hasNext(); ) {
Cell c = it.next();
if (c.getCellNum() == cell.getCellNum()) {
it.remove();
row.removeC(counter);
continue;
}
counter++;
}
}
public void setHeight(short height) {
// TODO Auto-generated method stub
}
public void setHeightInPoints(float height) {
// TODO Auto-generated method stub
}
public void setRowNum(int rowNum) {
// TODO Auto-generated method stub
}
public void setZeroHeight(boolean height) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,549 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.xssf.usermodel;
import java.util.Iterator;
import org.apache.poi.hssf.util.PaneInformation;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.Footer;
import org.apache.poi.ss.usermodel.Header;
import org.apache.poi.ss.usermodel.Patriarch;
import org.apache.poi.ss.usermodel.PrintSetup;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSelection;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetView;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetViews;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
public class XSSFSheet implements Sheet {
private CTSheet sheet;
private CTWorksheet worksheet;
public XSSFSheet(CTSheet sheet) {
this.sheet = sheet;
this.worksheet = CTWorksheet.Factory.newInstance();
this.worksheet.addNewSheetData();
// XXX ???
CTSheetViews views = this.worksheet.addNewSheetViews();
CTSheetView view = views.addNewSheetView();
view.setWorkbookViewId(0);
view.setZoomScale(100);
CTSelection selection = view.addNewSelection();
selection.setActiveCell("A1");
CTSheetFormatPr format = this.worksheet.addNewSheetFormatPr();
format.setDefaultColWidth(13.2307692307692);
format.setDefaultRowHeight(13);
format.setCustomHeight(true);
CTCols cols = this.worksheet.addNewCols();
CTCol col = cols.addNewCol();
col.setMin(1);
col.setMax(2);
col.setWidth(13.2307692307692);
col.setCustomWidth(true);
for (int i = 3 ; i < 5 ; ++i) {
col = cols.addNewCol();
col.setMin(i);
col.setMax(i);
col.setWidth(13.2307692307692);
col.setCustomWidth(true);
}
CTHeaderFooter hf = this.worksheet.addNewHeaderFooter();
hf.setOddHeader("&amp;C&amp;A");
hf.setOddFooter("&amp;C&amp;\"Arial\"&amp;10Page &amp;P");
}
protected CTWorksheet getWorksheet() {
return this.worksheet;
}
public int addMergedRegion(Region region) {
// TODO Auto-generated method stub
return 0;
}
public void autoSizeColumn(short column) {
// TODO Auto-generated method stub
}
public Patriarch createDrawingPatriarch() {
// TODO Auto-generated method stub
return null;
}
public void createFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow) {
// TODO Auto-generated method stub
}
public void createFreezePane(int colSplit, int rowSplit) {
// TODO Auto-generated method stub
}
public Row createRow(int rownum) {
CTRow row = this.worksheet.getSheetData().insertNewRow(rownum);
row.setR(rownum + 1);
row.setHt(13.41); // XXX ???
return new XSSFRow(row);
}
public void createSplitPane(int splitPos, int splitPos2, int leftmostColumn, int topRow, int activePane) {
// TODO Auto-generated method stub
}
public void dumpDrawingRecords(boolean fat) {
// TODO Auto-generated method stub
}
public boolean getAlternateExpression() {
// TODO Auto-generated method stub
return false;
}
public boolean getAlternateFormula() {
// TODO Auto-generated method stub
return false;
}
public boolean getAutobreaks() {
// TODO Auto-generated method stub
return false;
}
public Comment getCellComment(int row, int column) {
// TODO Auto-generated method stub
return null;
}
public short[] getColumnBreaks() {
// TODO Auto-generated method stub
return null;
}
public short getColumnWidth(short column) {
// TODO Auto-generated method stub
return 0;
}
public short getDefaultColumnWidth() {
// TODO Auto-generated method stub
return 0;
}
public short getDefaultRowHeight() {
// TODO Auto-generated method stub
return 0;
}
public float getDefaultRowHeightInPoints() {
// TODO Auto-generated method stub
return 0;
}
public boolean getDialog() {
// TODO Auto-generated method stub
return false;
}
public boolean getDisplayGuts() {
// TODO Auto-generated method stub
return false;
}
public int getFirstRowNum() {
// TODO Auto-generated method stub
return 0;
}
public boolean getFitToPage() {
// TODO Auto-generated method stub
return false;
}
public Footer getFooter() {
// TODO Auto-generated method stub
return null;
}
public Header getHeader() {
// TODO Auto-generated method stub
return null;
}
public boolean getHorizontallyCenter() {
// TODO Auto-generated method stub
return false;
}
public int getLastRowNum() {
// TODO Auto-generated method stub
return 0;
}
public short getLeftCol() {
// TODO Auto-generated method stub
return 0;
}
public double getMargin(short margin) {
// TODO Auto-generated method stub
return 0;
}
public Region getMergedRegionAt(int index) {
// TODO Auto-generated method stub
return null;
}
public int getNumMergedRegions() {
// TODO Auto-generated method stub
return 0;
}
public boolean getObjectProtect() {
// TODO Auto-generated method stub
return false;
}
public PaneInformation getPaneInformation() {
// TODO Auto-generated method stub
return null;
}
public short getPassword() {
// TODO Auto-generated method stub
return 0;
}
public int getPhysicalNumberOfRows() {
// TODO Auto-generated method stub
return 0;
}
public PrintSetup getPrintSetup() {
// TODO Auto-generated method stub
return null;
}
public boolean getProtect() {
// TODO Auto-generated method stub
return false;
}
public Row getRow(int rownum) {
// TODO Auto-generated method stub
return null;
}
public int[] getRowBreaks() {
// TODO Auto-generated method stub
return null;
}
public boolean getRowSumsBelow() {
// TODO Auto-generated method stub
return false;
}
public boolean getRowSumsRight() {
// TODO Auto-generated method stub
return false;
}
public boolean getScenarioProtect() {
// TODO Auto-generated method stub
return false;
}
public short getTopRow() {
// TODO Auto-generated method stub
return 0;
}
public boolean getVerticallyCenter(boolean value) {
// TODO Auto-generated method stub
return false;
}
public void groupColumn(short fromColumn, short toColumn) {
// TODO Auto-generated method stub
}
public void groupRow(int fromRow, int toRow) {
// TODO Auto-generated method stub
}
public boolean isColumnBroken(short column) {
// TODO Auto-generated method stub
return false;
}
public boolean isColumnHidden(short column) {
// TODO Auto-generated method stub
return false;
}
public boolean isDisplayFormulas() {
// TODO Auto-generated method stub
return false;
}
public boolean isDisplayGridlines() {
// TODO Auto-generated method stub
return false;
}
public boolean isDisplayRowColHeadings() {
// TODO Auto-generated method stub
return false;
}
public boolean isGridsPrinted() {
// TODO Auto-generated method stub
return false;
}
public boolean isPrintGridlines() {
// TODO Auto-generated method stub
return false;
}
public boolean isRowBroken(int row) {
// TODO Auto-generated method stub
return false;
}
public void protectSheet(String password) {
// TODO Auto-generated method stub
}
public void removeColumnBreak(short column) {
// TODO Auto-generated method stub
}
public void removeMergedRegion(int index) {
// TODO Auto-generated method stub
}
public void removeRow(Row row) {
// TODO Auto-generated method stub
}
public void removeRowBreak(int row) {
// TODO Auto-generated method stub
}
public Iterator rowIterator() {
// TODO Auto-generated method stub
return null;
}
public void setAlternativeExpression(boolean b) {
// TODO Auto-generated method stub
}
public void setAlternativeFormula(boolean b) {
// TODO Auto-generated method stub
}
public void setAutobreaks(boolean b) {
// TODO Auto-generated method stub
}
public void setColumnBreak(short column) {
// TODO Auto-generated method stub
}
public void setColumnGroupCollapsed(short columnNumber, boolean collapsed) {
// TODO Auto-generated method stub
}
public void setColumnHidden(short column, boolean hidden) {
// TODO Auto-generated method stub
}
public void setColumnWidth(short column, short width) {
// TODO Auto-generated method stub
}
public void setDefaultColumnStyle(short column, CellStyle style) {
// TODO Auto-generated method stub
}
public void setDefaultColumnWidth(short width) {
// TODO Auto-generated method stub
}
public void setDefaultRowHeight(short height) {
// TODO Auto-generated method stub
}
public void setDefaultRowHeightInPoints(float height) {
// TODO Auto-generated method stub
}
public void setDialog(boolean b) {
// TODO Auto-generated method stub
}
public void setDisplayFormulas(boolean show) {
// TODO Auto-generated method stub
}
public void setDisplayGridlines(boolean show) {
// TODO Auto-generated method stub
}
public void setDisplayGuts(boolean b) {
// TODO Auto-generated method stub
}
public void setDisplayRowColHeadings(boolean show) {
// TODO Auto-generated method stub
}
public void setFitToPage(boolean b) {
// TODO Auto-generated method stub
}
public void setGridsPrinted(boolean value) {
// TODO Auto-generated method stub
}
public void setHorizontallyCenter(boolean value) {
// TODO Auto-generated method stub
}
public void setMargin(short margin, double size) {
// TODO Auto-generated method stub
}
public void setPrintGridlines(boolean newPrintGridlines) {
// TODO Auto-generated method stub
}
public void setProtect(boolean protect) {
// TODO Auto-generated method stub
}
public void setRowBreak(int row) {
// TODO Auto-generated method stub
}
public void setRowGroupCollapsed(int row, boolean collapse) {
// TODO Auto-generated method stub
}
public void setRowSumsBelow(boolean b) {
// TODO Auto-generated method stub
}
public void setRowSumsRight(boolean b) {
// TODO Auto-generated method stub
}
public void setSelected(boolean sel) {
// TODO Auto-generated method stub
}
public void setVerticallyCenter(boolean value) {
// TODO Auto-generated method stub
}
public void setZoom(int numerator, int denominator) {
// TODO Auto-generated method stub
}
public void shiftRows(int startRow, int endRow, int n) {
// TODO Auto-generated method stub
}
public void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight) {
// TODO Auto-generated method stub
}
public void showInPane(short toprow, short leftcol) {
// TODO Auto-generated method stub
}
public void ungroupColumn(short fromColumn, short toColumn) {
// TODO Auto-generated method stub
}
public void ungroupRow(int fromRow, int toRow) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,386 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.xssf.usermodel;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.LinkedList;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.poi.hssf.usermodel.HSSFPalette;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.xmlbeans.XmlOptions;
import org.openxml4j.exceptions.InvalidFormatException;
import org.openxml4j.opc.Package;
import org.openxml4j.opc.PackagePart;
import org.openxml4j.opc.PackagePartName;
import org.openxml4j.opc.PackageRelationshipTypes;
import org.openxml4j.opc.PackagingURIHelper;
import org.openxml4j.opc.TargetMode;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookView;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookViews;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
public class XSSFWorkbook implements Workbook {
private CTWorkbook workbook;
private List<XSSFSheet> sheets = new LinkedList<XSSFSheet>();
public XSSFWorkbook() {
this.workbook = CTWorkbook.Factory.newInstance();
CTBookViews bvs = this.workbook.addNewBookViews();
CTBookView bv = bvs.addNewWorkbookView();
bv.setActiveTab(0);
this.workbook.addNewSheets();
}
public int addPicture(byte[] pictureData, int format) {
// TODO Auto-generated method stub
return 0;
}
public int addSSTString(String string) {
// TODO Auto-generated method stub
return 0;
}
public Sheet cloneSheet(int sheetNum) {
// TODO Auto-generated method stub
return null;
}
public CellStyle createCellStyle() {
// TODO Auto-generated method stub
return null;
}
public DataFormat createDataFormat() {
// TODO Auto-generated method stub
return null;
}
public Font createFont() {
// TODO Auto-generated method stub
return null;
}
public Name createName() {
// TODO Auto-generated method stub
return null;
}
public Sheet createSheet() {
return createSheet(null);
}
public Sheet createSheet(String sheetname) {
CTSheet sheet = workbook.getSheets().addNewSheet();
if (sheetname != null) {
sheet.setName(sheetname);
}
XSSFSheet wrapper = new XSSFSheet(sheet);
this.sheets.add(wrapper);
return wrapper;
}
public void dumpDrawingGroupRecords(boolean fat) {
// TODO Auto-generated method stub
}
public Font findFont(short boldWeight, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline) {
// TODO Auto-generated method stub
return null;
}
public List getAllEmbeddedObjects() {
// TODO Auto-generated method stub
return null;
}
public List getAllPictures() {
// TODO Auto-generated method stub
return null;
}
public boolean getBackupFlag() {
// TODO Auto-generated method stub
return false;
}
public byte[] getBytes() {
// TODO Auto-generated method stub
return null;
}
public CellStyle getCellStyleAt(short idx) {
// TODO Auto-generated method stub
return null;
}
public HSSFPalette getCustomPalette() {
// TODO Auto-generated method stub
return null;
}
public short getDisplayedTab() {
// TODO Auto-generated method stub
return 0;
}
public Font getFontAt(short idx) {
// TODO Auto-generated method stub
return null;
}
public Name getNameAt(int index) {
// TODO Auto-generated method stub
return null;
}
public int getNameIndex(String name) {
// TODO Auto-generated method stub
return 0;
}
public String getNameName(int index) {
// TODO Auto-generated method stub
return null;
}
public short getNumCellStyles() {
// TODO Auto-generated method stub
return 0;
}
public short getNumberOfFonts() {
// TODO Auto-generated method stub
return 0;
}
public int getNumberOfNames() {
// TODO Auto-generated method stub
return 0;
}
public int getNumberOfSheets() {
return this.workbook.getSheets().sizeOfSheetArray();
}
public String getPrintArea(int sheetIndex) {
// TODO Auto-generated method stub
return null;
}
public String getSSTString(int index) {
// TODO Auto-generated method stub
return null;
}
public short getSelectedTab() {
// TODO Auto-generated method stub
return 0;
}
public Sheet getSheet(String name) {
// TODO Auto-generated method stub
return null;
}
public Sheet getSheetAt(int index) {
return this.sheets.get(index - 1);
}
public int getSheetIndex(String name) {
// TODO Auto-generated method stub
return 0;
}
public int getSheetIndex(Sheet sheet) {
// TODO Auto-generated method stub
return 0;
}
public String getSheetName(int sheet) {
// TODO Auto-generated method stub
return null;
}
public void insertChartRecord() {
// TODO Auto-generated method stub
}
public void removeName(int index) {
// TODO Auto-generated method stub
}
public void removeName(String name) {
// TODO Auto-generated method stub
}
public void removePrintArea(int sheetIndex) {
// TODO Auto-generated method stub
}
public void removeSheetAt(int index) {
// TODO Auto-generated method stub
}
public void setBackupFlag(boolean backupValue) {
// TODO Auto-generated method stub
}
public void setDisplayedTab(short index) {
// TODO Auto-generated method stub
}
public void setPrintArea(int sheetIndex, String reference) {
// TODO Auto-generated method stub
}
public void setPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow) {
// TODO Auto-generated method stub
}
public void setRepeatingRowsAndColumns(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow) {
// TODO Auto-generated method stub
}
public void setSelectedTab(short index) {
// TODO Auto-generated method stub
}
public void setSheetName(int sheet, String name) {
// TODO Auto-generated method stub
}
public void setSheetName(int sheet, String name, short encoding) {
// TODO Auto-generated method stub
}
public void setSheetOrder(String sheetname, int pos) {
// TODO Auto-generated method stub
}
public void unwriteProtectWorkbook() {
// TODO Auto-generated method stub
}
/**
* XXX: Horribly naive implementation based on OpenXML4J's Package class,
* which sucks because it does not allow instantiation using an
* OutputStream instead of a File. So we write the Package to a temporary
* file, which we then proceed to read and stream out.
*/
public void write(OutputStream stream) throws IOException {
// Create a temporary file
File file = File.createTempFile("poi-", ".xlsx");
file.delete();
try {
// Create a package referring the temp file.
Package pkg = Package.create(file);
// Main part
PackagePartName corePartName = PackagingURIHelper.createPartName("/xl/workbook.xml");
// Create main part relationship
pkg.addRelationship(corePartName, TargetMode.INTERNAL, PackageRelationshipTypes.CORE_DOCUMENT, "rId1");
// Create main document part
PackagePart corePart = pkg.createPart(corePartName,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
XmlOptions xmlOptions = new XmlOptions();
// Requests use of whitespace for easier reading
xmlOptions.setSavePrettyPrint();
xmlOptions.setSaveOuter();
// XXX This should not be needed, but apparently the setSaveOuter call above does not work in XMLBeans 2.2
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTWorkbook.type.getName().getNamespaceURI(), "workbook"));
xmlOptions.setUseDefaultNamespace();
OutputStream out = corePart.getOutputStream();
workbook.save(out, xmlOptions);
out.close();
for (int i = 1 ; i <= this.getNumberOfSheets() ; ++i) {
XSSFSheet sheet = (XSSFSheet) this.getSheetAt(i);
PackagePartName partName = PackagingURIHelper.createPartName("/xl/worksheets/sheet" + i + ".xml");
corePart.addRelationship(partName, TargetMode.INTERNAL, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet", "rSheet" + 1);
PackagePart part = pkg.createPart(partName,
"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml");
// XXX This should not be needed, but apparently the setSaveOuter call above does not work in XMLBeans 2.2
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTWorksheet.type.getName().getNamespaceURI(), "worksheet"));
out = part.getOutputStream();
sheet.getWorksheet().save(out, xmlOptions);
// XXX DEBUG
System.err.println(sheet.getWorksheet().xmlText(xmlOptions));
out.close();
}
pkg.close();
byte[] buf = new byte[8192];
int nread = 0;
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
try {
while ((nread = bis.read(buf)) > 0) {
stream.write(buf, 0, nread);
}
} finally {
bis.close();
}
} catch (InvalidFormatException e) {
// TODO: replace with more meaningful exception
throw new RuntimeException(e);
}
}
public void writeProtectWorkbook(String password, String username) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,178 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.xssf.usermodel;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import junit.framework.TestCase;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.SharedStringSource;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType;
public class TestXSSFCell extends TestCase {
/**
* Test setting and getting boolean values.
*/
public void testSetGetBoolean() throws Exception {
XSSFCell cell = new XSSFCell(new XSSFRow());
cell.setCellValue(true);
assertEquals(Cell.CELL_TYPE_BOOLEAN, cell.getCellType());
assertTrue(cell.getBooleanCellValue());
cell.setCellValue(false);
assertFalse(cell.getBooleanCellValue());
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
try {
cell.getBooleanCellValue();
fail("Exception expected");
} catch (NumberFormatException e) {
// success
}
}
/**
* Test setting and getting numeric values.
*/
public void testSetGetNumeric() throws Exception {
XSSFCell cell = new XSSFCell(new XSSFRow());
cell.setCellValue(10d);
assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
assertEquals(10d, cell.getNumericCellValue());
cell.setCellValue(-23.76);
assertEquals(-23.76, cell.getNumericCellValue());
}
/**
* Test setting and getting numeric values.
*/
public void testSetGetDate() throws Exception {
XSSFCell cell = new XSSFCell(new XSSFRow());
Date now = new Date();
cell.setCellValue(now);
assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
assertEquals(now, cell.getDateCellValue());
// Test case for 1904 hack
Calendar cal = Calendar.getInstance();
cal.set(1903, 1, 8);
Date before1904 = cal.getTime();
cell.setCellValue(before1904);
assertEquals(before1904, cell.getDateCellValue());
cell.setCellType(Cell.CELL_TYPE_BOOLEAN);
try {
cell.getDateCellValue();
fail("Exception expected");
} catch (NumberFormatException e) {
// success
}
}
public void testSetGetError() throws Exception {
XSSFCell cell = new XSSFCell(new XSSFRow());
cell.setCellErrorValue((byte)255);
assertEquals(Cell.CELL_TYPE_ERROR, cell.getCellType());
assertEquals((byte)255, cell.getErrorCellValue());
}
public void testSetGetFormula() throws Exception {
XSSFCell cell = new XSSFCell(new XSSFRow());
String formula = "SQRT(C2^2+D2^2)";
cell.setCellFormula(formula);
assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType());
assertEquals(formula, cell.getCellFormula());
assertTrue( Double.isNaN( cell.getNumericCellValue() ));
}
public void testSetGetStringInline() throws Exception {
CTCell rawCell = CTCell.Factory.newInstance();
XSSFCell cell = new XSSFCell(new XSSFRow(), rawCell);
cell.setSharedStringSource(new DummySharedStringSource());
// Default is shared string mode, so have to do this explicitly
rawCell.setT(STCellType.INLINE_STR);
assertEquals(STCellType.INT_INLINE_STR, rawCell.getT().intValue());
assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType());
assertEquals("", cell.getRichStringCellValue().getString());
cell.setCellValue(new XSSFRichTextString("Foo"));
assertEquals(STCellType.INT_INLINE_STR, rawCell.getT().intValue());
assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType());
assertEquals("Foo", cell.getRichStringCellValue().getString());
// To number and back to string, stops being inline
cell.setCellValue(1.4);
cell.setCellValue(new XSSFRichTextString("Foo2"));
assertEquals(STCellType.INT_S, rawCell.getT().intValue());
assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType());
assertEquals("Foo2", cell.getRichStringCellValue().getString());
}
public void testSetGetStringShared() throws Exception {
XSSFCell cell = new XSSFCell(new XSSFRow());
cell.setSharedStringSource(new DummySharedStringSource());
cell.setCellValue(new XSSFRichTextString(""));
assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType());
assertEquals("", cell.getRichStringCellValue().getString());
cell.setCellValue(new XSSFRichTextString("Foo"));
assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType());
assertEquals("Foo", cell.getRichStringCellValue().getString());
}
/**
* Test that empty cells (no v element) return default values.
*/
public void testGetEmptyCellValue() throws Exception {
XSSFCell cell = new XSSFCell(new XSSFRow());
cell.setCellType(Cell.CELL_TYPE_BOOLEAN);
assertFalse(cell.getBooleanCellValue());
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
assertTrue(Double.isNaN( cell.getNumericCellValue() ));
assertNull(cell.getDateCellValue());
cell.setCellType(Cell.CELL_TYPE_ERROR);
assertEquals(0, cell.getErrorCellValue());
cell.setCellType(Cell.CELL_TYPE_STRING);
assertEquals("", cell.getRichStringCellValue().getString());
}
public static class DummySharedStringSource implements SharedStringSource {
ArrayList<String> strs = new ArrayList<String>();
public String getSharedStringAt(int idx) {
return strs.get(idx);
}
public synchronized int putSharedString(String s) {
if(strs.contains(s)) {
return strs.indexOf(s);
}
strs.add(s);
return strs.size() - 1;
}
}
}

View File

@ -0,0 +1,159 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.xssf.usermodel;
import java.util.Iterator;
import junit.framework.TestCase;
import org.apache.poi.ss.usermodel.Cell;
public class TestXSSFRow extends TestCase {
/**
* Test adding cells to a row in various places and see if we can find them again.
*/
public void testAddAndIterateCells() {
XSSFRow row = new XSSFRow();
// One cell at the beginning
Cell cell1 = row.createCell((short) 1);
Iterator<Cell> it = row.cellIterator();
assertTrue(it.hasNext());
assertTrue(cell1 == it.next());
assertFalse(it.hasNext());
// Add another cell at the end
Cell cell2 = row.createCell((short) 99);
it = row.cellIterator();
assertTrue(it.hasNext());
assertTrue(cell1 == it.next());
assertTrue(it.hasNext());
assertTrue(cell2 == it.next());
// Add another cell at the beginning
Cell cell3 = row.createCell((short) 0);
it = row.cellIterator();
assertTrue(it.hasNext());
assertTrue(cell3 == it.next());
assertTrue(it.hasNext());
assertTrue(cell1 == it.next());
assertTrue(it.hasNext());
assertTrue(cell2 == it.next());
// Replace cell1
Cell cell4 = row.createCell((short) 1);
it = row.cellIterator();
assertTrue(it.hasNext());
assertTrue(cell3 == it.next());
assertTrue(it.hasNext());
assertTrue(cell4 == it.next());
assertTrue(it.hasNext());
assertTrue(cell2 == it.next());
assertFalse(it.hasNext());
// Add another cell, specifying the cellType
Cell cell5 = row.createCell((short) 2, Cell.CELL_TYPE_STRING);
it = row.cellIterator();
assertNotNull(cell5);
assertTrue(it.hasNext());
assertTrue(cell3 == it.next());
assertTrue(it.hasNext());
assertTrue(cell4 == it.next());
assertTrue(it.hasNext());
assertTrue(cell5 == it.next());
assertTrue(it.hasNext());
assertTrue(cell2 == it.next());
assertEquals(Cell.CELL_TYPE_STRING, cell5.getCellType());
}
public void testGetCell() throws Exception {
XSSFRow row = getSampleRow();
assertNotNull(row.getCell((short) 2));
assertNotNull(row.getCell((short) 3));
assertNotNull(row.getCell((short) 4));
assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell((short) 3).getCellType());
assertNull(row.getCell((short) 5));
}
public void testGetPhysicalNumberOfCells() throws Exception {
XSSFRow row = getSampleRow();
assertEquals(7, row.getPhysicalNumberOfCells());
}
public void testGetFirstCellNum() throws Exception {
// Test a row with some cells
XSSFRow row = getSampleRow();
assertFalse(row.getFirstCellNum() == (short) 0);
assertEquals((short) 2, row.getFirstCellNum());
// Test after removing the first cell
Cell cell = row.getCell((short) 2);
row.removeCell(cell);
assertFalse(row.getFirstCellNum() == (short) 2);
// Test a row without cells
XSSFRow emptyRow = new XSSFRow();
assertEquals(-1, emptyRow.getFirstCellNum());
}
public void testLastCellNum() throws Exception {
XSSFRow row = getSampleRow();
assertEquals(100, row.getLastCellNum());
Cell cell = row.getCell((short) 100);
row.removeCell(cell);
assertFalse(row.getLastCellNum() == (short) 100);
}
public void testRemoveCell() throws Exception {
XSSFRow row = getSampleRow();
// Test removing the first cell
Cell firstCell = row.getCell((short) 2);
assertNotNull(firstCell);
assertEquals(7, row.getPhysicalNumberOfCells());
row.removeCell(firstCell);
assertEquals(6, row.getPhysicalNumberOfCells());
firstCell = row.getCell((short) 2);
assertNull(firstCell);
// Test removing the last cell
Cell lastCell = row.getCell((short) 100);
row.removeCell(lastCell);
}
/**
* Method that returns a row with some sample cells
* @return row
*/
public static XSSFRow getSampleRow() {
XSSFRow row = new XSSFRow();
row.createCell((short) 2);
row.createCell((short) 3, Cell.CELL_TYPE_NUMERIC);
row.createCell((short) 4);
row.createCell((short) 6);
row.createCell((short) 7);
row.createCell((short) 8);
row.createCell((short) 100);
return row;
}
}