Methods Summary |
---|
public int | addMergedRegion(org.apache.poi.hssf.util.Region region)adds a merged region of cells (hence those cells form one)
//return sheet.addMergedRegion((short) region.getRowFrom(),
return sheet.addMergedRegion( region.getRowFrom(),
region.getColumnFrom(),
//(short) region.getRowTo(),
region.getRowTo(),
region.getColumnTo());
|
private void | addRow(org.apache.poi.hssf.usermodel.HSSFRow row, boolean addLow)add a row to the sheet
rows.put(row, row);
if (addLow)
{
sheet.addRow(row.getRowRecord());
}
if (row.getRowNum() > getLastRowNum())
{
lastrow = row.getRowNum();
}
if (row.getRowNum() < getFirstRowNum())
{
firstrow = row.getRowNum();
}
|
public void | autoSizeColumn(short column)Adjusts the column width to fit the contents.
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 a good choice.
*/
char defaultChar = '0";
FontRenderContext frc = new FontRenderContext(null, true, true);
HSSFWorkbook wb = new HSSFWorkbook(book);
HSSFFont defaultFont = wb.getFontAt((short) 0);
str = new AttributedString("" + defaultChar);
str.addAttribute(TextAttribute.FAMILY, defaultFont.getFontName());
str.addAttribute(TextAttribute.SIZE, new Float(defaultFont.getFontHeightInPoints()));
layout = new TextLayout(str.getIterator(), frc);
int defaultCharWidth = (int)layout.getAdvance();
double width = -1;
for (Iterator it = rowIterator(); it.hasNext();) {
HSSFRow row = (HSSFRow) it.next();
HSSFCell cell = row.getCell(column);
if (cell == null) continue;
HSSFCellStyle style = cell.getCellStyle();
HSSFFont font = wb.getFontAt(style.getFontIndex());
if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
HSSFRichTextString rt = cell.getRichStringCellValue();
String[] lines = rt.getString().split("\\n");
for (int i = 0; i < lines.length; i++) {
str = new AttributedString(lines[i] + defaultChar);
str.addAttribute(TextAttribute.FAMILY, font.getFontName());
str.addAttribute(TextAttribute.SIZE, new Float(font.getFontHeightInPoints()));
if (font.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) str.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
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);
str.addAttribute(TextAttribute.FAMILY, fnt.getFontName(), j, j + 1);
str.addAttribute(TextAttribute.SIZE, new Float(fnt.getFontHeightInPoints()), j, j + 1);
}
}
}
layout = new TextLayout(str.getIterator(), frc);
width = Math.max(width, layout.getAdvance() / defaultCharWidth);
}
} else {
String sval = null;
if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
HSSFDataFormat dataformat = wb.createDataFormat();
short idx = style.getDataFormat();
String format = dataformat.getFormat(idx).replaceAll("\"", "");
double value = cell.getNumericCellValue();
try {
NumberFormat fmt;
if ("General".equals(format))
fmt = new DecimalFormat();
else
fmt = new DecimalFormat(format);
sval = fmt.format(value);
} catch (Exception e) {
sval = "" + value;
}
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN) {
sval = String.valueOf(cell.getBooleanCellValue());
}
str = new AttributedString(sval + defaultChar);
str.addAttribute(TextAttribute.FAMILY, font.getFontName());
str.addAttribute(TextAttribute.SIZE, new Float(font.getFontHeightInPoints()));
layout = new TextLayout(str.getIterator(), frc);
width = Math.max(width, layout.getAdvance() / defaultCharWidth);
}
if (width != -1) {
sheet.setColumnWidth(column, (short) (width * 256));
}
}
|
org.apache.poi.hssf.usermodel.HSSFSheet | cloneSheet(org.apache.poi.hssf.model.Workbook book)
return new HSSFSheet(book, sheet.cloneSheet());
|
public org.apache.poi.hssf.usermodel.HSSFPatriarch | createDrawingPatriarch()Creates the toplevel drawing patriarch. This will have the effect of
removing any existing drawings on this sheet.
// Create the drawing group if it doesn't already exist.
book.createDrawingGroup();
sheet.aggregateDrawingRecords(book.getDrawingManager());
EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid);
HSSFPatriarch patriarch = new HSSFPatriarch(this);
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;
|
public void | createFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow)Creates a split (freezepane). Any existing freezepane or split pane is overwritten.
if (colSplit < 0 || colSplit > 255) throw new IllegalArgumentException("Column must be between 0 and 255");
if (rowSplit < 0 || rowSplit > 65535) throw new IllegalArgumentException("Row must be between 0 and 65535");
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 );
|
public void | createFreezePane(int colSplit, int rowSplit)Creates a split (freezepane). Any existing freezepane or split pane is overwritten.
createFreezePane( colSplit, rowSplit, colSplit, rowSplit );
|
public org.apache.poi.hssf.usermodel.HSSFRow | createRow(int rownum)Create a new row within the sheet and return the high level representation
HSSFRow row = new HSSFRow(book, sheet, rownum);
addRow(row, true);
return row;
|
private org.apache.poi.hssf.usermodel.HSSFRow | createRowFromRecord(org.apache.poi.hssf.record.RowRecord row)Used internally to create a high level Row object from a low level row object.
USed when reading an existing file
HSSFRow hrow = new HSSFRow(book, sheet, row);
addRow(hrow, false);
return hrow;
|
public void | createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane)Creates a split pane. Any existing freezepane or split pane is overwritten.
getSheet().createSplitPane( xSplitPos, ySplitPos, topRow, leftmostColumn, activePane );
|
public void | dumpDrawingRecords(boolean fat)Aggregates the drawing records and dumps the escher record hierarchy
to the standard output.
sheet.aggregateDrawingRecords(book.getDrawingManager());
EscherAggregate r = (EscherAggregate) getSheet().findFirstRecordBySid(EscherAggregate.sid);
List escherRecords = r.getEscherRecords();
PrintWriter w = new PrintWriter(System.out);
for ( Iterator iterator = escherRecords.iterator(); iterator.hasNext(); )
{
EscherRecord escherRecord = (EscherRecord) iterator.next();
if (fat)
System.out.println(escherRecord.toString());
else
escherRecord.display(w, 0);
}
w.flush();
|
private int | findFirstRow(int firstrow)used internally to refresh the "first row" when the first row is removed.
int rownum = firstrow + 1;
HSSFRow r = getRow(rownum);
while (r == null && rownum <= getLastRowNum())
{
r = getRow(++rownum);
}
if (rownum > getLastRowNum())
return -1;
return rownum;
|
private int | findLastRow(int lastrow)used internally to refresh the "last row" when the last row is removed.
int rownum = lastrow - 1;
HSSFRow r = getRow(rownum);
while (r == null && rownum > 0)
{
r = getRow(--rownum);
}
if (r == null)
return -1;
return rownum;
|
public boolean | getAlternateExpression()whether alternate expression evaluation is on
return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid))
.getAlternateExpression();
|
public boolean | getAlternateFormula()whether alternative formula entry is on
return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid))
.getAlternateFormula();
|
public boolean | getAutobreaks()show automatic page breaks or not
return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid))
.getAutobreaks();
|
public org.apache.poi.hssf.usermodel.HSSFComment | getCellComment(int row, int column)Returns cell comment for the specified row and column
return HSSFCell.findCellComment(sheet, row, column);
|
public short[] | getColumnBreaks()Retrieves all the vertical page breaks
//we can probably cache this information, but this should be a sparsely used function
int count = sheet.getNumColumnBreaks();
if (count > 0) {
short[] returnValue = new short[count];
Iterator iterator = sheet.getColumnBreaks();
int i = 0;
while (iterator.hasNext()) {
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
returnValue[i++] = breakItem.main;
}
return returnValue;
}
return null;
|
public short | getColumnWidth(short column)get the width (in units of 1/256th of a character width )
return sheet.getColumnWidth(column);
|
public short | getDefaultColumnWidth()get the default column width for the sheet (if the columns do not define their own width) in
characters
return sheet.getDefaultColumnWidth();
|
public short | 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)
return sheet.getDefaultRowHeight();
|
public float | getDefaultRowHeightInPoints()get the default row height for the sheet (if the rows do not define their own height) in
points.
return (sheet.getDefaultRowHeight() / 20);
|
public boolean | getDialog()get whether sheet is a dialog sheet or not
return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid))
.getDialog();
|
public boolean | getDisplayGuts()get whether to display the guts or not
return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid))
.getDisplayGuts();
|
public int | getFirstRowNum()gets the first row on the sheet
return firstrow;
|
public boolean | getFitToPage()fit to page option is on
return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid))
.getFitToPage();
|
public org.apache.poi.hssf.usermodel.HSSFFooter | getFooter()Gets the user model for the document footer.
return new HSSFFooter( getSheet().getFooter() );
|
public org.apache.poi.hssf.usermodel.HSSFHeader | getHeader()Gets the user model for the document header.
return new HSSFHeader( getSheet().getHeader() );
|
public boolean | getHorizontallyCenter()Determine whether printed output for this sheet will be horizontally centered.
HCenterRecord record =
(HCenterRecord) sheet.findFirstRecordBySid(HCenterRecord.sid);
return record.getHCenter();
|
public int | getLastRowNum()gets the last row on the sheet
return lastrow;
|
public short | getLeftCol()The left col in the visible view when the sheet is
first viewed after opening it in a viewer
return sheet.getLeftCol();
|
public double | getMargin(short margin)Gets the size of the margin in inches.
return getSheet().getMargin( margin );
|
public org.apache.poi.hssf.util.Region | getMergedRegionAt(int index)gets the region at a particular index
return new Region(sheet.getMergedRegionAt(index));
|
public int | getNumMergedRegions()returns the number of merged regions
return sheet.getNumMergedRegions();
|
public org.apache.poi.hssf.util.PaneInformation | getPaneInformation()Returns the information regarding the currently configured pane (split or freeze).
return getSheet().getPaneInformation();
|
public int | getPhysicalNumberOfRows()Returns the number of phsyically defined rows (NOT the number of rows in the sheet)
return rows.size();
|
public org.apache.poi.hssf.usermodel.HSSFPrintSetup | getPrintSetup()Gets the print setup object.
return new HSSFPrintSetup( getSheet().getPrintSetup() );
|
public boolean | getProtect()Answer whether protection is enabled or disabled
return getSheet().getProtect().getProtect();
|
public org.apache.poi.hssf.usermodel.HSSFRow | getRow(int rownum)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.
HSSFRow row = new HSSFRow();
//row.setRowNum((short) rownum);
row.setRowNum( rownum);
return (HSSFRow) rows.get(row);
|
public int[] | getRowBreaks()Retrieves all the horizontal page breaks
//we can probably cache this information, but this should be a sparsely used function
int count = sheet.getNumRowBreaks();
if (count > 0) {
int[] returnValue = new int[count];
Iterator iterator = sheet.getRowBreaks();
int i = 0;
while (iterator.hasNext()) {
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
returnValue[i++] = (int)breakItem.main;
}
return returnValue;
}
return null;
|
public boolean | getRowSumsBelow()get if row summaries appear below detail in the outline
return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid))
.getRowSumsBelow();
|
public boolean | getRowSumsRight()get if col summaries appear right of the detail in the outline
return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid))
.getRowSumsRight();
|
protected org.apache.poi.hssf.model.Sheet | getSheet()used internally in the API to get the low level Sheet record represented by this
Object.
return sheet;
|
public short | getTopRow()The top row in the visible view when the sheet is
first viewed after opening it in a viewer
return sheet.getTopRow();
|
public boolean | getVerticallyCenter(boolean value)Determine whether printed output for this sheet will be vertically centered.
VCenterRecord record =
(VCenterRecord) sheet.findFirstRecordBySid(VCenterRecord.sid);
return record.getVCenter();
|
public void | groupColumn(short fromColumn, short toColumn)Create an outline for the provided column range.
sheet.groupColumnRange( fromColumn, toColumn, true );
|
public void | groupRow(int fromRow, int toRow)
sheet.groupRowRange( fromRow, toRow, true );
|
protected void | insertChartRecords(java.util.List records)
int window2Loc = sheet.findFirstRecordLocBySid( WindowTwoRecord.sid );
sheet.getRecords().addAll( window2Loc, records );
|
public boolean | isColumnBroken(short column)Determines if there is a page break at the indicated column
return sheet.isColumnBroken(column);
|
public boolean | isColumnHidden(short column)Get the hidden state for a given column.
return sheet.isColumnHidden(column);
|
public boolean | isDisplayFormulas()Returns if formulas are displayed.
return sheet.isDisplayFormulas();
|
public boolean | isDisplayGridlines()Returns if gridlines are displayed.
return sheet.isDisplayGridlines();
|
public boolean | isDisplayRowColHeadings()Returns if RowColHeadings are displayed.
return sheet.isDisplayRowColHeadings();
|
public boolean | isGridsPrinted()get whether gridlines are printed.
return sheet.isGridsPrinted();
|
public boolean | isPrintGridlines()Returns whether gridlines are printed.
return getSheet().getPrintGridlines().getPrintGridlines();
|
public boolean | isRowBroken(int row)Determines if there is a page break at the indicated row
return sheet.isRowBroken(row);
|
public void | removeColumnBreak(short column)Removes a page break at the indicated column
sheet.removeColumnBreak(column);
|
public void | removeMergedRegion(int index)removes a merged region of cells (hence letting them free)
sheet.removeMergedRegion(index);
|
public void | removeRow(org.apache.poi.hssf.usermodel.HSSFRow row)Remove a row from this sheet. All cells contained in the row are removed as well
sheet.setLoc(sheet.getDimsLoc());
if (rows.size() > 0)
{
rows.remove(row);
if (row.getRowNum() == getLastRowNum())
{
lastrow = findLastRow(lastrow);
}
if (row.getRowNum() == getFirstRowNum())
{
firstrow = findFirstRow(firstrow);
}
Iterator iter = row.cellIterator();
while (iter.hasNext())
{
HSSFCell cell = (HSSFCell) iter.next();
sheet.removeValueRecord(row.getRowNum(),
cell.getCellValueRecord());
}
sheet.removeRow(row.getRowRecord());
}
|
public void | removeRowBreak(int row)Removes the page break at the indicated row
sheet.removeRowBreak(row);
|
public java.util.Iterator | rowIterator()
return rows.values().iterator();
|
public void | setAlternativeExpression(boolean b)whether alternate expression evaluation is on
WSBoolRecord record =
(WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setAlternateExpression(b);
|
public void | setAlternativeFormula(boolean b)whether alternative formula entry is on
WSBoolRecord record =
(WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setAlternateFormula(b);
|
public void | setAutobreaks(boolean b)show automatic page breaks or not
WSBoolRecord record =
(WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setAutobreaks(b);
|
public void | setColumnBreak(short column)Sets a page break at the indicated column
validateColumn(column);
sheet.setColumnBreak(column, (short)0, (short)65535);
|
public void | setColumnGroupCollapsed(short columnNumber, boolean collapsed)Expands or collapses a column group.
sheet.setColumnGroupCollapsed( columnNumber, collapsed );
|
public void | setColumnHidden(short column, boolean hidden)Get the visibility state for a given column.
sheet.setColumnHidden(column, hidden);
|
public void | setColumnWidth(short column, short width)set the width (in units of 1/256th of a character width)
sheet.setColumnWidth(column, width);
|
public void | setDefaultColumnStyle(short column, org.apache.poi.hssf.usermodel.HSSFCellStyle style)Sets the default column style for a given column. POI will only apply this style to new cells added to the sheet.
sheet.setColumn(column, new Short(style.getIndex()), null, null, null, null);
|
public void | setDefaultColumnWidth(short width)set the default column width for the sheet (if the columns do not define their own width) in
characters
sheet.setDefaultColumnWidth(width);
|
public void | setDefaultRowHeight(short 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)
sheet.setDefaultRowHeight(height);
|
public void | setDefaultRowHeightInPoints(float height)set the default row height for the sheet (if the rows do not define their own height) in
points
sheet.setDefaultRowHeight((short) (height * 20));
|
public void | setDialog(boolean b)set whether sheet is a dialog sheet or not
WSBoolRecord record =
(WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setDialog(b);
|
public void | setDisplayFormulas(boolean show)Sets whether the formulas are shown in a viewer.
sheet.setDisplayFormulas(show);
|
public void | setDisplayGridlines(boolean show)Sets whether the gridlines are shown in a viewer.
sheet.setDisplayGridlines(show);
|
public void | setDisplayGuts(boolean b)set whether to display the guts or not
WSBoolRecord record =
(WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setDisplayGuts(b);
|
public void | setDisplayRowColHeadings(boolean show)Sets whether the RowColHeadings are shown in a viewer.
sheet.setDisplayRowColHeadings(show);
|
public void | setFitToPage(boolean b)fit to page option is on
WSBoolRecord record =
(WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setFitToPage(b);
|
public void | setGridsPrinted(boolean value)set whether gridlines printed.
sheet.setGridsPrinted(value);
|
public void | setHorizontallyCenter(boolean value)determines whether the output is horizontally centered on the page.
HCenterRecord record =
(HCenterRecord) sheet.findFirstRecordBySid(HCenterRecord.sid);
record.setHCenter(value);
|
public void | setMargin(short margin, double size)Sets the size of the margin in inches.
getSheet().setMargin( margin, size );
|
public void | setPrintGridlines(boolean newPrintGridlines)Turns on or off the printing of gridlines.
getSheet().getPrintGridlines().setPrintGridlines( newPrintGridlines );
|
private void | setPropertiesFromSheet(org.apache.poi.hssf.model.Sheet sheet)used internally to set the properties given a Sheet object
int sloc = sheet.getLoc();
RowRecord row = sheet.getNextRow();
while (row != null)
{
createRowFromRecord(row);
row = sheet.getNextRow();
}
sheet.setLoc(sloc);
CellValueRecordInterface cval = sheet.getNextValueRecord();
long timestart = System.currentTimeMillis();
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "Time at start of cell creating in HSSF sheet = ",
new Long(timestart));
HSSFRow lastrow = null;
while (cval != null)
{
long cellstart = System.currentTimeMillis();
HSSFRow hrow = lastrow;
if ( ( lastrow == null ) || ( lastrow.getRowNum() != cval.getRow() ) )
{
hrow = getRow( cval.getRow() );
}
if ( hrow != null )
{
lastrow = hrow;
if (log.check( POILogger.DEBUG ))
log.log( DEBUG, "record id = " + Integer.toHexString( ( (Record) cval ).getSid() ) );
hrow.createCellFromRecord( cval );
cval = sheet.getNextValueRecord();
if (log.check( POILogger.DEBUG ))
log.log( DEBUG, "record took ",
new Long( System.currentTimeMillis() - cellstart ) );
}
else
{
cval = null;
}
}
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "total sheet cell creation took ",
new Long(System.currentTimeMillis() - timestart));
|
public void | setProtect(boolean protect)Sets the protection on enabled or disabled
getSheet().getProtect().setProtect(protect);
|
public void | setRowBreak(int row)Sets a page break at the indicated row
validateRow(row);
sheet.setRowBreak(row, (short)0, (short)255);
|
public void | setRowGroupCollapsed(int row, boolean collapse)
sheet.setRowGroupCollapsed( row, collapse );
|
public void | setRowSumsBelow(boolean b)set if row summaries appear below detail in the outline
WSBoolRecord record =
(WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setRowSumsBelow(b);
|
public void | setRowSumsRight(boolean b)set if col summaries appear right of the detail in the outline
WSBoolRecord record =
(WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setRowSumsRight(b);
|
public void | setSelected(boolean sel)Sets whether sheet is selected.
getSheet().setSelected( sel );
|
public void | setVerticallyCenter(boolean value)determines whether the output is vertically centered on the page.
VCenterRecord record =
(VCenterRecord) sheet.findFirstRecordBySid(VCenterRecord.sid);
record.setVCenter(value);
|
public void | setZoom(int numerator, int denominator)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.
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);
|
protected void | shiftMerged(int startRow, int endRow, int n, boolean isRow)Shifts the merged regions left or right depending on mode
TODO: MODE , this is only row specific
List shiftedRegions = new ArrayList();
//move merged regions completely if they fall within the new region boundaries when they are shifted
for (int i = 0; i < this.getNumMergedRegions(); i++) {
Region merged = this.getMergedRegionAt(i);
boolean inStart = (merged.getRowFrom() >= startRow || merged.getRowTo() >= startRow);
boolean inEnd = (merged.getRowTo() <= endRow || merged.getRowFrom() <= endRow);
//dont 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 (!merged.contains(startRow-1, (short)0) && !merged.contains(endRow+1, (short)0)){
merged.setRowFrom(merged.getRowFrom()+n);
merged.setRowTo(merged.getRowTo()+n);
//have to remove/add it back
shiftedRegions.add(merged);
this.removeMergedRegion(i);
i = i -1; // we have to back up now since we removed one
}
}
//readd so it doesn't get shifted again
Iterator iterator = shiftedRegions.iterator();
while (iterator.hasNext()) {
Region region = (Region)iterator.next();
this.addMergedRegion(region);
}
|
public 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.
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).
shiftRows(startRow, endRow, n, false, false);
|
public void | shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight)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
int s, e, inc;
if ( n < 0 )
{
s = startRow;
e = endRow;
inc = 1;
}
else
{
s = endRow;
e = startRow;
inc = -1;
}
shiftMerged(startRow, endRow, n, true);
sheet.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 );
HSSFCell cell;
// Removes the cells before over writting them.
for ( short col = row2Replace.getFirstCellNum(); col <= row2Replace.getLastCellNum(); col++ )
{
cell = row2Replace.getCell( col );
if ( cell != null )
row2Replace.removeCell( cell );
}
if (row == null) continue; // Nothing to do for this row
else {
if (copyRowHeight) {
row2Replace.setHeight(row.getHeight());
}
if (resetOriginalRowHeight) {
row.setHeight((short)0xff);
}
}
for ( short col = row.getFirstCellNum(); col <= row.getLastCellNum(); col++ )
{
cell = row.getCell( col );
if ( cell != null )
{
row.removeCell( cell );
CellValueRecordInterface cellRecord = cell.getCellValueRecord();
cellRecord.setRow( rowNum + n );
row2Replace.createCellFromRecord( cellRecord );
sheet.addValueRecord( rowNum + n, cellRecord );
}
}
}
if ( endRow == lastrow || endRow + n > lastrow ) lastrow = Math.min( endRow + n, 65535 );
if ( startRow == firstrow || startRow + n < firstrow ) firstrow = Math.max( startRow + n, 0 );
|
public void | showInPane(short toprow, short leftcol)Sets desktop window pane display area, when the
file is first opened in a viewer.
this.sheet.setTopRow((short)toprow);
this.sheet.setLeftCol((short)leftcol);
|
public void | ungroupColumn(short fromColumn, short toColumn)
sheet.groupColumnRange( fromColumn, toColumn, false );
|
public void | ungroupRow(int fromRow, int toRow)
sheet.groupRowRange( fromRow, toRow, false );
|
protected void | validateColumn(short column)Runs a bounds check for column numbers
if (column > 255) throw new IllegalArgumentException("Maximum column number is 255");
if (column < 0) throw new IllegalArgumentException("Minimum column number is 0");
|
protected void | validateRow(int row)Runs a bounds check for row numbers
if (row > 65535) throw new IllegalArgumentException("Maximum row number is 65535");
if (row < 0) throw new IllegalArgumentException("Minumum row number is 0");
|