📄 writablesheetimpl.java
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name: WritableSheetImpl.java
package jxl.write.biff;
import common.Assert;
import common.Logger;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.*;
import jxl.*;
import jxl.biff.*;
import jxl.biff.drawing.*;
import jxl.format.*;
import jxl.write.*;
// Referenced classes of package jxl.write.biff:
// RowRecord, MergedCells, SheetWriter, HyperlinkRecord,
// ColumnInfoRecord, CellValue, JxlWriteException, RowsExceededException,
// ReadNumberFormulaRecord, ReadStringFormulaRecord, ReadBooleanFormulaRecord, ReadDateFormulaRecord,
// ReadErrorFormulaRecord, SheetCopier, PLSRecord, ButtonPropertySetRecord,
// WritableWorkbookImpl, Styles, File, SharedStrings,
// HeaderRecord, FooterRecord
class WritableSheetImpl
implements WritableSheet
{
private static class ColumnInfoComparator
implements Comparator
{
public boolean equals(Object o)
{
return o == this;
}
public int compare(Object o1, Object o2)
{
if(o1 == o2)
{
return 0;
} else
{
Assert.verify(o1 instanceof ColumnInfoRecord);
Assert.verify(o2 instanceof ColumnInfoRecord);
ColumnInfoRecord ci1 = (ColumnInfoRecord)o1;
ColumnInfoRecord ci2 = (ColumnInfoRecord)o2;
return ci1.getColumn() - ci2.getColumn();
}
}
private ColumnInfoComparator()
{
}
ColumnInfoComparator(_cls1 x0)
{
this();
}
}
private static Logger logger;
private String name;
private jxl.write.biff.File outputFile;
private RowRecord rows[];
private FormattingRecords formatRecords;
private SharedStrings sharedStrings;
private TreeSet columnFormats;
private TreeSet autosizedColumns;
private ArrayList hyperlinks;
private MergedCells mergedCells;
private int numRows;
private int numColumns;
private PLSRecord plsRecord;
private ButtonPropertySetRecord buttonPropertySet;
private boolean chartOnly;
private DataValidation dataValidation;
private ArrayList rowBreaks;
private ArrayList columnBreaks;
private ArrayList drawings;
private ArrayList images;
private ArrayList validatedCells;
private ComboBox comboBox;
private boolean drawingsModified;
private SheetSettings settings;
private SheetWriter sheetWriter;
private WorkbookSettings workbookSettings;
private WritableWorkbookImpl workbook;
private static final int rowGrowSize = 10;
private static final int numRowsPerSheet = 0x10000;
private static final int maxSheetNameLength = 31;
private static final char illegalSheetNameCharacters[] = {
'*', ':', '?', '\\'
};
private static final String imageTypes[] = {
"png"
};
static Class class$jxl$write$biff$WritableSheetImpl; /* synthetic field */
public WritableSheetImpl(String n, jxl.write.biff.File of, FormattingRecords fr, SharedStrings ss, WorkbookSettings ws, WritableWorkbookImpl ww)
{
name = validateName(n);
outputFile = of;
rows = new RowRecord[0];
numRows = 0;
numColumns = 0;
chartOnly = false;
workbook = ww;
formatRecords = fr;
sharedStrings = ss;
workbookSettings = ws;
drawingsModified = false;
columnFormats = new TreeSet(new ColumnInfoComparator(null));
autosizedColumns = new TreeSet();
hyperlinks = new ArrayList();
mergedCells = new MergedCells(this);
rowBreaks = new ArrayList();
columnBreaks = new ArrayList();
drawings = new ArrayList();
images = new ArrayList();
validatedCells = new ArrayList();
settings = new SheetSettings();
sheetWriter = new SheetWriter(outputFile, this, workbookSettings);
}
public Cell getCell(String loc)
{
return getCell(CellReferenceHelper.getColumn(loc), CellReferenceHelper.getRow(loc));
}
public Cell getCell(int column, int row)
{
return getWritableCell(column, row);
}
public WritableCell getWritableCell(String loc)
{
return getWritableCell(CellReferenceHelper.getColumn(loc), CellReferenceHelper.getRow(loc));
}
public WritableCell getWritableCell(int column, int row)
{
WritableCell c = null;
if(row < rows.length && rows[row] != null)
c = rows[row].getCell(column);
if(c == null)
c = new EmptyCell(column, row);
return c;
}
public int getRows()
{
return numRows;
}
public int getColumns()
{
return numColumns;
}
public Cell findCell(String contents)
{
Cell cell = null;
boolean found = false;
for(int i = 0; i < getRows() && !found; i++)
{
Cell row[] = getRow(i);
for(int j = 0; j < row.length && !found; j++)
if(row[j].getContents().equals(contents))
{
cell = row[j];
found = true;
}
}
return cell;
}
public LabelCell findLabelCell(String contents)
{
LabelCell cell = null;
boolean found = false;
for(int i = 0; i < getRows() && !found; i++)
{
Cell row[] = getRow(i);
for(int j = 0; j < row.length && !found; j++)
if((row[j].getType() == CellType.LABEL || row[j].getType() == CellType.STRING_FORMULA) && row[j].getContents().equals(contents))
{
cell = (LabelCell)row[j];
found = true;
}
}
return cell;
}
public Cell[] getRow(int row)
{
boolean found = false;
int col;
for(col = numColumns - 1; col >= 0 && !found;)
if(getCell(col, row).getType() != CellType.EMPTY)
found = true;
else
col--;
Cell cells[] = new Cell[col + 1];
for(int i = 0; i <= col; i++)
cells[i] = getCell(i, row);
return cells;
}
public Cell[] getColumn(int col)
{
boolean found = false;
int row;
for(row = numRows - 1; row >= 0 && !found;)
if(getCell(col, row).getType() != CellType.EMPTY)
found = true;
else
row--;
Cell cells[] = new Cell[row + 1];
for(int i = 0; i <= row; i++)
cells[i] = getCell(col, i);
return cells;
}
public String getName()
{
return name;
}
public void insertRow(int row)
{
if(row < 0 || row >= numRows)
return;
RowRecord oldRows[] = rows;
if(numRows == rows.length)
rows = new RowRecord[oldRows.length + 10];
else
rows = new RowRecord[oldRows.length];
System.arraycopy(oldRows, 0, rows, 0, row);
System.arraycopy(oldRows, row, rows, row + 1, numRows - row);
for(int i = row + 1; i <= numRows; i++)
if(rows[i] != null)
rows[i].incrementRow();
HyperlinkRecord hr = null;
for(Iterator i = hyperlinks.iterator(); i.hasNext(); hr.insertRow(row))
hr = (HyperlinkRecord)i.next();
if(dataValidation != null)
dataValidation.insertRow(row);
mergedCells.insertRow(row);
ArrayList newRowBreaks = new ArrayList();
int val;
for(Iterator ri = rowBreaks.iterator(); ri.hasNext(); newRowBreaks.add(new Integer(val)))
{
val = ((Integer)ri.next()).intValue();
if(val >= row)
val++;
}
rowBreaks = newRowBreaks;
if(workbookSettings.getFormulaAdjust())
workbook.rowInserted(this, row);
numRows++;
}
public void insertColumn(int col)
{
if(col < 0 || col >= numColumns)
return;
for(int i = 0; i < numRows; i++)
if(rows[i] != null)
rows[i].insertColumn(col);
HyperlinkRecord hr = null;
Iterator i;
for(i = hyperlinks.iterator(); i.hasNext(); hr.insertColumn(col))
hr = (HyperlinkRecord)i.next();
i = columnFormats.iterator();
do
{
if(!i.hasNext())
break;
ColumnInfoRecord cir = (ColumnInfoRecord)i.next();
if(cir.getColumn() >= col)
cir.incrementColumn();
} while(true);
if(autosizedColumns.size() > 0)
{
TreeSet newAutosized = new TreeSet();
for(i = autosizedColumns.iterator(); i.hasNext();)
{
Integer colnumber = (Integer)i.next();
if(colnumber.intValue() >= col)
newAutosized.add(new Integer(colnumber.intValue() + 1));
else
newAutosized.add(colnumber);
}
autosizedColumns = newAutosized;
}
if(dataValidation != null)
dataValidation.insertColumn(col);
mergedCells.insertColumn(col);
ArrayList newColumnBreaks = new ArrayList();
int val;
for(Iterator ri = columnBreaks.iterator(); ri.hasNext(); newColumnBreaks.add(new Integer(val)))
{
val = ((Integer)ri.next()).intValue();
if(val >= col)
val++;
}
columnBreaks = newColumnBreaks;
if(workbookSettings.getFormulaAdjust())
workbook.columnInserted(this, col);
numColumns++;
}
public void removeColumn(int col)
{
if(col < 0 || col >= numColumns)
return;
for(int i = 0; i < numRows; i++)
if(rows[i] != null)
rows[i].removeColumn(col);
HyperlinkRecord hr = null;
Iterator i;
for(i = hyperlinks.iterator(); i.hasNext();)
{
hr = (HyperlinkRecord)i.next();
if(hr.getColumn() == col && hr.getLastColumn() == col)
hyperlinks.remove(hyperlinks.indexOf(hr));
else
hr.removeColumn(col);
}
if(dataValidation != null)
dataValidation.removeColumn(col);
mergedCells.removeColumn(col);
ArrayList newColumnBreaks = new ArrayList();
Iterator ri = columnBreaks.iterator();
do
{
if(!ri.hasNext())
break;
int val = ((Integer)ri.next()).intValue();
if(val != col)
{
if(val > col)
val--;
newColumnBreaks.add(new Integer(val));
}
} while(true);
columnBreaks = newColumnBreaks;
i = columnFormats.iterator();
ColumnInfoRecord removeColumn = null;
do
{
if(!i.hasNext())
break;
ColumnInfoRecord cir = (ColumnInfoRecord)i.next();
if(cir.getColumn() == col)
removeColumn = cir;
else
if(cir.getColumn() > col)
cir.decrementColumn();
} while(true);
if(removeColumn != null)
columnFormats.remove(removeColumn);
if(autosizedColumns.size() > 0)
{
TreeSet newAutosized = new TreeSet();
i = autosizedColumns.iterator();
do
{
if(!i.hasNext())
break;
Integer colnumber = (Integer)i.next();
if(colnumber.intValue() != col)
if(colnumber.intValue() > col)
newAutosized.add(new Integer(colnumber.intValue() - 1));
else
newAutosized.add(colnumber);
} while(true);
autosizedColumns = newAutosized;
}
if(workbookSettings.getFormulaAdjust())
workbook.columnRemoved(this, col);
numColumns--;
}
public void removeRow(int row)
{
if(row < 0 || row >= numRows)
return;
RowRecord oldRows[] = rows;
rows = new RowRecord[oldRows.length];
System.arraycopy(oldRows, 0, rows, 0, row);
System.arraycopy(oldRows, row + 1, rows, row, numRows - (row + 1));
for(int i = row; i < numRows; i++)
if(rows[i] != null)
rows[i].decrementRow();
HyperlinkRecord hr = null;
for(Iterator i = hyperlinks.iterator(); i.hasNext();)
{
hr = (HyperlinkRecord)i.next();
if(hr.getRow() == row && hr.getLastRow() == row)
i.remove();
else
hr.removeRow(row);
}
if(dataValidation != null)
dataValidation.removeRow(row);
mergedCells.removeRow(row);
ArrayList newRowBreaks = new ArrayList();
Iterator ri = rowBreaks.iterator();
do
{
if(!ri.hasNext())
break;
int val = ((Integer)ri.next()).intValue();
if(val != row)
{
if(val > row)
val--;
newRowBreaks.add(new Integer(val));
}
} while(true);
rowBreaks = newRowBreaks;
if(workbookSettings.getFormulaAdjust())
workbook.rowRemoved(this, row);
numRows--;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -