📄 workbookparser.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: WorkbookParser.java
package jxl.read.biff;
import common.Assert;
import common.Logger;
import java.io.File;
import java.util.*;
import jxl.*;
import jxl.biff.*;
import jxl.biff.drawing.*;
import jxl.biff.formula.ExternalSheet;
// Referenced classes of package jxl.read.biff:
// SheetImpl, BoundsheetRecord, SupbookRecord, BOFRecord,
// BiffException, Record, SSTRecord, PasswordException,
// NameRecord, NineteenFourRecord, ExternalSheetRecord, CodepageRecord,
// ExternalNameRecord, ProtectRecord, CountryRecord, ButtonPropertySetRecord,
// File, CompoundFile
public class WorkbookParser extends Workbook
implements ExternalSheet, WorkbookMethods
{
private static Logger logger;
private jxl.read.biff.File excelFile;
private int bofs;
private boolean nineteenFour;
private SSTRecord sharedStrings;
private ArrayList boundsheets;
private FormattingRecords formattingRecords;
private Fonts fonts;
private ArrayList sheets;
private SheetImpl lastSheet;
private int lastSheetIndex;
private HashMap namedRecords;
private ArrayList nameTable;
private ArrayList addInFunctions;
private ExternalSheetRecord externSheet;
private ArrayList supbooks;
private BOFRecord workbookBof;
private MsoDrawingGroupRecord msoDrawingGroup;
private ButtonPropertySetRecord buttonPropertySet;
private boolean wbProtected;
private boolean containsMacros;
private WorkbookSettings settings;
private DrawingGroup drawingGroup;
private CountryRecord countryRecord;
static Class class$jxl$read$biff$WorkbookParser; /* synthetic field */
public WorkbookParser(jxl.read.biff.File f, WorkbookSettings s)
{
excelFile = f;
boundsheets = new ArrayList(10);
fonts = new Fonts();
formattingRecords = new FormattingRecords(fonts);
sheets = new ArrayList(10);
supbooks = new ArrayList(10);
namedRecords = new HashMap();
lastSheetIndex = -1;
wbProtected = false;
containsMacros = false;
settings = s;
}
public Sheet[] getSheets()
{
Sheet sheetArray[] = new Sheet[getNumberOfSheets()];
return (Sheet[])sheets.toArray(sheetArray);
}
public Sheet getReadSheet(int index)
{
return getSheet(index);
}
public Sheet getSheet(int index)
{
if(lastSheet != null && lastSheetIndex == index)
return lastSheet;
if(lastSheet != null)
{
lastSheet.clear();
if(!settings.getGCDisabled())
System.gc();
}
lastSheet = (SheetImpl)sheets.get(index);
lastSheetIndex = index;
lastSheet.readSheet();
return lastSheet;
}
public Sheet getSheet(String name)
{
int pos = 0;
boolean found = false;
Iterator i = boundsheets.iterator();
BoundsheetRecord br = null;
while(i.hasNext() && !found)
{
br = (BoundsheetRecord)i.next();
if(br.getName().equals(name))
found = true;
else
pos++;
}
return found ? getSheet(pos) : null;
}
public String[] getSheetNames()
{
String names[] = new String[boundsheets.size()];
BoundsheetRecord br = null;
for(int i = 0; i < names.length; i++)
{
br = (BoundsheetRecord)boundsheets.get(i);
names[i] = br.getName();
}
return names;
}
public int getExternalSheetIndex(int index)
{
if(workbookBof.isBiff7())
{
return index;
} else
{
Assert.verify(externSheet != null);
int firstTab = externSheet.getFirstTabIndex(index);
return firstTab;
}
}
public int getLastExternalSheetIndex(int index)
{
if(workbookBof.isBiff7())
{
return index;
} else
{
Assert.verify(externSheet != null);
int lastTab = externSheet.getLastTabIndex(index);
return lastTab;
}
}
public String getExternalSheetName(int index)
{
if(workbookBof.isBiff7())
{
BoundsheetRecord br = (BoundsheetRecord)boundsheets.get(index);
return br.getName();
}
int supbookIndex = externSheet.getSupbookIndex(index);
SupbookRecord sr = (SupbookRecord)supbooks.get(supbookIndex);
int firstTab = externSheet.getFirstTabIndex(index);
int lastTab = externSheet.getLastTabIndex(index);
String firstTabName = "";
String lastTabName = "";
if(sr.getType() == SupbookRecord.INTERNAL)
{
if(firstTab == 65535)
{
firstTabName = "#REF";
} else
{
BoundsheetRecord br = (BoundsheetRecord)boundsheets.get(firstTab);
firstTabName = br.getName();
}
if(lastTab == 65535)
{
lastTabName = "#REF";
} else
{
BoundsheetRecord br = (BoundsheetRecord)boundsheets.get(lastTab);
lastTabName = br.getName();
}
String sheetName = firstTab != lastTab ? firstTabName + ':' + lastTabName : firstTabName;
sheetName = sheetName.indexOf(39) != -1 ? StringHelper.replace(sheetName, "'", "''") : sheetName;
return sheetName.indexOf(32) != -1 ? '\'' + sheetName + '\'' : sheetName;
}
if(sr.getType() == SupbookRecord.EXTERNAL)
{
StringBuffer sb = new StringBuffer();
File fl = new File(sr.getFileName());
sb.append("'");
sb.append(fl.getAbsolutePath());
sb.append("[");
sb.append(fl.getName());
sb.append("]");
sb.append(firstTab != 65535 ? sr.getSheetName(firstTab) : "#REF");
if(lastTab != firstTab)
sb.append(sr.getSheetName(lastTab));
sb.append("'");
return sb.toString();
} else
{
return "[UNKNOWN]";
}
}
public String getLastExternalSheetName(int index)
{
if(workbookBof.isBiff7())
{
BoundsheetRecord br = (BoundsheetRecord)boundsheets.get(index);
return br.getName();
}
int supbookIndex = externSheet.getSupbookIndex(index);
SupbookRecord sr = (SupbookRecord)supbooks.get(supbookIndex);
int lastTab = externSheet.getLastTabIndex(index);
if(sr.getType() == SupbookRecord.INTERNAL)
if(lastTab == 65535)
{
return "#REF";
} else
{
BoundsheetRecord br = (BoundsheetRecord)boundsheets.get(lastTab);
return br.getName();
}
if(sr.getType() == SupbookRecord.EXTERNAL)
{
StringBuffer sb = new StringBuffer();
File fl = new File(sr.getFileName());
sb.append("'");
sb.append(fl.getAbsolutePath());
sb.append("[");
sb.append(fl.getName());
sb.append("]");
sb.append(lastTab != 65535 ? sr.getSheetName(lastTab) : "#REF");
sb.append("'");
return sb.toString();
} else
{
return "[UNKNOWN]";
}
}
public int getNumberOfSheets()
{
return sheets.size();
}
public void close()
{
if(lastSheet != null)
lastSheet.clear();
excelFile.clear();
if(!settings.getGCDisabled())
System.gc();
}
final void addSheet(Sheet s)
{
sheets.add(s);
}
protected void parse()
throws BiffException, PasswordException
{
Record r = null;
BOFRecord bof = new BOFRecord(excelFile.next());
workbookBof = bof;
bofs++;
if(!bof.isBiff8() && !bof.isBiff7())
throw new BiffException(BiffException.unrecognizedBiffVersion);
if(!bof.isWorkbookGlobals())
throw new BiffException(BiffException.expectedGlobals);
ArrayList continueRecords = new ArrayList();
nameTable = new ArrayList();
addInFunctions = new ArrayList();
do
{
if(bofs != 1)
break;
r = excelFile.next();
if(r.getType() == Type.SST)
{
continueRecords.clear();
for(Record nextrec = excelFile.peek(); nextrec.getType() == Type.CONTINUE; nextrec = excelFile.peek())
continueRecords.add(excelFile.next());
Record records[] = new Record[continueRecords.size()];
records = (Record[])continueRecords.toArray(records);
sharedStrings = new SSTRecord(r, records, settings);
} else
{
if(r.getType() == Type.FILEPASS)
throw new PasswordException();
if(r.getType() == Type.NAME)
{
NameRecord nr = null;
if(bof.isBiff8())
nr = new NameRecord(r, settings, namedRecords.size());
else
nr = new NameRecord(r, settings, namedRecords.size(), NameRecord.biff7);
namedRecords.put(nr.getName(), nr);
nameTable.add(nr);
} else
if(r.getType() == Type.FONT)
{
FontRecord fr = null;
if(bof.isBiff8())
fr = new FontRecord(r, settings);
else
fr = new FontRecord(r, settings, FontRecord.biff7);
fonts.addFont(fr);
} else
if(r.getType() == Type.PALETTE)
{
PaletteRecord palette = new PaletteRecord(r);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -