Method from org.apache.poi.hssf.usermodel.HSSFSheet Detail: |
public int addMergedRegion(Region region) {
return _sheet.addMergedRegion( region.getRowFrom(),
region.getColumnFrom(),
//(short) region.getRowTo(),
region.getRowTo(),
region.getColumnTo());
} Deprecated! ( - Aug-2008) use CellRangeAddress instead of Region
|
public int addMergedRegion(CellRangeAddress region) {
region.validate(SpreadsheetVersion.EXCEL97);
return _sheet.addMergedRegion( region.getFirstRow(),
region.getFirstColumn(),
region.getLastRow(),
region.getLastColumn());
}
adds a merged region of cells (hence those cells form one) |
public void addValidationData(HSSFDataValidation dataValidation) {
if (dataValidation == null) {
throw new IllegalArgumentException("objValidation must not be null");
}
DataValidityTable dvt = _sheet.getOrCreateDataValidityTable();
DVRecord dvRecord = dataValidation.createDVRecord(this);
dvt.addDataValidation(dvRecord);
}
Creates a data validation object |
public void autoSizeColumn(int column) {
autoSizeColumn(column, false);
}
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. |
public void autoSizeColumn(int column,
boolean useMergedCells) {
AttributedString str;
TextLayout layout;
/**
* Excel measures columns in units of 1/256th of a character width
* but the docs say nothing about what particular character is used.
* '0' looks to be a good choice.
*/
char defaultChar = '0';
/**
* This is the multiple that the font height is scaled by when determining the
* boundary of rotated text.
*/
double fontHeightMultiple = 2.0;
FontRenderContext frc = new FontRenderContext(null, true, true);
HSSFWorkbook wb = new HSSFWorkbook(_book);
HSSFFont defaultFont = wb.getFontAt((short) 0);
str = new AttributedString("" + defaultChar);
copyAttributes(defaultFont, str, 0, 1);
layout = new TextLayout(str.getIterator(), frc);
int defaultCharWidth = (int)layout.getAdvance();
double width = -1;
rows:
for (Iterator< Row > it = rowIterator(); it.hasNext();) {
HSSFRow row = (HSSFRow) it.next();
HSSFCell cell = row.getCell(column);
if (cell == null) {
continue;
}
int colspan = 1;
for (int i = 0 ; i < getNumMergedRegions(); i++) {
CellRangeAddress region = getMergedRegion(i);
if (containsCell(region, row.getRowNum(), column)) {
if (!useMergedCells) {
// If we're not using merged cells, skip this one and move on to the next.
continue rows;
}
cell = row.getCell(region.getFirstColumn());
colspan = 1 + region.getLastColumn() - region.getFirstColumn();
}
}
HSSFCellStyle style = cell.getCellStyle();
int cellType = cell.getCellType();
if(cellType == HSSFCell.CELL_TYPE_FORMULA) cellType = cell.getCachedFormulaResultType();
HSSFFont font = wb.getFontAt(style.getFontIndex());
if (cellType == HSSFCell.CELL_TYPE_STRING) {
HSSFRichTextString rt = cell.getRichStringCellValue();
String[] lines = rt.getString().split("\\n");
for (int i = 0; i < lines.length; i++) {
String txt = lines[i] + defaultChar;
str = new AttributedString(txt);
copyAttributes(font, str, 0, txt.length());
if (rt.numFormattingRuns() > 0) {
for (int j = 0; j < lines[i].length(); j++) {
int idx = rt.getFontAtIndex(j);
if (idx != 0) {
HSSFFont fnt = wb.getFontAt((short) idx);
copyAttributes(fnt, str, j, j + 1);
}
}
}
layout = new TextLayout(str.getIterator(), frc);
if(style.getRotation() != 0){
/*
* Transform the text using a scale so that it's height is increased by a multiple of the leading,
* and then rotate the text before computing the bounds. The scale results in some whitespace around
* the unrotated top and bottom of the text that normally wouldn't be present if unscaled, but
* is added by the standard Excel autosize.
*/
AffineTransform trans = new AffineTransform();
trans.concatenate(AffineTransform.getRotateInstance(style.getRotation()*2.0*Math.PI/360.0));
trans.concatenate(
AffineTransform.getScaleInstance(1, fontHeightMultiple)
);
width = Math.max(width, ((layout.getOutline(trans).getBounds().getWidth() / colspan) / defaultCharWidth) + cell.getCellStyle().getIndention());
} else {
width = Math.max(width, ((layout.getBounds().getWidth() / colspan) / defaultCharWidth) + cell.getCellStyle().getIndention());
}
}
} else {
String sval = null;
if (cellType == HSSFCell.CELL_TYPE_NUMERIC) {
String dfmt = style.getDataFormatString();
String format = dfmt == null ? null : dfmt.replaceAll("\"", "");
double value = cell.getNumericCellValue();
try {
NumberFormat fmt;
if ("General".equals(format))
sval = "" + value;
else
{
fmt = new DecimalFormat(format);
sval = fmt.format(value);
}
} catch (Exception e) {
sval = "" + value;
}
} else if (cellType == HSSFCell.CELL_TYPE_BOOLEAN) {
sval = String.valueOf(cell.getBooleanCellValue());
}
if(sval != null) {
String txt = sval + defaultChar;
str = new AttributedString(txt);
copyAttributes(font, str, 0, txt.length());
layout = new TextLayout(str.getIterator(), frc);
if(style.getRotation() != 0){
/*
* Transform the text using a scale so that it's height is increased by a multiple of the leading,
* and then rotate the text before computing the bounds. The scale results in some whitespace around
* the unrotated top and bottom of the text that normally wouldn't be present if unscaled, but
* is added by the standard Excel autosize.
*/
AffineTransform trans = new AffineTransform();
trans.concatenate(AffineTransform.getRotateInstance(style.getRotation()*2.0*Math.PI/360.0));
trans.concatenate(
AffineTransform.getScaleInstance(1, fontHeightMultiple)
);
width = Math.max(width, ((layout.getOutline(trans).getBounds().getWidth() / colspan) / defaultCharWidth) + cell.getCellStyle().getIndention());
} else {
width = Math.max(width, ((layout.getBounds().getWidth() / colspan) / defaultCharWidth) + cell.getCellStyle().getIndention());
}
}
}
}
if (width != -1) {
width *= 256;
if (width > Short.MAX_VALUE) { //width can be bigger that Short.MAX_VALUE!
width = Short.MAX_VALUE;
}
_sheet.setColumnWidth(column, (short) (width));
}
}
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.
You can specify whether the content of merged cells should be considered or ignored.
Default is to ignore merged cells. |
HSSFSheet cloneSheet(HSSFWorkbook workbook) {
return new HSSFSheet(workbook, _sheet.cloneSheet());
}
|
public HSSFPatriarch createDrawingPatriarch() {
// Create the drawing group if it doesn't already exist.
_book.createDrawingGroup();
_sheet.aggregateDrawingRecords(_book.getDrawingManager(), true);
EscherAggregate agg = (EscherAggregate) _sheet.findFirstRecordBySid(EscherAggregate.sid);
HSSFPatriarch patriarch = new HSSFPatriarch(this, agg);
agg.clear(); // Initially the behaviour will be to clear out any existing shapes in the sheet when
// creating a new patriarch.
agg.setPatriarch(patriarch);
return patriarch;
}
Creates the top-level drawing patriarch. This will have
the effect of removing any existing drawings on this
sheet.
This may then be used to add graphics or charts |
public void createFreezePane(int colSplit,
int rowSplit) {
createFreezePane(colSplit, rowSplit, colSplit, rowSplit);
}
Creates a split (freezepane). Any existing freezepane or split pane is overwritten. |
public void createFreezePane(int colSplit,
int rowSplit,
int leftmostColumn,
int topRow) {
validateColumn(colSplit);
validateRow(rowSplit);
if (leftmostColumn < colSplit) throw new IllegalArgumentException("leftmostColumn parameter must not be less than colSplit parameter");
if (topRow < rowSplit) throw new IllegalArgumentException("topRow parameter must not be less than leftmostColumn parameter");
getSheet().createFreezePane( colSplit, rowSplit, topRow, leftmostColumn );
}
Creates a split (freezepane). Any existing freezepane or split pane is overwritten. |
public HSSFRow createRow(int rownum) {
HSSFRow row = new HSSFRow(_workbook, this, rownum);
addRow(row, true);
return row;
}
Create a new row within the sheet and return the high level representation |
public void createSplitPane(int xSplitPos,
int ySplitPos,
int leftmostColumn,
int topRow,
int activePane) {
getSheet().createSplitPane( xSplitPos, ySplitPos, topRow, leftmostColumn, activePane );
}
Creates a split pane. Any existing freezepane or split pane is overwritten. |
public void dumpDrawingRecords(boolean fat) {
_sheet.aggregateDrawingRecords(_book.getDrawingManager(), false);
EscherAggregate r = (EscherAggregate) getSheet().findFirstRecordBySid(EscherAggregate.sid);
List< EscherRecord > escherRecords = r.getEscherRecords();
PrintWriter w = new PrintWriter(System.out);
for (Iterator< EscherRecord > iterator = escherRecords.iterator(); iterator.hasNext();) {
EscherRecord escherRecord = iterator.next();
if (fat) {
System.out.println(escherRecord.toString());
} else {
escherRecord.display(w, 0);
}
}
w.flush();
}
Aggregates the drawing records and dumps the escher record hierarchy
to the standard output. |
public boolean getAlternateExpression() {
return ((WSBoolRecord) _sheet.findFirstRecordBySid(WSBoolRecord.sid))
.getAlternateExpression();
}
whether alternate expression evaluation is on |
public boolean getAlternateFormula() {
return ((WSBoolRecord) _sheet.findFirstRecordBySid(WSBoolRecord.sid))
.getAlternateFormula();
}
whether alternative formula entry is on |
public boolean getAutobreaks() {
return ((WSBoolRecord) _sheet.findFirstRecordBySid(WSBoolRecord.sid))
.getAutobreaks();
}
show automatic page breaks or not |
public HSSFComment getCellComment(int row,
int column) {
// Don't call findCellComment directly, otherwise
// two calls to this method will result in two
// new HSSFComment instances, which is bad
HSSFRow r = getRow(row);
if(r != null) {
HSSFCell c = r.getCell(column);
if(c != null) {
return c.getCellComment();
}
// No cell, so you will get new
// objects every time, sorry...
return HSSFCell.findCellComment(_sheet, row, column);
}
return null;
}
Returns cell comment for the specified row and column |
public int[] getColumnBreaks() {
//we can probably cache this information, but this should be a sparsely used function
return _sheet.getPageSettings().getColumnBreaks();
}
|
public HSSFCellStyle getColumnStyle(int column) {
short styleIndex = _sheet.getXFIndexForColAt((short)column);
if(styleIndex == 0xf) {
// None set
return null;
}
ExtendedFormatRecord xf = _book.getExFormatAt(styleIndex);
return new HSSFCellStyle(styleIndex, xf, _book);
}
Returns the HSSFCellStyle that applies to the given
(0 based) column, or null if no style has been
set for that column |
public short getColumnWidth(short columnIndex) {
return (short)getColumnWidth(columnIndex & 0xFFFF);
} Deprecated! ( - Sep 2008) use #getColumnWidth(int)
|
public int getColumnWidth(int columnIndex) {
return _sheet.getColumnWidth(columnIndex);
}
get the width (in units of 1/256th of a character width ) |
public int getDefaultColumnWidth() {
return _sheet.getDefaultColumnWidth();
}
get the default column width for the sheet (if the columns do not define their own width) in
characters |
public short getDefaultRowHeight() {
return _sheet.getDefaultRowHeight();
}
get the default row height for the sheet (if the rows do not define their own height) in
twips (1/20 of a point) |
public float getDefaultRowHeightInPoints() {
return ((float)_sheet.getDefaultRowHeight() / 20);
}
get the default row height for the sheet (if the rows do not define their own height) in
points. |
public boolean getDialog() {
return ((WSBoolRecord) _sheet.findFirstRecordBySid(WSBoolRecord.sid))
.getDialog();
}
get whether sheet is a dialog sheet or not |
public boolean getDisplayGuts() {
return ((WSBoolRecord) _sheet.findFirstRecordBySid(WSBoolRecord.sid))
.getDisplayGuts();
}
get whether to display the guts or not |
public EscherAggregate getDrawingEscherAggregate() {
_book.findDrawingGroup();
// If there's now no drawing manager, then there's
// no drawing escher records on the workbook
if(_book.getDrawingManager() == null) {
return null;
}
int found = _sheet.aggregateDrawingRecords(
_book.getDrawingManager(), false
);
if(found == -1) {
// Workbook has drawing stuff, but this sheet doesn't
return null;
}
// Grab our aggregate record, and wire it up
EscherAggregate agg = (EscherAggregate) _sheet.findFirstRecordBySid(EscherAggregate.sid);
return agg;
}
Returns the agregate escher records for this sheet,
it there is one.
WARNING - calling this will trigger a parsing of the
associated escher records. Any that aren't supported
(such as charts and complex drawing types) will almost
certainly be lost or corrupted when written out. |
public HSSFPatriarch getDrawingPatriarch() {
EscherAggregate agg = getDrawingEscherAggregate();
if(agg == null) return null;
HSSFPatriarch patriarch = new HSSFPatriarch(this, agg);
agg.setPatriarch(patriarch);
// Have it process the records into high level objects
// as best it can do (this step may eat anything
// that isn't supported, you were warned...)
agg.convertRecordsToUserModel();
// Return what we could cope with
return patriarch;
}
Returns the top-level drawing patriach, if there is
one.
This will hold any graphics or charts for the sheet.
WARNING - calling this will trigger a parsing of the
associated escher records. Any that aren't supported
(such as charts and complex drawing types) will almost
certainly be lost or corrupted when written out. Only
use this with simple drawings, otherwise call
HSSFSheet#createDrawingPatriarch() and
start from scratch! |
public int getFirstRowNum() {
return _firstrow;
}
Gets the first row on the sheet |
public boolean getFitToPage() {
return ((WSBoolRecord) _sheet.findFirstRecordBySid(WSBoolRecord.sid))
.getFitToPage();
}
|
public HSSFFooter getFooter() {
return new HSSFFooter(_sheet.getPageSettings());
}
|
public boolean getForceFormulaRecalculation() {
return _sheet.getUncalced();
}
Whether a record must be inserted or not at generation to indicate that
formula must be recalculated when workbook is opened. |
public HSSFHeader getHeader() {
return new HSSFHeader(_sheet.getPageSettings());
}
|
public boolean getHorizontallyCenter() {
return _sheet.getPageSettings().getHCenter().getHCenter();
}
Determine whether printed output for this sheet will be horizontally centered. |
public int getLastRowNum() {
return _lastrow;
}
Gets the number last row on the sheet.
Owing to idiosyncrasies in the excel file
format, if the result of calling this method
is zero, you can't tell if that means there
are zero rows on the sheet, or one at
position zero. For that case, additionally
call #getPhysicalNumberOfRows() to
tell if there is a row at position zero
or not. |
public short getLeftCol() {
return _sheet.getLeftCol();
}
The left col in the visible view when the sheet is
first viewed after opening it in a viewer |
public double getMargin(short margin) {
return _sheet.getPageSettings().getMargin(margin);
}
Gets the size of the margin in inches. |
public CellRangeAddress getMergedRegion(int index) {
return _sheet.getMergedRegionAt(index);
}
|
public Region getMergedRegionAt(int index) {
CellRangeAddress cra = getMergedRegion(index);
return new Region(cra.getFirstRow(), (short)cra.getFirstColumn(),
cra.getLastRow(), (short)cra.getLastColumn());
} Deprecated! ( - Aug-2008) use HSSFSheet#getMergedRegion(int)
|
public int getNumMergedRegions() {
return _sheet.getNumMergedRegions();
}
returns the number of merged regions |
public boolean getObjectProtect() {
return getProtectionBlock().isObjectProtected();
}
Answer whether object protection is enabled or disabled |
public PaneInformation getPaneInformation() {
return getSheet().getPaneInformation();
}
Returns the information regarding the currently configured pane (split or freeze). |
public short getPassword() {
return (short)getProtectionBlock().getPasswordHash();
}
|
public int getPhysicalNumberOfRows() {
return _rows.size();
}
Returns the number of physically defined rows (NOT the number of rows in the sheet) |
public HSSFPrintSetup getPrintSetup() {
return new HSSFPrintSetup(_sheet.getPageSettings().getPrintSetup());
}
Gets the print setup object. |
public boolean getProtect() {
return getProtectionBlock().isSheetProtected();
}
Answer whether protection is enabled or disabled |
public HSSFRow getRow(int rowIndex) {
return _rows.get(new Integer(rowIndex));
}
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. |
public int[] getRowBreaks() {
//we can probably cache this information, but this should be a sparsely used function
return _sheet.getPageSettings().getRowBreaks();
}
|
public boolean getRowSumsBelow() {
return ((WSBoolRecord) _sheet.findFirstRecordBySid(WSBoolRecord.sid))
.getRowSumsBelow();
}
get if row summaries appear below detail in the outline |
public boolean getRowSumsRight() {
return ((WSBoolRecord) _sheet.findFirstRecordBySid(WSBoolRecord.sid))
.getRowSumsRight();
}
get if col summaries appear right of the detail in the outline |
public boolean getScenarioProtect() {
return getProtectionBlock().isScenarioProtected();
}
Answer whether scenario protection is enabled or disabled |
Sheet getSheet() {
return _sheet;
}
used internally in the API to get the low level Sheet record represented by this
Object. |
public HSSFSheetConditionalFormatting getSheetConditionalFormatting() {
return new HSSFSheetConditionalFormatting(this);
}
|
public String getSheetName() {
HSSFWorkbook wb = getWorkbook();
int idx = wb.getSheetIndex(this);
return wb.getSheetName(idx);
}
Returns the name of this sheet |
public short getTopRow() {
return _sheet.getTopRow();
}
The top row in the visible view when the sheet is
first viewed after opening it in a viewer |
public boolean getVerticallyCenter() {
return _sheet.getPageSettings().getVCenter().getVCenter();
}
Determine whether printed output for this sheet will be vertically centered. |
public boolean getVerticallyCenter(boolean value) {
return getVerticallyCenter();
} Deprecated! ( - Mar-2008) use getVerticallyCenter() instead
TODO: Boolean not needed, remove after next release |
public HSSFWorkbook getWorkbook() {
return _workbook;
}
Return the parent workbook |
public void groupColumn(short fromColumn,
short toColumn) {
groupColumn(fromColumn & 0xFFFF, toColumn & 0xFFFF);
} Deprecated! ( - Sep 2008) use #groupColumn(int, int)
|
public void groupColumn(int fromColumn,
int toColumn) {
_sheet.groupColumnRange(fromColumn, toColumn, true);
}
Create an outline for the provided column range. |
public void groupRow(int fromRow,
int toRow) {
_sheet.groupRowRange(fromRow, toRow, true);
}
Tie a range of cell together so that they can be collapsed or expanded |
protected void insertChartRecords(List<Record> records) {
int window2Loc = _sheet.findFirstRecordLocBySid(WindowTwoRecord.sid);
_sheet.getRecords().addAll(window2Loc, records);
}
|
public boolean isActive() {
return getSheet().getWindowTwo().isActive();
}
|
public boolean isColumnBroken(int column) {
return _sheet.getPageSettings().isColumnBroken(column);
}
Determines if there is a page break at the indicated column |
public boolean isColumnHidden(short columnIndex) {
return isColumnHidden(columnIndex & 0xFFFF);
} Deprecated! ( - Sep 2008) use #isColumnHidden(int)
|
public boolean isColumnHidden(int columnIndex) {
return _sheet.isColumnHidden(columnIndex);
}
Get the hidden state for a given column. |
public boolean isDisplayFormulas() {
return _sheet.isDisplayFormulas();
}
Returns if formulas are displayed. |
public boolean isDisplayGridlines() {
return _sheet.isDisplayGridlines();
}
Returns if gridlines are displayed. |
public boolean isDisplayRowColHeadings() {
return _sheet.isDisplayRowColHeadings();
}
Returns if RowColHeadings are displayed. |
public boolean isDisplayZeros() {
return _sheet.getWindowTwo().getDisplayZeros();
}
|
public boolean isGridsPrinted() {
return _sheet.isGridsPrinted();
}
get whether gridlines are printed. |
public boolean isPrintGridlines() {
return getSheet().getPrintGridlines().getPrintGridlines();
}
Returns whether gridlines are printed. |
public boolean isRowBroken(int row) {
return _sheet.getPageSettings().isRowBroken(row);
}
|
public boolean isSelected() {
return getSheet().getWindowTwo().getSelected();
}
Note - this is not the same as whether the sheet is focused (isActive) |
public Iterator<Row> iterator() {
return rowIterator();
}
|
public void protectSheet(String password) {
getProtectionBlock().protectSheet(password, true, true); //protect objs&scenarios(normal)
}
Sets the protection enabled as well as the password |
public void removeColumnBreak(int column) {
_sheet.getPageSettings().removeColumnBreak(column);
}
Removes a page break at the indicated column |
public void removeMergedRegion(int index) {
_sheet.removeMergedRegion(index);
}
removes a merged region of cells (hence letting them free) |
public void removeRow(Row row) {
HSSFRow hrow = (HSSFRow) row;
if (row.getSheet() != this) {
throw new IllegalArgumentException("Specified row does not belong to this sheet");
}
if (_rows.size() > 0) {
Integer key = new Integer(row.getRowNum());
HSSFRow removedRow = _rows.remove(key);
if (removedRow != row) {
//should not happen if the input argument is valid
throw new IllegalArgumentException("Specified row does not belong to this sheet");
}
if (hrow.getRowNum() == getLastRowNum())
{
_lastrow = findLastRow(_lastrow);
}
if (hrow.getRowNum() == getFirstRowNum())
{
_firstrow = findFirstRow(_firstrow);
}
_sheet.removeRow(hrow.getRowRecord());
}
}
Remove a row from this sheet. All cells contained in the row are removed as well |
public void removeRowBreak(int row) {
_sheet.getPageSettings().removeRowBreak(row);
}
Removes the page break at the indicated row |
public Iterator<Row> rowIterator() {
@SuppressWarnings("unchecked") // can this clumsy generic syntax be improved?
Iterator< Row > result = (Iterator< Row >)(Iterator< ? extends Row >)_rows.values().iterator();
return result;
}
|
public void setActive(boolean sel) {
getSheet().getWindowTwo().setActive(sel);
}
Sets whether sheet is selected. |
public void setAlternativeExpression(boolean b) {
WSBoolRecord record =
(WSBoolRecord) _sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setAlternateExpression(b);
}
whether alternate expression evaluation is on |
public void setAlternativeFormula(boolean b) {
WSBoolRecord record =
(WSBoolRecord) _sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setAlternateFormula(b);
}
whether alternative formula entry is on |
public void setAutobreaks(boolean b) {
WSBoolRecord record =
(WSBoolRecord) _sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setAutobreaks(b);
}
show automatic page breaks or not |
public void setColumnBreak(int column) {
validateColumn((short)column);
_sheet.getPageSettings().setColumnBreak((short)column, (short)0, (short) SpreadsheetVersion.EXCEL97.getLastRowIndex());
}
Sets a page break at the indicated column |
public void setColumnGroupCollapsed(short columnNumber,
boolean collapsed) {
setColumnGroupCollapsed(columnNumber & 0xFFFF, collapsed);
} Deprecated! ( - Sep 2008) use #setColumnGroupCollapsed(int, boolean)
|
public void setColumnGroupCollapsed(int columnNumber,
boolean collapsed) {
_sheet.setColumnGroupCollapsed(columnNumber, collapsed);
}
Expands or collapses a column group. |
public void setColumnHidden(short columnIndex,
boolean hidden) {
setColumnHidden(columnIndex & 0xFFFF, hidden);
} Deprecated! ( - Sep 2008) use #setColumnHidden(int, boolean)
|
public void setColumnHidden(int columnIndex,
boolean hidden) {
_sheet.setColumnHidden(columnIndex, hidden);
}
Get the visibility state for a given column. |
public void setColumnWidth(short columnIndex,
short width) {
setColumnWidth(columnIndex & 0xFFFF, width & 0xFFFF);
} Deprecated! ( - Sep 2008) use #setColumnWidth(int, int)
|
public void setColumnWidth(int columnIndex,
int width) {
_sheet.setColumnWidth(columnIndex, width);
}
Set the width (in units of 1/256th of a character width)
The maximum column width for an individual cell is 255 characters.
This value represents the number of characters that can be displayed
in a cell that is formatted with the standard font.
|
public void setDefaultColumnStyle(int column,
CellStyle style) {
_sheet.setDefaultColumnStyle(column, ((HSSFCellStyle)style).getIndex());
}
Sets the default column style for a given column. POI will only apply this style to new cells added to the sheet. |
public void setDefaultColumnWidth(short width) {
setDefaultColumnWidth(width & 0xFFFF);
} Deprecated! ( - Sep 2008) use #setDefaultColumnWidth(int)
|
public void setDefaultColumnWidth(int width) {
_sheet.setDefaultColumnWidth(width);
}
set the default column width for the sheet (if the columns do not define their own width) in
characters |
public void setDefaultRowHeight(short height) {
_sheet.setDefaultRowHeight(height);
}
set the default row height for the sheet (if the rows do not define their own height) in
twips (1/20 of a point) |
public void setDefaultRowHeightInPoints(float height) {
_sheet.setDefaultRowHeight((short) (height * 20));
}
set the default row height for the sheet (if the rows do not define their own height) in
points |
public void setDialog(boolean b) {
WSBoolRecord record =
(WSBoolRecord) _sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setDialog(b);
}
set whether sheet is a dialog sheet or not |
public void setDisplayFormulas(boolean show) {
_sheet.setDisplayFormulas(show);
}
Sets whether the formulas are shown in a viewer. |
public void setDisplayGridlines(boolean show) {
_sheet.setDisplayGridlines(show);
}
Sets whether the gridlines are shown in a viewer. |
public void setDisplayGuts(boolean b) {
WSBoolRecord record =
(WSBoolRecord) _sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setDisplayGuts(b);
}
set whether to display the guts or not |
public void setDisplayRowColHeadings(boolean show) {
_sheet.setDisplayRowColHeadings(show);
}
Sets whether the RowColHeadings are shown in a viewer. |
public void setDisplayZeros(boolean value) {
_sheet.getWindowTwo().setDisplayZeros(value);
}
|
public void setFitToPage(boolean b) {
WSBoolRecord record =
(WSBoolRecord) _sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setFitToPage(b);
}
|
public void setForceFormulaRecalculation(boolean value) {
_sheet.setUncalced(value);
}
Whether a record must be inserted or not at generation to indicate that
formula must be recalculated when workbook is opened. |
public void setGridsPrinted(boolean value) {
_sheet.setGridsPrinted(value);
}
set whether gridlines printed. |
public void setHorizontallyCenter(boolean value) {
_sheet.getPageSettings().getHCenter().setHCenter(value);
}
determines whether the output is horizontally centered on the page. |
public void setMargin(short margin,
double size) {
_sheet.getPageSettings().setMargin(margin, size);
}
Sets the size of the margin in inches. |
public void setPrintGridlines(boolean newPrintGridlines) {
getSheet().getPrintGridlines().setPrintGridlines(newPrintGridlines);
}
Turns on or off the printing of gridlines. |
public void setRowBreak(int row) {
validateRow(row);
_sheet.getPageSettings().setRowBreak(row, (short)0, (short)255);
}
Sets a page break at the indicated row |
public void setRowGroupCollapsed(int rowIndex,
boolean collapse) {
if (collapse) {
_sheet.getRowsAggregate().collapseRow(rowIndex);
} else {
_sheet.getRowsAggregate().expandRow(rowIndex);
}
}
|
public void setRowSumsBelow(boolean b) {
WSBoolRecord record =
(WSBoolRecord) _sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setRowSumsBelow(b);
//setAlternateExpression must be set in conjuction with setRowSumsBelow
record.setAlternateExpression(b);
}
set if row summaries appear below detail in the outline |
public void setRowSumsRight(boolean b) {
WSBoolRecord record =
(WSBoolRecord) _sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setRowSumsRight(b);
}
set if col summaries appear right of the detail in the outline |
public void setSelected(boolean sel) {
getSheet().getWindowTwo().setSelected(sel);
}
Sets whether sheet is selected. |
public void setVerticallyCenter(boolean value) {
_sheet.getPageSettings().getVCenter().setVCenter(value);
}
determines whether the output is vertically centered on the page. |
public void setZoom(int numerator,
int denominator) {
if (numerator < 1 || numerator > 65535)
throw new IllegalArgumentException("Numerator must be greater than 1 and less than 65536");
if (denominator < 1 || denominator > 65535)
throw new IllegalArgumentException("Denominator must be greater than 1 and less than 65536");
SCLRecord sclRecord = new SCLRecord();
sclRecord.setNumerator((short)numerator);
sclRecord.setDenominator((short)denominator);
getSheet().setSCLRecord(sclRecord);
}
Sets the zoom magnification 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. |
protected void shiftMerged(int startRow,
int endRow,
int n,
boolean isRow) {
List< CellRangeAddress > shiftedRegions = new ArrayList< CellRangeAddress >();
//move merged regions completely if they fall within the new region boundaries when they are shifted
for (int i = 0; i < getNumMergedRegions(); i++) {
CellRangeAddress merged = getMergedRegion(i);
boolean inStart= (merged.getFirstRow() >= startRow || merged.getLastRow() >= startRow);
boolean inEnd = (merged.getFirstRow() < = endRow || merged.getLastRow() < = endRow);
//don't check if it's not within the shifted area
if (!inStart || !inEnd) {
continue;
}
//only shift if the region outside the shifted rows is not merged too
if (!containsCell(merged, startRow-1, 0) && !containsCell(merged, endRow+1, 0)){
merged.setFirstRow(merged.getFirstRow()+n);
merged.setLastRow(merged.getLastRow()+n);
//have to remove/add it back
shiftedRegions.add(merged);
removeMergedRegion(i);
i = i -1; // we have to back up now since we removed one
}
}
//read so it doesn't get shifted again
Iterator< CellRangeAddress > iterator = shiftedRegions.iterator();
while (iterator.hasNext()) {
CellRangeAddress region = iterator.next();
this.addMergedRegion(region);
}
}
Shifts the merged regions left or right depending on mode
TODO: MODE , this is only row specific |
public void shiftRows(int startRow,
int endRow,
int n) {
shiftRows(startRow, endRow, n, false, false);
}
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);
Additionally shifts merged regions that are completely defined in these
rows (ie. merged 2 cells on a row to be shifted). |
public void shiftRows(int startRow,
int endRow,
int n,
boolean copyRowHeight,
boolean resetOriginalRowHeight) {
shiftRows(startRow, endRow, n, copyRowHeight, resetOriginalRowHeight, true);
}
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
Additionally shifts merged regions that are completely defined in these
rows (ie. merged 2 cells on a row to be shifted).
TODO Might want to add bounds checking here |
public void shiftRows(int startRow,
int endRow,
int n,
boolean copyRowHeight,
boolean resetOriginalRowHeight,
boolean moveComments) {
int s, inc;
if (n < 0) {
s = startRow;
inc = 1;
} else {
s = endRow;
inc = -1;
}
NoteRecord[] noteRecs;
if (moveComments) {
noteRecs = _sheet.getNoteRecords();
} else {
noteRecs = NoteRecord.EMPTY_ARRAY;
}
shiftMerged(startRow, endRow, n, true);
_sheet.getPageSettings().shiftRowBreaks(startRow, endRow, n);
for ( int rowNum = s; rowNum >= startRow && rowNum < = endRow && rowNum >= 0 && rowNum < 65536; rowNum += inc ) {
HSSFRow row = getRow( rowNum );
HSSFRow row2Replace = getRow( rowNum + n );
if ( row2Replace == null )
row2Replace = createRow( rowNum + n );
// Remove all the old cells from the row we'll
// be writing too, before we start overwriting
// any cells. This avoids issues with cells
// changing type, and records not being correctly
// overwritten
row2Replace.removeAllCells();
// If this row doesn't exist, nothing needs to
// be done for the now empty destination row
if (row == null) continue; // Nothing to do for this row
// Fix up row heights if required
if (copyRowHeight) {
row2Replace.setHeight(row.getHeight());
}
if (resetOriginalRowHeight) {
row.setHeight((short)0xff);
}
// Copy each cell from the source row to
// the destination row
for(Iterator< Cell > cells = row.cellIterator(); cells.hasNext(); ) {
HSSFCell cell = (HSSFCell)cells.next();
row.removeCell( cell );
CellValueRecordInterface cellRecord = cell.getCellValueRecord();
cellRecord.setRow( rowNum + n );
row2Replace.createCellFromRecord( cellRecord );
_sheet.addValueRecord( rowNum + n, cellRecord );
HSSFHyperlink link = cell.getHyperlink();
if(link != null){
link.setFirstRow(link.getFirstRow() + n);
link.setLastRow(link.getLastRow() + n);
}
}
// Now zap all the cells in the source row
row.removeAllCells();
// Move comments from the source row to the
// destination row. Note that comments can
// exist for cells which are null
if(moveComments) {
// This code would get simpler if NoteRecords could be organised by HSSFRow.
for(int i=noteRecs.length-1; i >=0; i--) {
NoteRecord nr = noteRecs[i];
if (nr.getRow() != rowNum) {
continue;
}
HSSFComment comment = getCellComment(rowNum, nr.getColumn());
if (comment != null) {
comment.setRow(rowNum + n);
}
}
}
}
if ( endRow == _lastrow || endRow + n > _lastrow ) _lastrow = Math.min( endRow + n, SpreadsheetVersion.EXCEL97.getLastRowIndex() );
if ( startRow == _firstrow || startRow + n < _firstrow ) _firstrow = Math.max( startRow + n, 0 );
// Update any formulas on this sheet that point to
// rows which have been moved
int sheetIndex = _workbook.getSheetIndex(this);
short externSheetIndex = _book.checkExternSheet(sheetIndex);
FormulaShifter shifter = FormulaShifter.createForRowShift(externSheetIndex, startRow, endRow, n);
_sheet.updateFormulasAfterCellShift(shifter, externSheetIndex);
int nSheets = _workbook.getNumberOfSheets();
for(int i=0; i< nSheets; i++) {
Sheet otherSheet = _workbook.getSheetAt(i).getSheet();
if (otherSheet == this._sheet) {
continue;
}
short otherExtSheetIx = _book.checkExternSheet(i);
otherSheet.updateFormulasAfterCellShift(shifter, otherExtSheetIx);
}
_workbook.getWorkbook().updateNamesAfterCellShift(shifter);
}
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
Additionally shifts merged regions that are completely defined in these
rows (ie. merged 2 cells on a row to be shifted).
TODO Might want to add bounds checking here |
public void showInPane(short toprow,
short leftcol) {
_sheet.setTopRow(toprow);
_sheet.setLeftCol(leftcol);
}
Sets desktop window pane display area, when the
file is first opened in a viewer. |
public void ungroupColumn(short fromColumn,
short toColumn) {
ungroupColumn(fromColumn & 0xFFFF, toColumn & 0xFFFF);
} Deprecated! ( - Sep 2008) use #ungroupColumn(int, int)
|
public void ungroupColumn(int fromColumn,
int toColumn) {
_sheet.groupColumnRange(fromColumn, toColumn, false);
}
|
public void ungroupRow(int fromRow,
int toRow) {
_sheet.groupRowRange(fromRow, toRow, false);
}
|
protected void validateColumn(int column) {
int maxcol = SpreadsheetVersion.EXCEL97.getLastColumnIndex();
if (column > maxcol) throw new IllegalArgumentException("Maximum column number is " + maxcol);
if (column < 0) throw new IllegalArgumentException("Minimum column number is 0");
}
Runs a bounds check for column numbers |
protected void validateRow(int row) {
int maxrow = SpreadsheetVersion.EXCEL97.getLastRowIndex();
if (row > maxrow) throw new IllegalArgumentException("Maximum row number is " + maxrow);
if (row < 0) throw new IllegalArgumentException("Minumum row number is 0");
}
Runs a bounds check for row numbers |