📄 writableworkbookimpl.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: WritableWorkbookImpl.java
package jxl.write.biff;
import common.Assert;
import common.Logger;
import java.io.*;
import java.util.*;
import jxl.*;
import jxl.biff.*;
import jxl.biff.drawing.*;
import jxl.biff.formula.ExternalSheet;
import jxl.format.Colour;
import jxl.format.RGB;
import jxl.read.biff.*;
import jxl.write.*;
// Referenced classes of package jxl.write.biff:
// File, SharedStrings, Styles, WritableFonts,
// WritableFormattingRecords, CountryRecord, ExternalSheetRecord, SupbookRecord,
// ButtonPropertySetRecord, NameRecord, WritableSheetImpl, BOFRecord,
// InterfaceHeaderRecord, MMSRecord, InterfaceEndRecord, WriteAccessRecord,
// CodepageRecord, DSFRecord, TabIdRecord, ObjProjRecord,
// FunctionGroupCountRecord, WindowProtectRecord, ProtectRecord, PasswordRecord,
// Prot4RevRecord, Prot4RevPassRecord, Window1Record, BackupRecord,
// HideobjRecord, NineteenFourRecord, PrecisionRecord, RefreshAllRecord,
// BookboolRecord, UsesElfsRecord, BoundsheetRecord, ExternalNameRecord,
// EOFRecord, CellValue, JxlWriteException, DateRecord
public class WritableWorkbookImpl extends WritableWorkbook
implements ExternalSheet, WorkbookMethods
{
private static Logger logger;
private FormattingRecords formatRecords;
private jxl.write.biff.File outputFile;
private ArrayList sheets;
private Fonts fonts;
private ExternalSheetRecord externSheet;
private ArrayList supbooks;
private ArrayList names;
private HashMap nameRecords;
private SharedStrings sharedStrings;
private boolean closeStream;
private boolean wbProtected;
private WorkbookSettings settings;
private ArrayList rcirCells;
private DrawingGroup drawingGroup;
private Styles styles;
private boolean containsMacros;
private ButtonPropertySetRecord buttonPropertySet;
private CountryRecord countryRecord;
private String addInFunctionNames[];
static Class class$jxl$write$biff$WritableWorkbookImpl; /* synthetic field */
public WritableWorkbookImpl(OutputStream os, boolean cs, WorkbookSettings ws)
throws IOException
{
outputFile = new jxl.write.biff.File(os, ws, null);
sheets = new ArrayList();
sharedStrings = new SharedStrings();
nameRecords = new HashMap();
closeStream = cs;
wbProtected = false;
containsMacros = false;
settings = ws;
rcirCells = new ArrayList();
styles = new Styles();
WritableWorkbook.ARIAL_10_PT.uninitialize();
WritableWorkbook.HYPERLINK_FONT.uninitialize();
WritableWorkbook.NORMAL_STYLE.uninitialize();
WritableWorkbook.HYPERLINK_STYLE.uninitialize();
WritableWorkbook.HIDDEN_STYLE.uninitialize();
DateRecord.defaultDateFormat.uninitialize();
WritableFonts wf = new WritableFonts(this);
fonts = wf;
WritableFormattingRecords wfr = new WritableFormattingRecords(fonts, styles);
formatRecords = wfr;
}
public WritableWorkbookImpl(OutputStream os, Workbook w, boolean cs, WorkbookSettings ws)
throws IOException
{
WorkbookParser wp;
label0:
{
wp = (WorkbookParser)w;
WritableWorkbook.ARIAL_10_PT.uninitialize();
WritableWorkbook.HYPERLINK_FONT.uninitialize();
WritableWorkbook.NORMAL_STYLE.uninitialize();
WritableWorkbook.HYPERLINK_STYLE.uninitialize();
WritableWorkbook.HIDDEN_STYLE.uninitialize();
DateRecord.defaultDateFormat.uninitialize();
closeStream = cs;
sheets = new ArrayList();
sharedStrings = new SharedStrings();
nameRecords = new HashMap();
fonts = wp.getFonts();
formatRecords = wp.getFormattingRecords();
wbProtected = false;
settings = ws;
rcirCells = new ArrayList();
styles = new Styles();
outputFile = new jxl.write.biff.File(os, ws, wp.getCompoundFile());
containsMacros = false;
if(!ws.getPropertySetsDisabled())
containsMacros = wp.containsMacros();
if(wp.getCountryRecord() != null)
countryRecord = new CountryRecord(wp.getCountryRecord());
addInFunctionNames = wp.getAddInFunctionNames();
if(wp.getExternalSheetRecord() == null)
break label0;
externSheet = new ExternalSheetRecord(wp.getExternalSheetRecord());
SupbookRecord readsr[] = wp.getSupbookRecords();
supbooks = new ArrayList(readsr.length);
for(int i = 0; i < readsr.length; i++)
{
SupbookRecord readSupbook;
label1:
{
readSupbook = readsr[i];
SupbookRecord _tmp = readSupbook;
if(readSupbook.getType() != SupbookRecord.INTERNAL)
{
SupbookRecord _tmp1 = readSupbook;
if(readSupbook.getType() != SupbookRecord.EXTERNAL)
break label1;
}
supbooks.add(new jxl.write.biff.SupbookRecord(readSupbook, settings));
continue;
}
SupbookRecord _tmp2 = readSupbook;
if(readSupbook.getType() != SupbookRecord.ADDIN)
logger.warn("unsupported supbook type - ignoring");
}
}
if(wp.getDrawingGroup() != null)
drawingGroup = new DrawingGroup(wp.getDrawingGroup());
if(containsMacros && wp.getButtonPropertySet() != null)
buttonPropertySet = new ButtonPropertySetRecord(wp.getButtonPropertySet());
if(!settings.getNamesDisabled())
{
NameRecord na[] = wp.getNameRecords();
names = new ArrayList(na.length);
for(int i = 0; i < na.length; i++)
if(na[i].isBiff8())
{
jxl.write.biff.NameRecord n = new jxl.write.biff.NameRecord(na[i], i);
names.add(n);
String name = n.getName();
nameRecords.put(name, n);
} else
{
logger.warn("Cannot copy Biff7 name records - ignoring");
}
}
copyWorkbook(w);
if(drawingGroup != null)
drawingGroup.updateData(wp.getDrawingGroup());
}
public WritableSheet[] getSheets()
{
WritableSheet sheetArray[] = new WritableSheet[getNumberOfSheets()];
for(int i = 0; i < getNumberOfSheets(); i++)
sheetArray[i] = getSheet(i);
return sheetArray;
}
public String[] getSheetNames()
{
String sheetNames[] = new String[getNumberOfSheets()];
for(int i = 0; i < sheetNames.length; i++)
sheetNames[i] = getSheet(i).getName();
return sheetNames;
}
public Sheet getReadSheet(int index)
{
return getSheet(index);
}
public WritableSheet getSheet(int index)
{
return (WritableSheet)sheets.get(index);
}
public WritableSheet getSheet(String name)
{
boolean found = false;
Iterator i = sheets.iterator();
WritableSheet s = null;
do
{
if(!i.hasNext() || found)
break;
s = (WritableSheet)i.next();
if(s.getName().equals(name))
found = true;
} while(true);
return found ? s : null;
}
public int getNumberOfSheets()
{
return sheets.size();
}
public void close()
throws IOException, JxlWriteException
{
outputFile.close(closeStream);
}
public void setOutputFile(File fileName)
throws IOException
{
FileOutputStream fos = new FileOutputStream(fileName);
outputFile.setOutputFile(fos);
}
private WritableSheet createSheet(String name, int index, boolean handleRefs)
{
WritableSheet w = new WritableSheetImpl(name, outputFile, formatRecords, sharedStrings, settings, this);
int pos = index;
if(index <= 0)
{
pos = 0;
sheets.add(0, w);
} else
if(index > sheets.size())
{
pos = sheets.size();
sheets.add(w);
} else
{
sheets.add(index, w);
}
if(handleRefs && externSheet != null)
externSheet.sheetInserted(pos);
if(supbooks != null && supbooks.size() > 0)
{
jxl.write.biff.SupbookRecord supbook = (jxl.write.biff.SupbookRecord)supbooks.get(0);
if(supbook.getType() == SupbookRecord.INTERNAL)
supbook.adjustInternal(sheets.size());
}
return w;
}
public WritableSheet createSheet(String name, int index)
{
return createSheet(name, index, true);
}
public void removeSheet(int index)
{
int pos = index;
if(index <= 0)
{
pos = 0;
sheets.remove(0);
} else
if(index >= sheets.size())
{
pos = sheets.size() - 1;
sheets.remove(sheets.size() - 1);
} else
{
sheets.remove(index);
}
if(externSheet != null)
externSheet.sheetRemoved(pos);
if(supbooks != null && supbooks.size() > 0)
{
jxl.write.biff.SupbookRecord supbook = (jxl.write.biff.SupbookRecord)supbooks.get(0);
if(supbook.getType() == SupbookRecord.INTERNAL)
supbook.adjustInternal(sheets.size());
}
if(names != null && names.size() > 0)
{
for(int i = 0; i < names.size(); i++)
{
jxl.write.biff.NameRecord n = (jxl.write.biff.NameRecord)names.get(i);
int oldRef = n.getSheetRef();
if(oldRef == pos + 1)
{
n.setSheetRef(0);
continue;
}
if(oldRef <= pos + 1)
continue;
if(oldRef < 1)
oldRef = 1;
n.setSheetRef(oldRef - 1);
}
}
}
public WritableSheet moveSheet(int fromIndex, int toIndex)
{
fromIndex = Math.max(fromIndex, 0);
fromIndex = Math.min(fromIndex, sheets.size() - 1);
toIndex = Math.max(toIndex, 0);
toIndex = Math.min(toIndex, sheets.size() - 1);
WritableSheet sheet = (WritableSheet)sheets.remove(fromIndex);
sheets.add(toIndex, sheet);
return sheet;
}
public void write()
throws IOException
{
WritableSheetImpl wsi = null;
for(int i = 0; i < getNumberOfSheets(); i++)
{
wsi = (WritableSheetImpl)getSheet(i);
wsi.checkMergedBorders();
}
if(!settings.getRationalizationDisabled())
rationalize();
jxl.write.biff.BOFRecord bof = new jxl.write.biff.BOFRecord(BOFRecord.workbookGlobals);
outputFile.write(bof);
InterfaceHeaderRecord ihr = new InterfaceHeaderRecord();
outputFile.write(ihr);
MMSRecord mms = new MMSRecord(0, 0);
outputFile.write(mms);
InterfaceEndRecord ier = new InterfaceEndRecord();
outputFile.write(ier);
WriteAccessRecord wr = new WriteAccessRecord();
outputFile.write(wr);
CodepageRecord cp = new CodepageRecord();
outputFile.write(cp);
DSFRecord dsf = new DSFRecord();
outputFile.write(dsf);
TabIdRecord tabid = new TabIdRecord(getNumberOfSheets());
outputFile.write(tabid);
if(containsMacros)
{
ObjProjRecord objproj = new ObjProjRecord();
outputFile.write(objproj);
}
if(buttonPropertySet != null)
outputFile.write(buttonPropertySet);
FunctionGroupCountRecord fgcr = new FunctionGroupCountRecord();
outputFile.write(fgcr);
WindowProtectRecord wpr = new WindowProtectRecord(false);
outputFile.write(wpr);
ProtectRecord pr = new ProtectRecord(wbProtected);
outputFile.write(pr);
PasswordRecord pw = new PasswordRecord(null);
outputFile.write(pw);
Prot4RevRecord p4r = new Prot4RevRecord(false);
outputFile.write(p4r);
Prot4RevPassRecord p4rp = new Prot4RevPassRecord();
outputFile.write(p4rp);
Window1Record w1r = new Window1Record();
outputFile.write(w1r);
BackupRecord bkr = new BackupRecord(false);
outputFile.write(bkr);
HideobjRecord ho = new HideobjRecord(false);
outputFile.write(ho);
NineteenFourRecord nf = new NineteenFourRecord(false);
outputFile.write(nf);
PrecisionRecord pc = new PrecisionRecord(false);
outputFile.write(pc);
RefreshAllRecord rar = new RefreshAllRecord(false);
outputFile.write(rar);
BookboolRecord bb = new BookboolRecord(true);
outputFile.write(bb);
fonts.write(outputFile);
formatRecords.write(outputFile);
if(formatRecords.getPalette() != null)
outputFile.write(formatRecords.getPalette());
UsesElfsRecord uer = new UsesElfsRecord();
outputFile.write(uer);
int boundsheetPos[] = new int[getNumberOfSheets()];
Sheet sheet = null;
for(int i = 0; i < getNumberOfSheets(); i++)
{
boundsheetPos[i] = outputFile.getPos();
sheet = getSheet(i);
BoundsheetRecord br = new BoundsheetRecord(sheet.getName());
if(sheet.getSettings().isHidden())
br.setHidden();
if(((WritableSheetImpl)sheets.get(i)).isChartOnly())
br.setChartOnly();
outputFile.write(br);
}
if(countryRecord == null)
{
CountryCode lang = CountryCode.getCountryCode(settings.getExcelDisplayLanguage());
if(lang == CountryCode.UNKNOWN)
{
logger.warn("Unknown country code " + settings.getExcelDisplayLanguage() + " using " + CountryCode.USA.getCode());
lang = CountryCode.USA;
}
CountryCode region = CountryCode.getCountryCode(settings.getExcelRegionalSettings());
countryRecord = new CountryRecord(lang, region);
if(region == CountryCode.UNKNOWN)
{
logger.warn("Unknown country code " + settings.getExcelDisplayLanguage() + " using " + CountryCode.UK.getCode());
CountryCode countrycode = CountryCode.UK;
}
}
outputFile.write(countryRecord);
if(addInFunctionNames != null && addInFunctionNames.length > 0)
{
jxl.write.biff.SupbookRecord supbook = new jxl.write.biff.SupbookRecord();
outputFile.write(supbook);
for(int i = 0; i < addInFunctionNames.length; i++)
{
ExternalNameRecord enr = new ExternalNameRecord(addInFunctionNames[i]);
outputFile.write(enr);
}
}
if(externSheet != null)
{
for(int i = 0; i < supbooks.size(); i++)
{
jxl.write.biff.SupbookRecord supbook = (jxl.write.biff.SupbookRecord)supbooks.get(i);
outputFile.write(supbook);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -