📄 sheetcopier.java
字号:
{
jxl.write.biff.ColumnInfoRecord cir = new jxl.write.biff.ColumnInfoRecord(rcir, j);
int xfIndex = cir.getXfIndex();
XFRecord cf = (WritableCellFormat)xfRecords.get(new Integer(xfIndex));
if(cf == null)
{
CellFormat readFormat = fromSheet.getColumnView(j).getFormat();
WritableCellFormat wcf = copyCellFormat(readFormat);
}
cir.setCellFormat(cf);
cir.setHidden(rcir.getHidden());
columnFormats.add(cir);
}
}
jxl.Hyperlink hls[] = fromSheet.getHyperlinks();
for(int i = 0; i < hls.length; i++)
{
WritableHyperlink hr = new WritableHyperlink(hls[i], toSheet);
hyperlinks.add(hr);
}
jxl.Range merged[] = fromSheet.getMergedCells();
for(int i = 0; i < merged.length; i++)
mergedCells.add(new SheetRangeImpl((SheetRangeImpl)merged[i], toSheet));
try
{
RowRecord rowprops[] = fromSheet.getRowProperties();
for(int i = 0; i < rowprops.length; i++)
{
jxl.write.biff.RowRecord rr = toSheet.getRowRecord(rowprops[i].getRowNumber());
XFRecord format = rowprops[i].hasDefaultFormat() ? formatRecords.getXFRecord(rowprops[i].getXFIndex()) : null;
rr.setRowDetails(rowprops[i].getRowHeight(), rowprops[i].matchesDefaultFontHeight(), rowprops[i].isCollapsed(), format);
}
}
catch(RowsExceededException e)
{
Assert.verify(false);
}
int rowbreaks[] = fromSheet.getRowPageBreaks();
if(rowbreaks != null)
{
for(int i = 0; i < rowbreaks.length; i++)
rowBreaks.add(new Integer(rowbreaks[i]));
}
int columnbreaks[] = fromSheet.getColumnPageBreaks();
if(columnbreaks != null)
{
for(int i = 0; i < columnbreaks.length; i++)
columnBreaks.add(new Integer(columnbreaks[i]));
}
logger.warn("Importing of charts is not supported");
jxl.biff.drawing.DrawingGroupObject dr[] = fromSheet.getDrawings();
for(int i = 0; i < dr.length; i++)
{
if(dr[i] instanceof Drawing)
{
WritableImage wi = new WritableImage(dr[i], toSheet.getWorkbook().getDrawingGroup());
drawings.add(wi);
images.add(wi);
continue;
}
if(dr[i] instanceof Comment)
{
Comment c = new Comment(dr[i], toSheet.getWorkbook().getDrawingGroup(), workbookSettings);
drawings.add(c);
CellValue cv = (CellValue)toSheet.getWritableCell(c.getColumn(), c.getRow());
Assert.verify(cv.getCellFeatures() != null);
cv.getWritableCellFeatures().setCommentDrawing(c);
continue;
}
if(dr[i] instanceof Button)
{
Button b = new Button(dr[i], toSheet.getWorkbook().getDrawingGroup(), workbookSettings);
drawings.add(b);
continue;
}
if(dr[i] instanceof ComboBox)
{
ComboBox cb = new ComboBox(dr[i], toSheet.getWorkbook().getDrawingGroup(), workbookSettings);
drawings.add(cb);
}
}
DataValidation rdv = fromSheet.getDataValidation();
if(rdv != null)
{
dataValidation = new DataValidation(rdv, toSheet.getWorkbook(), toSheet.getWorkbook(), workbookSettings);
int objid = dataValidation.getComboBoxObjectId();
if(objid != 0)
comboBox = (ComboBox)drawings.get(objid);
}
sheetWriter.setWorkspaceOptions(fromSheet.getWorkspaceOptions());
if(fromSheet.getSheetBof().isChart())
{
chartOnly = true;
sheetWriter.setChartOnly();
}
if(fromSheet.getPLS() != null)
if(fromSheet.getWorkbookBof().isBiff7())
logger.warn("Cannot copy Biff7 print settings record - ignoring");
else
plsRecord = new PLSRecord(fromSheet.getPLS());
if(fromSheet.getButtonPropertySet() != null)
buttonPropertySet = new ButtonPropertySetRecord(fromSheet.getButtonPropertySet());
}
private WritableCell shallowCopyCell(Cell cell)
{
CellType ct = cell.getType();
WritableCell newCell = null;
if(ct == CellType.LABEL)
newCell = new Label((LabelCell)cell);
else
if(ct == CellType.NUMBER)
newCell = new Number((NumberCell)cell);
else
if(ct == CellType.DATE)
newCell = new DateTime((DateCell)cell);
else
if(ct == CellType.BOOLEAN)
newCell = new Boolean((BooleanCell)cell);
else
if(ct == CellType.NUMBER_FORMULA)
newCell = new ReadNumberFormulaRecord((FormulaData)cell);
else
if(ct == CellType.STRING_FORMULA)
newCell = new ReadStringFormulaRecord((FormulaData)cell);
else
if(ct == CellType.BOOLEAN_FORMULA)
newCell = new ReadBooleanFormulaRecord((FormulaData)cell);
else
if(ct == CellType.DATE_FORMULA)
newCell = new ReadDateFormulaRecord((FormulaData)cell);
else
if(ct == CellType.FORMULA_ERROR)
newCell = new ReadErrorFormulaRecord((FormulaData)cell);
else
if(ct == CellType.EMPTY && cell.getCellFormat() != null)
newCell = new Blank(cell);
return newCell;
}
private WritableCell deepCopyCell(Cell cell)
{
WritableCell c = shallowCopyCell(cell);
if(c == null)
return c;
CellFormat cf = c.getCellFormat();
int index = ((XFRecord)cf).getXFIndex();
WritableCellFormat wcf = (WritableCellFormat)xfRecords.get(new Integer(index));
if(wcf == null)
wcf = copyCellFormat(cf);
c.setCellFormat(wcf);
return c;
}
void shallowCopyCells()
{
int cells = fromSheet.getRows();
Cell row[] = null;
Cell cell = null;
for(int i = 0; i < cells; i++)
{
row = fromSheet.getRow(i);
for(int j = 0; j < row.length; j++)
{
cell = row[j];
WritableCell c = shallowCopyCell(cell);
try
{
if(c != null)
toSheet.addCell(c);
}
catch(WriteException e)
{
Assert.verify(false);
}
}
}
}
void deepCopyCells()
{
int cells = fromSheet.getRows();
Cell row[] = null;
Cell cell = null;
for(int i = 0; i < cells; i++)
{
row = fromSheet.getRow(i);
for(int j = 0; j < row.length; j++)
{
cell = row[j];
WritableCell c = deepCopyCell(cell);
try
{
if(c != null)
toSheet.addCell(c);
}
catch(WriteException e)
{
Assert.verify(false);
}
}
}
}
private WritableCellFormat copyCellFormat(CellFormat cf)
{
WritableCellFormat f;
XFRecord xfr = (XFRecord)cf;
f = new WritableCellFormat(xfr);
formatRecords.addStyle(f);
int xfIndex = xfr.getXFIndex();
xfRecords.put(new Integer(xfIndex), f);
int fontIndex = xfr.getFontIndex();
fonts.put(new Integer(fontIndex), new Integer(f.getFontIndex()));
int formatIndex = xfr.getFormatRecord();
formats.put(new Integer(formatIndex), new Integer(f.getFormatRecord()));
return f;
NumFormatRecordsException e;
e;
logger.warn("Maximum number of format records exceeded. Using default format.");
return WritableWorkbook.NORMAL_STYLE;
}
static Class class$(String x0)
{
return Class.forName(x0);
ClassNotFoundException x1;
x1;
throw new NoClassDefFoundError(x1.getMessage());
}
static
{
logger = Logger.getLogger(class$jxl$write$biff$SheetCopier != null ? class$jxl$write$biff$SheetCopier : (class$jxl$write$biff$SheetCopier = class$("jxl.write.biff.SheetCopier")));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -