📄 writablesheetimpl.java
字号:
/**
* Sets a column grouping
*
* @param col1 the first column of the group
* @param col2 the last column of the group
* @param collapsed should the group be collapsed?
* @exception WriteException
* @exception RowsExceededException
*/
public void setColumnGroup(int col1, int col2, boolean collapsed)
throws WriteException, RowsExceededException
{
if (col2 < col1)
{
logger.warn("Cannot merge cells - top and bottom rows incorrectly " +
"specified");
}
for (int i = col1; i <= col2; i++)
{
ColumnInfoRecord cir = getColumnInfo(i);
cir.incrementOutlineLevel();
cir.setCollapsed(collapsed);
maxColumnOutlineLevel = Math.max(maxColumnOutlineLevel,
cir.getOutlineLevel());
}
}
/**
* Unsets a column grouping
*
* @param col1 the first column to unset
* @param col2 the last column to unset
* @exception WriteException
* @exception RowsExceededException
*/
public void unsetColumnGroup(int col1, int col2)
throws WriteException, RowsExceededException
{
if (col2 < col1)
{
logger.warn("Cannot merge cells - top and bottom rows incorrectly " +
"specified");
}
for (int i = col1; i <= col2; i++)
{
ColumnInfoRecord cir = getColumnInfo(i);
cir.decrementOutlineLevel();
}
// Recalculate the max outline level
maxColumnOutlineLevel = 0;
for (Iterator it = columnFormats.iterator(); it.hasNext(); )
{
ColumnInfoRecord cir = (ColumnInfoRecord)it.next();
maxColumnOutlineLevel = Math.max(maxColumnOutlineLevel,
cir.getOutlineLevel());
}
}
/**
* Unmerges the specified cells. The Range passed in should be one that
* has been previously returned as a result of the getMergedCells method
*
* @param r the range of cells to unmerge
*/
public void unmergeCells(Range r)
{
mergedCells.unmergeCells(r);
}
/**
* Sets the header for this page
*
* @param l the print header to print on the left side
* @param c the print header to print in the centre
* @param r the print header to print on the right hand side
* @deprecated Use the sheet settings bean
*/
public void setHeader(String l, String c, String r)
{
HeaderFooter header = new HeaderFooter();
header.getLeft().append(l);
header.getCentre().append(c);
header.getRight().append(r);
settings.setHeader(header);
}
/**
* Sets the footer for this page
*
* @param l the print header to print on the left side
* @param c the print header to print in the centre
* @param r the print header to print on the right hand side
* @deprecated Use the sheet settings bean
*/
public void setFooter(String l, String c, String r)
{
HeaderFooter footer = new HeaderFooter();
footer.getLeft().append(l);
footer.getCentre().append(c);
footer.getRight().append(r);
settings.setFooter(footer);
}
/**
* Sets the page setup details
*
* @param p the page orientation
* @deprecated Use the SheetSettings bean
*/
public void setPageSetup(PageOrientation p)
{
settings.setOrientation(p);
}
/**
* Sets the page setup details
*
* @param p the page orientation
* @param hm the header margin, in inches
* @param fm the footer margin, in inches
* @deprecated Use the SheetSettings bean
*/
public void setPageSetup(PageOrientation p, double hm, double fm)
{
settings.setOrientation(p);
settings.setHeaderMargin(hm);
settings.setFooterMargin(fm);
}
/**
* Sets the page setup details
*
* @param p the page orientation
* @param ps the paper size
* @param hm the header margin, in inches
* @param fm the footer margin, in inches
* @deprecated Use the SheetSettings bean
*/
public void setPageSetup(PageOrientation p, PaperSize ps,
double hm, double fm)
{
settings.setPaperSize(ps);
settings.setOrientation(p);
settings.setHeaderMargin(hm);
settings.setFooterMargin(fm);
}
/**
* Gets the settings for this sheet
*
* @return the page settings bean
*/
public SheetSettings getSettings()
{
return settings;
}
/**
* Gets the workbook settings
*/
WorkbookSettings getWorkbookSettings()
{
return workbookSettings;
}
/**
* Forces a page break at the specified row
*
* @param row the row to break at
*/
public void addRowPageBreak(int row)
{
// First check that the row is not already present
Iterator i = rowBreaks.iterator();
boolean found = false;
while (i.hasNext() && !found)
{
if (( (Integer) i.next()).intValue() == row)
{
found = true;
}
}
if (!found)
{
rowBreaks.add(new Integer(row));
}
}
/**
* Forces a page break at the specified column
*
* @param col the column to break at
*/
public void addColumnPageBreak(int col)
{
// First check that the row is not already present
Iterator i = columnBreaks.iterator();
boolean found = false;
while (i.hasNext() && !found)
{
if (( (Integer) i.next()).intValue() == col)
{
found = true;
}
}
if (!found)
{
columnBreaks.add(new Integer(col));
}
}
/**
* Accessor for the charts. Used when copying
*
* @return the charts on this sheet
*/
private Chart[] getCharts()
{
return sheetWriter.getCharts();
}
/**
* Accessor for the drawings. Used when copying
*
* @return the drawings on this sheet
*/
private DrawingGroupObject[] getDrawings()
{
DrawingGroupObject[] dr = new DrawingGroupObject[drawings.size()];
dr = (DrawingGroupObject[]) drawings.toArray(dr);
return dr;
}
/**
* Check all the merged cells for borders. Although in an OO sense the
* logic should belong in this class, in order to reduce the bloated
* nature of the source code for this object this logic has been delegated
* to the SheetWriter
*/
void checkMergedBorders()
{
sheetWriter.setWriteData(rows,
rowBreaks,
columnBreaks,
hyperlinks,
mergedCells,
columnFormats,
maxRowOutlineLevel,
maxColumnOutlineLevel);
sheetWriter.setDimensions(getRows(), getColumns());
sheetWriter.checkMergedBorders();
}
/**
* Accessor for the workspace options
*
* @return the workspace options
*/
private WorkspaceInformationRecord getWorkspaceOptions()
{
return sheetWriter.getWorkspaceOptions();
}
/**
* Rationalizes the sheets xf index mapping
* @param xfMapping the index mapping for XFRecords
* @param fontMapping the index mapping for fonts
* @param formatMapping the index mapping for formats
*/
void rationalize(IndexMapping xfMapping,
IndexMapping fontMapping,
IndexMapping formatMapping)
{
// Rationalize the column formats
for (Iterator i = columnFormats.iterator() ; i.hasNext() ;)
{
ColumnInfoRecord cir = (ColumnInfoRecord) i.next();
cir.rationalize(xfMapping);
}
// Rationalize the row formats
for (int i = 0; i < rows.length ; i++)
{
if (rows[i] != null)
{
rows[i].rationalize(xfMapping);
}
}
// Rationalize any data that appears on the charts
Chart[] charts = getCharts();
for (int c = 0; c < charts.length; c++)
{
charts[c].rationalize(xfMapping, fontMapping, formatMapping);
}
}
/**
* Accessor for the workbook
* @return the workbook
*/
WritableWorkbookImpl getWorkbook()
{
return workbook;
}
/**
* Gets the column format for the specified column
*
* @param col the column number
* @return the column format, or NULL if the column has no specific format
* @deprecated Use getColumnView instead
*/
public CellFormat getColumnFormat(int col)
{
return getColumnView(col).getFormat();
}
/**
* Gets the column width for the specified column
*
* @param col the column number
* @return the column width, or the default width if the column has no
* specified format
* @deprecated Use getColumnView instead
*/
public int getColumnWidth(int col)
{
return getColumnView(col).getDimension();
}
/**
* Gets the column width for the specified column
*
* @param row the column number
* @return the row height, or the default height if the column has no
* specified format
* @deprecated Use getRowView instead
*/
public int getRowHeight(int row)
{
return getRowView(row).getDimension();
}
/**
* Accessor for the chart only method
*
* @return TRUE if this is a chart only, FALSE otherwise
*/
boolean isChartOnly()
{
return chartOnly;
}
/**
* Gets the row view for the specified row
*
* @param col the row number
* @return the row format, or the default format if no override is
specified
*/
public CellView getRowView(int row)
{
CellView cv = new CellView();
try
{
RowRecord rr = getRowRecord(row);
if (rr == null || rr.isDefaultHeight())
{
cv.setDimension(settings.getDefaultRowHeight());
cv.setSize(settings.getDefaultRowHeight());
}
else if (rr.isCollapsed())
{
cv.setHidden(true);
}
else
{
cv.setDimension(rr.getRowHeight());
cv.setSize(rr.getRowHeight());
}
return cv;
}
catch (RowsExceededException e)
{
// Simple return the default
cv.setDimension(settings.getDefaultRowHeight());
cv.setSize(settings.getDefaultRowHeight());
return cv;
}
}
/**
* Gets the column width for the specified column
*
* @param col the column number
* @return the column format, or the default format if no override is
specified
*/
public CellView getColumnView(int col)
{
ColumnInfoRecord cir = getColumnInfo(col);
CellView cv = new CellView();
if (cir != null)
{
cv.setDimension(cir.getWidth()/256);
cv.setSize(cir.getWidth());
cv.setHidden(cir.getHidden());
cv.setFormat(cir.getCellFormat());
}
else
{
cv.setDimension(settings.getDefaultColumnWidth()/256);
cv.setSize(settings.getDefaultColumnWidth() * 256);
}
return cv;
}
/**
* Adds an image to this sheet
*
* @param image the image to add
*/
public void addImage(WritableImage image)
{
boolean supported = false;
java.io.File imageFile = image.getImageFile();
String fileType = "?";
if (imageFile != null)
{
String fileName = imageFile.getName();
int fileTypeIndex = fileName.lastIndexOf('.');
fileType = fileTypeIndex != -1 ?
fileName.substring(fileTypeIndex+1) : "";
for (int i = 0 ; i < imageTypes.length && !supported ; i++)
{
if (fileType.equalsIgnoreCase(imageTypes[i]))
{
supported = true;
}
}
}
else
{
supported = true;
}
if (supported)
{
workbook.addDrawing(image);
drawings.add(image);
images.add(image);
}
else
{
StringBuffer message = new StringBuffer("Image type ");
message.append(fileType);
message.append(" not supported. Supported types are ");
message.append(imageTypes[0]);
for (int i = 1 ; i < imageTypes.length ; i++)
{
message.append(", ");
message.append(imageTypes[i]);
}
logger.warn(message.toString());
}
}
/**
* Gets the number of images on this sheet
*
* @return the number of images on this sheet
*/
public int getNumberOfImages()
{
return images.size();
}
/**
* Accessor for a particular image on this sheet
*
* @param i the 0-based image index number
* @return the image with the specified index number
*/
public WritableI
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -