/** * Constructor * * @param os the output stream * @param ws the configuration settings for this workbook * @param rcf the rea compound file * @exception IOException */ public File(Stream os, WorkbookSettings ws, CSharpJExcel.Jxl.Read.Biff.CompoundFile rcf) { outputStream = os; workbookSettings = ws; readCompoundFile = rcf; createDataOutput(); }
/** * Constructs this object from the raw data * * @param t the raw data * @param ws the workbook settings */ public ExternalSheetRecord(Record t, WorkbookSettings ws) : base(t) { byte[] data = getRecord().getData(); int numxtis = IntegerHelper.getInt(data[0],data[1]); if (data.Length < numxtis * 6 + 2) { xtiArray = new XTI[0]; //logger.warn("Could not process external sheets. Formulas may be compromised."); return; } xtiArray = new XTI[numxtis]; int pos = 2; for (int i = 0; i < numxtis; i++) { int s = IntegerHelper.getInt(data[pos],data[pos + 1]); int f = IntegerHelper.getInt(data[pos + 2],data[pos + 3]); int l = IntegerHelper.getInt(data[pos + 4],data[pos + 5]); xtiArray[i] = new XTI(s,f,l); pos += 6; } }
/** * Constructor used when parsing a function from a string * * @param f the function * @param a the number of arguments */ public VariableArgFunction(Function f,int a,WorkbookSettings ws) { function = f; arguments = a; readFromSheet = false; settings = ws; }
/** * Constructs this object from the raw data * * @param t the raw data * @param fr the formatting records * @param si the sheet * @param ws the workbook settings * @param dummy dummy overload to indicate a biff 7 workbook */ public RStringRecord(Record t,FormattingRecords fr,SheetImpl si,WorkbookSettings ws,Biff7 dummy) : base(t,fr,si) { byte[] data = getRecord().getData(); length = IntegerHelper.getInt(data[6],data[7]); description = StringHelper.getString(data,length,8,ws); }
/** * Constructor for external sheets * * @param fn the filename of the external supbook * @param ws the workbook settings */ public SupbookRecord(string fn, WorkbookSettings ws) : base(Type.SUPBOOK) { fileName = fn; numSheets = 1; sheetNames = new string[0]; workbookSettings = ws; type = EXTERNAL; }
/// <summary> Constructor</summary> public TokenFormulaParser(sbyte[] data, Cell c, ExternalSheet es, WorkbookMethods nt, WorkbookSettings ws) { tokenData = data; pos = 0; relativeTo = c; workbook = es; nameTable = nt; tokenStack = new Stack(); settings = ws; }
/** * Constructs this object from the raw data. Used when reading in a * format record * * @param t the raw data * @param ws the workbook settings * @param biffType biff type dummy overload */ public FormatRecord(Record t, WorkbookSettings ws, BiffType biffType) : base(t) { byte[] data = getRecord().getData(); indexCode = IntegerHelper.getInt(data[0], data[1]); initialized = true; if (biffType == biff8) { int numchars = IntegerHelper.getInt(data[2], data[3]); if (data[4] == 0) { formatString = StringHelper.getString(data, numchars, 5, ws); } else { formatString = StringHelper.getUnicodeString(data, numchars, 5); } } else { int numchars = data[2]; byte[] chars = new byte[numchars]; System.Array.Copy(data, 3, chars, 0, chars.Length); UnicodeEncoding enc = new UnicodeEncoding(); formatString = enc.GetString(chars); // formatString = new string(chars); uses platform default charset -- should be unicode, right? } date = false; number = false; // First see if this is a date format for (int i = 0; i < dateStrings.Length; i++) { string dateString = dateStrings[i]; if (formatString.IndexOf(dateString) != -1 || formatString.IndexOf(dateString.ToUpper()) != -1) { date = true; break; } } // See if this is number format - look for the # or 0 characters if (!date) { if (formatString.IndexOf('#') != -1 || formatString.IndexOf('0') != -1) { number = true; } } }
/** * Constructor */ public DataValiditySettingsRecord(Record t, ExternalSheet es, WorkbookMethods wm, WorkbookSettings ws) : base(t) { data = t.getData(); externalSheet = es; workbook = wm; workbookSettings = ws; }
/** * Constructs this object from the raw data * * @param t the raw data * @param fr the formatting records * @param si the sheet * @param ws the workbook settings */ public LabelRecord(Record t,FormattingRecords fr,SheetImpl si,WorkbookSettings ws) : base(t,fr,si) { byte[] data = getRecord().getData(); length = IntegerHelper.getInt(data[6],data[7]); if (data[8] == 0x0) description = StringHelper.getString(data,length,9,ws); else description = StringHelper.getUnicodeString(data,length,9); }
public WriteAccess(FileInfo file, TextWriter os) { WorkbookSettings ws = new WorkbookSettings(); Stream fis = new FileStream(file.FullName, FileMode.Open, FileAccess.Read); CSharpJExcel.Jxl.Read.Biff.File f = new CSharpJExcel.Jxl.Read.Biff.File(fis, ws); reader = new BiffRecordReader(f); display(ws, os); fis.Close(); }
/** * Creates a new <code>SheetWriter</code> instance. * * @param of the output file */ public SheetWriter(File of, WritableSheetImpl wsi, WorkbookSettings ws) { outputFile = of; sheet = wsi; workspaceOptions = new WorkspaceInformationRecord(); workbookSettings = ws; chartOnly = false; drawingWriter = new SheetDrawingWriter(ws); }
/** * Constructor used to create writable data validations */ public DataValidation(uint objId, ExternalSheet es, WorkbookMethods wm, WorkbookSettings ws) { workbook = wm; externalSheet = es; workbookSettings = ws; validitySettings = new ArrayList(); comboBoxObjectId = objId; copied = false; }
/** * Reads in the string * * @param d the data * @param ws the workbook settings */ private void readString(byte[] d, WorkbookSettings ws) { int pos = 0; int chars = IntegerHelper.getInt(d[0], d[1]); if (chars == 0) { value = string.Empty; return; } pos += 2; int optionFlags = d[pos]; pos++; if ((optionFlags & 0xf) != optionFlags) { // Uh oh - looks like a plain old string, not unicode // Recalculate all the positions pos = 0; chars = IntegerHelper.getInt(d[0], (byte)0); optionFlags = d[1]; pos = 2; } // See if it is an extended string bool extendedString = ((optionFlags & 0x04) != 0); // See if string contains formatting information bool richString = ((optionFlags & 0x08) != 0); if (richString) { pos += 2; } if (extendedString) { pos += 4; } // See if string is ASCII (compressed) or unicode bool asciiEncoding = ((optionFlags & 0x01) == 0); if (asciiEncoding) { value = StringHelper.getString(d, chars, pos, ws); } else { value = StringHelper.getUnicodeString(d, chars, pos); } }
/// <summary> Constructor for use when this is called when parsing a string /// /// </summary> /// <param name="sf">the built in function /// </param> /// <param name="ws">the workbook settings /// </param> public Attribute(StringFunction sf, WorkbookSettings ws) { settings = ws; if (sf.getFunction(settings) == NExcel.Biff.Formula.Function.SUM) { options |= sumMask; } else if (sf.getFunction(settings) == NExcel.Biff.Formula.Function.IF) { options |= ifMask; } }
/** * Constructor for use when this is called when parsing a string * * @param sf the built in function * @param ws the workbook settings */ public Attribute(StringFunction sf, WorkbookSettings ws) { settings = ws; if (sf.getFunction(settings) == Function.SUM) { options |= SUM_MASK; } else if (sf.getFunction(settings) == Function.IF) { options |= IF_MASK; } }
public void CellsWorkbookPostWorkbookSettingsTest() { string name = "Book1.xlsx"; WorkbookSettings settings = new WorkbookSettings(); settings.AutoCompressPictures = true; string folder = null; new Config().UpdateDataFile(folder, name); var response = instance.CellsWorkbookPostWorkbookSettings(name, settings, folder); Console.WriteLine(response); }
/// <summary> Constructs this object from the raw data /// /// </summary> /// <param name="t">the record data /// </param> /// <param name="ws">the workbook settings /// </param> /// <param name="dummy">dummy record to indicate a biff7 document /// </param> internal HeaderRecord(Record t, WorkbookSettings ws, Biff7 dummy) : base(t) { sbyte[] data = getRecord().Data; if (data.Length == 0) { return; } int chars = data[0]; header = StringHelper.getString(data, chars, 1, ws); }
/// <summary> Constructs this object from the raw excel data /// /// </summary> /// <param name="f">the excel 97 biff file /// </param> /// <param name="s">the workbook settings /// </param> public WorkbookParser(File f, WorkbookSettings s) : base() { excelFile = f; boundsheets = new ArrayList(10); fonts = new Fonts(); formattingRecords = new FormattingRecords(fonts); sheets = new ArrayList(10); supbooks = new ArrayList(10); namedRecords = new Hashtable(); lastSheetIndex = -1; wbProtected = false; settings = s; }
/** * Constructor * * @param f the excel file * @param sst the shared string table * @param fr formatting records * @param sb the bof record which indicates the start of the sheet * @param wb the bof record which indicates the start of the sheet * @param nf the 1904 flag * @param wp the workbook which this sheet belongs to * @exception BiffException */ public SheetImpl(File f, SSTRecord sst, FormattingRecords fr, BOFRecord sb, BOFRecord wb, bool nf, WorkbookParser wp) { excelFile = f; sharedStrings = sst; formattingRecords = fr; sheetBof = sb; workbookBof = wb; columnInfosArray = new ArrayList(); sharedFormulas = new ArrayList(); hyperlinks = new ArrayList(); rowProperties = new ArrayList(10); columnInfosInitialized = false; rowRecordsInitialized = false; nineteenFour = nf; workbook = wp; workbookSettings = workbook.getSettings(); // Mark the position in the stream, and then skip on until the end startPosition = f.getPos(); if (sheetBof.isChart()) { // Set the start pos to include the bof so the sheet reader can handle it startPosition -= (sheetBof.getLength() + 4); } Record r = null; int bofs = 1; while (bofs >= 1) { r = f.next(); // use this form for quick performance if (r.getCode() == Type.EOF.value) { bofs--; } if (r.getCode() == Type.BOF.value) { bofs++; } } }
/// <summary> Constructs this object from the raw data /// /// </summary> /// <param name="t">the raw data /// </param> /// <param name="fr">the formatting records /// </param> /// <param name="si">the sheet /// </param> /// <param name="ws">the workbook settings /// </param> public LabelRecord(Record t, FormattingRecords fr, SheetImpl si, WorkbookSettings ws) : base(t, fr, si) { sbyte[] data = getRecord().Data; length = IntegerHelper.getInt(data[6], data[7]); if (data[8] == 0x0) { _Value = StringHelper.getString(data, length, 9, ws); } else { _Value = StringHelper.getUnicodeString(data, length, 9); } }
/** * Constructs this object from the raw data * * @param t the record data * @param ws the workbook settings * @param dummy dummy record to indicate a biff7 document */ public FooterRecord(Record t, WorkbookSettings ws, Biff7 dummy) : base(t) { byte[] data = getRecord().getData(); if (data.Length == 0) { return; } int chars = data[0]; footer = StringHelper.getString(data, chars, 1, ws); }
/// <summary> Constructs this object from the raw data. Used when reading in a /// format record /// /// </summary> /// <param name="t">the raw data /// </param> /// <param name="ws">the workbook settings /// </param> /// <param name="biffType">biff type dummy overload /// </param> public FormatRecord(Record t, WorkbookSettings ws, BiffType biffType) : base(t) { sbyte[] data = getRecord().Data; indexCode = IntegerHelper.getInt(data[0], data[1]); initialized = true; if (biffType == biff8) { int numchars = IntegerHelper.getInt(data[2], data[3]); if (data[4] == 0) { formatString = StringHelper.getString(data, numchars, 5, ws); } else { formatString = StringHelper.getUnicodeString(data, numchars, 5); } } else { int numchars = data[2]; sbyte[] chars = new sbyte[numchars]; Array.Copy(data, 3, chars, 0, chars.Length); formatString = new string(NExcelUtils.Byte.ToCharArray(NExcelUtils.Byte.ToByteArray(chars))); } date = false; number = false; // First see if this is a date format for (int i = 0; i < dateStrings.Length; i++) { string dateString = dateStrings[i]; if (formatString.IndexOf(dateString) != -1 || formatString.IndexOf(dateString.ToUpper()) != -1) { date = true; break; } } // See if this is number format - look for the # or 0 characters if (!date) { if (formatString.IndexOf((System.Char) '#') != -1 || formatString.IndexOf((System.Char) '0') != -1) { number = true; } } }
/** * Constructor * * @param t the raw bytes * @param isBiff8 Is record BIFF8 (else BIFF7) */ public WriteAccessRecord(Record t,bool isBiff8,WorkbookSettings ws) : base(Type.WRITEACCESS) { byte[] data = t.getData(); if (isBiff8) { wauser = StringHelper.getUnicodeString(data,112 / 2,0); } else { // BIFF7 does not use unicode encoding in string int length = data[1]; wauser = StringHelper.getString(data,length,1,ws); } }
/// <summary> Constructor /// /// </summary> /// <param name="mso">a <code>MsoDrawingRecord</code> value /// </param> /// <param name="obj">an <code>ObjRecord</code> value /// </param> /// <param name="sp">an <code>int</code> value /// </param> /// <param name="ep">an <code>int</code> value /// </param> /// <param name="f">a <code>File</code> value /// </param> /// <param name="ws">the workbook settings /// </param> public Chart(MsoDrawingRecord mso, ObjRecord obj, int sp, int ep, File f, WorkbookSettings ws) { msoDrawingRecord = mso; objRecord = obj; startpos = sp; endpos = ep; file = f; workbookSettings = ws; initialized = false; // Note: mso and obj values can be null if we are creating a chart // which takes up an entire worksheet. Check that both are null or both // not null though Assert.verify((mso != null && obj != null) || (mso == null && obj == null)); }
public void CellsWorkbookPostWorkbookSettingsTest() { // TODO uncomment below to test the method and replace null with proper value string name = BOOK1; WorkbookSettings settings = new WorkbookSettings(); settings.AutoCompressPictures = true; string folder = TEMPFOLDER; UpdateDataFile(instance, folder, name); var response = instance.CellsWorkbookPostWorkbookSettings(name, settings, folder); Assert.IsInstanceOf <CellsCloudResponse>(response, "response is CellsCloudResponse"); Assert.AreEqual(response.Code, 200); }
public static byte[] getEncodedURL(string s, WorkbookSettings ws) { if (s.StartsWith("http:")) { return(getURL(s, ws)); } else if (s.StartsWith("https:")) // CML { return(getURL(s, ws)); } else { return(getFile(s, ws)); } }
/** * Constructor * * @param t the raw bytes * @param isBiff8 Is record BIFF8 (else BIFF7) */ public WriteAccessRecord(Record t, bool isBiff8, WorkbookSettings ws) : base(Type.WRITEACCESS) { byte[] data = t.getData(); if (isBiff8) { wauser = StringHelper.getUnicodeString(data, 112 / 2, 0); } else { // BIFF7 does not use unicode encoding in string int length = data[1]; wauser = StringHelper.getString(data, length, 1, ws); } }
/** * Constructs this object from the raw excel data * * @param f the excel 97 biff file * @param s the workbook settings */ public WorkbookParser(File f, WorkbookSettings s) : base() { excelFile = f; boundsheets = new ArrayList(10); fonts = new Fonts(); formattingRecords = new FormattingRecords(fonts); sheets = new ArrayList(10); supbooks = new ArrayList(10); namedRecords = new Dictionary <string, NameRecord>(); lastSheetIndex = -1; wbProtected = false; doesContainMacros = false; settings = s; xctRecords = new ArrayList(10); }
/** * Constructor used when copying sheets * * @param dvsr the record copied from a writable sheet */ public DataValiditySettingsRecord(DataValiditySettingsRecord dvsr, ExternalSheet es, WorkbookMethods w, WorkbookSettings ws) : base(Type.DV) { workbook = w; externalSheet = es; workbookSettings = ws; Assert.verify(w != null); Assert.verify(es != null); data = new byte[dvsr.data.Length]; System.Array.Copy(dvsr.data, 0, data, 0, data.Length); }
/** * Constructs this object from the raw data * * @param t the raw data * @param continuations the continuations * @param ws the workbook settings */ public SSTRecord(Record t, Record[] continuations, WorkbookSettings ws) : base(t) { // If a continue record appears in the middle of // a string, then the encoding character is repeated // Concatenate everything into one big bugger of a byte array int totalRecordLength = 0; for (int i = 0; i < continuations.Length; i++) { totalRecordLength += continuations[i].getLength(); } totalRecordLength += getRecord().getLength(); byte[] data = new byte[totalRecordLength]; // First the original data gets put in int pos = 0; System.Array.Copy(getRecord().getData(), 0, data, 0, getRecord().getLength()); pos += getRecord().getLength(); // Now copy in everything else. continuationBreaks = new int[continuations.Length]; Record r = null; for (int i = 0; i < continuations.Length; i++) { r = continuations[i]; System.Array.Copy(r.getData(), 0, data, pos, r.getLength()); continuationBreaks[i] = pos; pos += r.getLength(); } totalStrings = IntegerHelper.getInt(data[0], data[1], data[2], data[3]); uniqueStrings = IntegerHelper.getInt(data[4], data[5], data[6], data[7]); strings = new string[uniqueStrings]; readStrings(data, 8, ws); }
/** * Constructor which creates the parse tree out of tokens * * @param tokens the list of parsed tokens * @param rt the cell containing the formula * @param es a handle to the external sheet * @param nt a handle to the name table * @param ws the workbook settings * @param pc the parse context * @exception FormulaException */ public FormulaParser(byte[] tokens, Cell rt, ExternalSheet es, WorkbookMethods nt, WorkbookSettings ws) { // A null workbook bof means that it is a writable workbook and therefore // must be biff8 if (es.getWorkbookBof() != null && !es.getWorkbookBof().isBiff8()) { throw new FormulaException(FormulaException.BIFF8_SUPPORTED); } Assert.verify(nt != null); parser = new TokenFormulaParser(tokens,rt,es,nt,ws, ParseContext.DEFAULT); }
/** * Constructor which creates the parse tree out of tokens * * @param tokens the list of parsed tokens * @param rt the cell containing the formula * @param es a handle to the external sheet * @param nt a handle to the name table * @param ws the workbook settings * @param pc the parse context * @exception FormulaException */ public FormulaParser(byte[] tokens, Cell rt, ExternalSheet es, WorkbookMethods nt, WorkbookSettings ws, ParseContext pc) { // A null workbook bof means that it is a writable workbook and therefore // must be biff8 if (es.getWorkbookBof() != null && !es.getWorkbookBof().isBiff8()) { throw new FormulaException(FormulaException.BIFF8_SUPPORTED); } Assert.verify(nt != null); parser = new TokenFormulaParser(tokens, rt, es, nt, ws, pc); }
/** * Copy constructor used to copy drawings from read to write * * @param dgo the drawing group object * @param dg the drawing group * @param ws the workbook settings */ public ComboBox(DrawingGroupObject dgo, DrawingGroup dg, WorkbookSettings ws) { ComboBox d = (ComboBox)dgo; Assert.verify(d.origin == Origin.READ); msoDrawingRecord = d.msoDrawingRecord; objRecord = d.objRecord; initialized = false; origin = Origin.READ; drawingData = d.drawingData; drawingGroup = dg; drawingNumber = d.drawingNumber; drawingGroup.addDrawing(this); workbookSettings = ws; }
/** * Gets the bytes of the specified string. This will simply return the ASCII * values of the characters in the string * * @param s the string to convert into bytes * @return the ASCII values of the characters in the string */ public static byte[] getBytes(string s, WorkbookSettings ws) { try { System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); return(enc.GetBytes(s)); // CML - not sure this is right //System.Text.Encoding encoding = System.Text.Encoding.GetEncoding(ws.getEncoding()); //return encoding.GetEncoder().GetBytes(s); // return s.getBytes(ws.getEncoding()); } catch (Exception e) { // fail silently return(null); } }
/** * Constructor */ public TokenFormulaParser(byte[] data, Cell c, ExternalSheet es, WorkbookMethods nt, WorkbookSettings ws, ParseContext pc) { tokenData = data; pos = 0; relativeTo = c; workbook = es; nameTable = nt; tokenStack = new Stack <ParseItem>(); settings = ws; parseContext = pc; Assert.verify(nameTable != null); }
/** * Constructor used when reading images * * @param mso the drawing record * @param obj the object record * @param dd the drawing data for all drawings on this sheet * @param dg the drawing group * @param ws the workbook settings */ public CheckBox(MsoDrawingRecord mso, ObjRecord obj, DrawingData dd, DrawingGroup dg, WorkbookSettings ws) { drawingGroup = dg; msoDrawingRecord = mso; drawingData = dd; objRecord = obj; initialized = false; workbookSettings = ws; origin = Origin.READ; drawingData.addData(msoDrawingRecord.getData()); drawingNumber = drawingData.getNumDrawings() - 1; drawingGroup.addDrawing(this); Assert.verify(mso != null && obj != null); initialize(); }
/** * @exception IOException */ public void write(File outputFile) { if (ranges.Count == 0) { return; } WorkbookSettings ws = ((WritableSheetImpl)sheet).getWorkbookSettings(); if (!ws.getMergedCellCheckingDisabled()) { checkIntersections(); checkRanges(); } // If they will all fit into one record, then create a single // record, write them and get out if (ranges.Count < maxRangesPerSheet) { MergedCellsRecord mcr = new MergedCellsRecord(ranges); outputFile.write(mcr); return; } int numRecordsRequired = ranges.Count / maxRangesPerSheet + 1; int pos = 0; for (int i = 0; i < numRecordsRequired; i++) { int numranges = System.Math.Min(maxRangesPerSheet, ranges.Count - pos); ArrayList cells = new ArrayList(numranges); for (int j = 0; j < numranges; j++) { cells.Add(ranges[pos + j]); } MergedCellsRecord mcr = new MergedCellsRecord(cells); outputFile.write(mcr); pos += numranges; } }
/** * Constructs this object from the raw data * * @param t the raw data * @param continuations the continuations * @param ws the workbook settings */ public SSTRecord(Record t,Record[] continuations,WorkbookSettings ws) : base(t) { // If a continue record appears in the middle of // a string, then the encoding character is repeated // Concatenate everything into one big bugger of a byte array int totalRecordLength = 0; for (int i = 0; i < continuations.Length; i++) totalRecordLength += continuations[i].getLength(); totalRecordLength += getRecord().getLength(); byte[] data = new byte[totalRecordLength]; // First the original data gets put in int pos = 0; System.Array.Copy(getRecord().getData(),0, data,0,getRecord().getLength()); pos += getRecord().getLength(); // Now copy in everything else. continuationBreaks = new int[continuations.Length]; Record r = null; for (int i = 0; i < continuations.Length; i++) { r = continuations[i]; System.Array.Copy(r.getData(),0, data,pos, r.getLength()); continuationBreaks[i] = pos; pos += r.getLength(); } totalStrings = IntegerHelper.getInt(data[0],data[1], data[2],data[3]); uniqueStrings = IntegerHelper.getInt(data[4],data[5], data[6],data[7]); strings = new string[uniqueStrings]; readStrings(data,8,ws); }
/** * Constructs this object from the raw data * * @param t the raw data * @param ws the workbook settings */ public ExternalNameRecord(Record t, WorkbookSettings ws) : base(t) { byte[] data = getRecord().getData(); int options = IntegerHelper.getInt(data[0],data[1]); if (options == 0) addInFunction = true; if (!addInFunction) return; int length = data[6]; bool unicode = (data[7] != 0); if (unicode) name = StringHelper.getUnicodeString(data,length,8); else name = StringHelper.getString(data,length,8,ws); }
/** * Constructs this object from the raw data * * @param t the raw data * @param ws the workbook settings */ public SupbookRecord(Record t, WorkbookSettings ws) : base(t) { byte[] data = getRecord().getData(); // First deduce the type if (data.Length == 4) { if (data[2] == 0x01 && data[3] == 0x04) { type = INTERNAL; } else if (data[2] == 0x01 && data[3] == 0x3a) { type = ADDIN; } else { type = UNKNOWN; } } else if (data[0] == 0 && data[1] == 0) { type = LINK; } else { type = EXTERNAL; } if (type == INTERNAL) { numSheets = IntegerHelper.getInt(data[0],data[1]); } if (type == EXTERNAL) { readExternal(data,ws); } }
/** * Constructs this object from the raw data * * @param t the record data * @param ws the workbook settings */ public FooterRecord(Record t,WorkbookSettings ws) : base(t) { byte[] data = getRecord().getData(); if (data.Length == 0) { return; } int chars = IntegerHelper.getInt(data[0],data[1]); bool unicode = data[2] == 1; if (unicode) { footer = StringHelper.getUnicodeString(data,chars,3); } else { footer = StringHelper.getString(data,chars,3,ws); } }
/** * Constructs this object from the raw data * * @param t the raw data * @param s the workbook settings */ public BoundsheetRecord(Record t,WorkbookSettings s) : base(t) { byte[] data = getRecord().getData(); offset = IntegerHelper.getInt(data[0],data[1],data[2],data[3]); typeFlag = data[5]; visibilityFlag = data[4]; length = data[6]; if (data[7] == 0) { // Standard ASCII encoding byte[] bytes = new byte[length]; System.Array.Copy(data,8,bytes,0,length); name = StringHelper.getString(bytes,length,0,s); } else { // little endian Unicode encoding byte[] bytes = new byte[length * 2]; System.Array.Copy(data,8,bytes,0,length * 2); name = StringHelper.getUnicodeString(bytes,length,0); } }
/** * Reads in the string * * @param d the data * @param ws the workbook settings */ private void readString(byte[] d,WorkbookSettings ws) { int pos = 0; int chars = IntegerHelper.getInt(d[0],d[1]); if (chars == 0) { value = string.Empty; return; } pos += 2; int optionFlags = d[pos]; pos++; if ((optionFlags & 0xf) != optionFlags) { // Uh oh - looks like a plain old string, not unicode // Recalculate all the positions pos = 0; chars = IntegerHelper.getInt(d[0],(byte)0); optionFlags = d[1]; pos = 2; } // See if it is an extended string bool extendedString = ((optionFlags & 0x04) != 0); // See if string contains formatting information bool richString = ((optionFlags & 0x08) != 0); if (richString) { pos += 2; } if (extendedString) { pos += 4; } // See if string is ASCII (compressed) or unicode bool asciiEncoding = ((optionFlags & 0x01) == 0); if (asciiEncoding) { value = StringHelper.getString(d,chars,pos,ws); } else { value = StringHelper.getUnicodeString(d,chars,pos); } }
/** * Reads in all the strings from the raw data * * @param data the raw data * @param offset the offset * @param ws the workbook settings */ private void readStrings(byte[] data,int offset,WorkbookSettings ws) { int pos = offset; int numChars; byte optionFlags; string s = null; bool asciiEncoding = false; bool richString = false; bool extendedString = false; int formattingRuns = 0; int extendedRunLength = 0; for (int i = 0; i < uniqueStrings; i++) { // Read in the number of characters numChars = IntegerHelper.getInt(data[pos],data[pos + 1]); pos += 2; optionFlags = data[pos]; pos++; // See if it is an extended string extendedString = ((optionFlags & 0x04) != 0); // See if string contains formatting information richString = ((optionFlags & 0x08) != 0); if (richString) { // Read in the crun formattingRuns = IntegerHelper.getInt(data[pos],data[pos + 1]); pos += 2; } if (extendedString) { // Read in cchExtRst extendedRunLength = IntegerHelper.getInt (data[pos],data[pos + 1],data[pos + 2],data[pos + 3]); pos += 4; } // See if string is ASCII (compressed) or unicode asciiEncoding = ((optionFlags & 0x01) == 0); ByteArrayHolder bah = new ByteArrayHolder(); BooleanHolder bh = new BooleanHolder(); bh.value = asciiEncoding; pos += getChars(data,bah,pos,bh,numChars); asciiEncoding = bh.value; if (asciiEncoding) { s = StringHelper.getString(bah.bytes,numChars,0,ws); } else { s = StringHelper.getUnicodeString(bah.bytes,numChars,0); } strings[i] = s; // For rich strings, skip over the formatting runs if (richString) { pos += 4 * formattingRuns; } // For extended strings, skip over the extended string data if (extendedString) { pos += extendedRunLength; } if (pos > data.Length) { Assert.verify(false,"pos exceeds record length"); } } }
/** * Constructor used when copying from an external workbook */ public SupbookRecord(CSharpJExcel.Jxl.Read.Biff.SupbookRecord sr, WorkbookSettings ws) : base(Type.SUPBOOK) { workbookSettings = ws; if (sr.getType() == SupbookRecord.INTERNAL) { type = INTERNAL; numSheets = sr.getNumberOfSheets(); } else if (sr.getType() == SupbookRecord.EXTERNAL) { type = EXTERNAL; numSheets = sr.getNumberOfSheets(); fileName = sr.getFileName(); sheetNames = new string[numSheets]; for (int i = 0; i < numSheets; i++) sheetNames[i] = sr.getSheetName(i); } if (sr.getType() == SupbookRecord.ADDIN) { //logger.warn("Supbook type is addin"); } }
/** * Constructs this string formula * * @param t the record * @param excelFile the excel file * @param fr the formatting record * @param es the external sheet * @param nt the workbook * @param si the sheet * @param ws the workbook settings */ public SharedStringFormulaRecord(Record t, File excelFile, FormattingRecords fr, ExternalSheet es, WorkbookMethods nt, SheetImpl si, WorkbookSettings ws) : base(t,fr,es,nt,si,excelFile.getPos()) { int pos = excelFile.getPos(); // Save the position in the excel file int filepos = excelFile.getPos(); // Look for the string record in one of the records after the // formula. Put a cap on it to prevent ednas Record nextRecord = excelFile.next(); int count = 0; while (nextRecord.getType() != Type.STRING && count < 4) { nextRecord = excelFile.next(); count++; } Assert.verify(count < 4," @ " + pos); byte[] stringData = nextRecord.getData(); // Read in any continuation records nextRecord = excelFile.peek(); while (nextRecord.getType() == Type.CONTINUE) { nextRecord = excelFile.next(); // move the pointer within the data byte[] d = new byte[stringData.Length + nextRecord.getLength() - 1]; System.Array.Copy(stringData,0,d,0,stringData.Length); System.Array.Copy(nextRecord.getData(),1,d, stringData.Length,nextRecord.getLength() - 1); stringData = d; nextRecord = excelFile.peek(); } int chars = IntegerHelper.getInt(stringData[0],stringData[1]); bool unicode = false; int startpos = 3; if (stringData.Length == chars + 2) { // string might only consist of a one byte length indicator, instead // of the more normal 2 startpos = 2; unicode = false; } else if (stringData[2] == 0x1) { // unicode string, two byte length indicator startpos = 3; unicode = true; } else { // ascii string, two byte length indicator startpos = 3; unicode = false; } if (!unicode) { value = StringHelper.getString(stringData,chars,startpos,ws); } else { value = StringHelper.getUnicodeString(stringData,chars,startpos); } // Restore the position in the excel file, to enable the SHRFMLA // record to be picked up excelFile.setPos(filepos); }
/** * If this formula was on an imported sheet, check that * cell references to another sheet are warned appropriately * * @return TRUE if this formula was able to be imported, FALSE otherwise */ public bool handleImportedCellReferences(ExternalSheet es, WorkbookMethods mt, WorkbookSettings ws) { try { if (parser == null) { byte[] formulaData = formula.getFormulaData(); byte[] formulaBytes = new byte[formulaData.Length - 16]; System.Array.Copy(formulaData, 16, formulaBytes, 0, formulaBytes.Length); parser = new FormulaParser(formulaBytes, this, es, mt, ws); parser.parse(); } return parser.handleImportedCellReferences(); } catch (FormulaException e) { //logger.warn("cannot import formula: " + e.Message); return false; } }
/** * Constructs this object from the raw data * * @param t the raw data * @param ws the workbook settings * @param ind the index in the name table */ public NameRecord(Record t,WorkbookSettings ws,int ind) : base(t) { index = ind; isbiff8 = true; try { ranges = new ArrayList(); byte[] data = getRecord().getData(); int option = IntegerHelper.getInt(data[0],data[1]); int length = data[3]; sheetRef = IntegerHelper.getInt(data[8],data[9]); if ((option & builtIn) != 0) { builtInName = BuiltInName.getBuiltInName(data[15]); } else { name = StringHelper.getString(data,length,15,ws); } if ((option & commandMacro) != 0) { // This is a command macro, so it has no cell references return; } int pos = length + 15; if (data[pos] == cellReference) { int sheet = IntegerHelper.getInt(data[pos + 1],data[pos + 2]); int row = IntegerHelper.getInt(data[pos + 3],data[pos + 4]); int columnMask = IntegerHelper.getInt(data[pos + 5],data[pos + 6]); int column = columnMask & 0xff; // Check that we are not dealing with offsets Assert.verify((columnMask & 0xc0000) == 0); NameRange r = new NameRange(sheet,column,row,column,row); ranges.Add(r); } else if (data[pos] == areaReference) { int sheet1 = 0; int r1 = 0; int columnMask = 0; int c1 = 0; int r2 = 0; int c2 = 0; NameRange range = null; while (pos < data.Length) { sheet1 = IntegerHelper.getInt(data[pos + 1],data[pos + 2]); r1 = IntegerHelper.getInt(data[pos + 3],data[pos + 4]); r2 = IntegerHelper.getInt(data[pos + 5],data[pos + 6]); columnMask = IntegerHelper.getInt(data[pos + 7],data[pos + 8]); c1 = columnMask & 0xff; // Check that we are not dealing with offsets Assert.verify((columnMask & 0xc0000) == 0); columnMask = IntegerHelper.getInt(data[pos + 9],data[pos + 10]); c2 = columnMask & 0xff; // Check that we are not dealing with offsets Assert.verify((columnMask & 0xc0000) == 0); range = new NameRange(sheet1,c1,r1,c2,r2); ranges.Add(range); pos += 11; } } else if (data[pos] == subExpression) { int sheet1 = 0; int r1 = 0; int columnMask = 0; int c1 = 0; int r2 = 0; int c2 = 0; NameRange range = null; // Consume unnecessary parsed tokens if (pos < data.Length && data[pos] != cellReference && data[pos] != areaReference) { if (data[pos] == subExpression) { pos += 3; } else if (data[pos] == union) { pos += 1; } } while (pos < data.Length) { sheet1 = IntegerHelper.getInt(data[pos + 1],data[pos + 2]); r1 = IntegerHelper.getInt(data[pos + 3],data[pos + 4]); r2 = IntegerHelper.getInt(data[pos + 5],data[pos + 6]); columnMask = IntegerHelper.getInt(data[pos + 7],data[pos + 8]); c1 = columnMask & 0xff; // Check that we are not dealing with offsets Assert.verify((columnMask & 0xc0000) == 0); columnMask = IntegerHelper.getInt(data[pos + 9],data[pos + 10]); c2 = columnMask & 0xff; // Check that we are not dealing with offsets Assert.verify((columnMask & 0xc0000) == 0); range = new NameRange(sheet1,c1,r1,c2,r2); ranges.Add(range); pos += 11; // Consume unnecessary parsed tokens if (pos < data.Length && data[pos] != cellReference && data[pos] != areaReference) { if (data[pos] == subExpression) { pos += 3; } else if (data[pos] == union) { pos += 1; } } } } else { string n = name != null ? name : builtInName.getName(); //logger.warn("Cannot read name ranges for " + n + " - setting to empty"); NameRange range = new NameRange(0,0,0,0,0); ranges.Add(range); } } catch (Exception t1) { // Generate a warning // Names are really a nice to have, and we don't want to halt the // reading process for functionality that probably won't be used //logger.warn("Cannot read name"); name = "ERROR"; } }
/** * Copy constructor used to copy drawings from read to write * * @param dgo the drawing group object * @param dg the drawing group * @param ws the workbook settings */ /*protected*/ public Comment(DrawingGroupObject dgo, DrawingGroup dg, WorkbookSettings ws) { Comment d = (Comment)dgo; Assert.verify(d.origin == Origin.READ); msoDrawingRecord = d.msoDrawingRecord; objRecord = d.objRecord; initialized = false; origin = Origin.READ; drawingData = d.drawingData; drawingGroup = dg; drawingNumber = d.drawingNumber; drawingGroup.addDrawing(this); mso = d.mso; txo = d.txo; text = d.text; formatting = d.formatting; note = d.note; width = d.width; height = d.height; workbookSettings = ws; }
/** * Constructs this object from the raw data * * @param t the raw data * @param s the sheet * @param ws the workbook settings */ public HyperlinkRecord(Record t,Sheet s,WorkbookSettings ws) : base(t) { linkType = unknown; byte[] data = getRecord().getData(); // Build up the range of cells occupied by this hyperlink firstRow = IntegerHelper.getInt(data[0],data[1]); lastRow = IntegerHelper.getInt(data[2],data[3]); firstColumn = IntegerHelper.getInt(data[4],data[5]); lastColumn = IntegerHelper.getInt(data[6],data[7]); range = new SheetRangeImpl(s, firstColumn,firstRow, lastColumn,lastRow); int options = IntegerHelper.getInt(data[28],data[29],data[30],data[31]); bool description = (options & 0x14) != 0; int startpos = 32; int descbytes = 0; if (description) { int descchars = IntegerHelper.getInt(data[startpos],data[startpos + 1],data[startpos + 2],data[startpos + 3]); descbytes = descchars * 2 + 4; } startpos += descbytes; bool targetFrame = (options & 0x80) != 0; int targetbytes = 0; if (targetFrame) { int targetchars = IntegerHelper.getInt(data[startpos],data[startpos + 1],data[startpos + 2],data[startpos + 3]); targetbytes = targetchars * 2 + 4; } startpos += targetbytes; // Try and determine the type if ((options & 0x3) == 0x03) { linkType = urlLink; // check the guid monicker if (data[startpos] == 0x03) linkType = fileLink; } else if ((options & 0x01) != 0) { linkType = fileLink; // check the guid monicker if (data[startpos] == (byte)0xe0) { linkType = urlLink; } } else if ((options & 0x08) != 0) { linkType = workbookLink; } // Try and determine the type if (linkType == urlLink) { string urlString = null; try { startpos += 16; // Get the url, ignoring the 0 char at the end int bytes = IntegerHelper.getInt(data[startpos], data[startpos + 1], data[startpos + 2], data[startpos + 3]); urlString = StringHelper.getUnicodeString(data,bytes / 2 - 1, startpos + 4); url = new Uri(urlString); } catch (UriFormatException e) { //logger.warn("URL " + urlString + " is malformed. Trying a file"); try { linkType = fileLink; file = new FileInfo(urlString); } catch (Exception e3) { //logger.warn("Cannot set to file. Setting a default URL"); // Set a default URL try { linkType = urlLink; url = new Uri("http://www.andykhan.com/jexcelapi/index.html"); } catch (UriFormatException e2) { // fail silently } } } catch (Exception e) { //StringBuilder sb1 = new StringBuilder(); //StringBuilder sb2 = new StringBuilder(); //CellReferenceHelper.getCellReference(firstColumn,firstRow,sb1); //CellReferenceHelper.getCellReference(lastColumn,lastRow,sb2); //sb1.Insert(0,"Exception when parsing URL "); //sb1.Append('\"').Append(sb2.ToString()).Append("\". Using default."); //logger.warn(sb1,e); // Set a default URL try { url = new Uri("http://www.andykhan.com/jexcelapi/index.html"); } catch (UriFormatException e2) { // fail silently } } } else if (linkType == fileLink) { try { startpos += 16; // Get the name of the local file, ignoring the zero character at the // end int upLevelCount = IntegerHelper.getInt(data[startpos], data[startpos + 1]); int chars = IntegerHelper.getInt(data[startpos + 2], data[startpos + 3], data[startpos + 4], data[startpos + 5]); string fileName = StringHelper.getString(data,chars - 1, startpos + 6,ws); StringBuilder sb = new StringBuilder(); for (int i = 0; i < upLevelCount; i++) { sb.Append("..\\"); } sb.Append(fileName); file = new FileInfo(sb.ToString()); } catch (Exception e) { //logger.warn("Exception when parsing file " + e.getClass().getName() + "."); file = new FileInfo("."); } } else if (linkType == workbookLink) { int chars = IntegerHelper.getInt(data[32],data[33],data[34],data[35]); location = StringHelper.getUnicodeString(data,chars - 1,36); } else { // give up //logger.warn("Cannot determine link type"); return; } }
/** * Constructor used when copying sheets * * @param dvsr the record copied from a writable sheet */ public DataValiditySettingsRecord(DataValiditySettingsRecord dvsr, ExternalSheet es, WorkbookMethods w, WorkbookSettings ws) : base(Type.DV) { workbook = w; externalSheet = es; workbookSettings = ws; Assert.verify(w != null); Assert.verify(es != null); data = new byte[dvsr.data.Length]; System.Array.Copy(dvsr.data,0,data,0,data.Length); }
/** * Constructor for internal sheets */ public SupbookRecord(int sheets, WorkbookSettings ws) : base(Type.SUPBOOK) { numSheets = sheets; type = INTERNAL; workbookSettings = ws; }
/** * Constructor */ public TokenFormulaParser(byte[] data, Cell c, ExternalSheet es, WorkbookMethods nt, WorkbookSettings ws, ParseContext pc) { tokenData = data; pos = 0; relativeTo = c; workbook = es; nameTable = nt; tokenStack = new Stack<ParseItem>(); settings = ws; parseContext = pc; Assert.verify(nameTable != null); }
/** * Constructs this object from the raw data * * @param t the raw data * @param ws the workbook settings * @param ind the index in the name table * @param dummy dummy parameter to indicate a biff7 workbook */ public NameRecord(Record t,WorkbookSettings ws,int ind,Biff7 dummy) : base(t) { index = ind; isbiff8 = false; try { ranges = new ArrayList(); byte[] data = getRecord().getData(); int length = data[3]; sheetRef = IntegerHelper.getInt(data[8],data[9]); name = StringHelper.getString(data,length,14,ws); int pos = length + 14; if (pos >= data.Length) { // There appears to be nothing after the name, so return return; } if (data[pos] == cellReference) { int sheet = IntegerHelper.getInt(data[pos + 11],data[pos + 12]); int row = IntegerHelper.getInt(data[pos + 15],data[pos + 16]); int column = data[pos + 17]; NameRange r = new NameRange(sheet,column,row,column,row); ranges.Add(r); } else if (data[pos] == areaReference) { int sheet1 = 0; int r1 = 0; int c1 = 0; int r2 = 0; int c2 = 0; NameRange range = null; while (pos < data.Length) { sheet1 = IntegerHelper.getInt(data[pos + 11],data[pos + 12]); r1 = IntegerHelper.getInt(data[pos + 15],data[pos + 16]); r2 = IntegerHelper.getInt(data[pos + 17],data[pos + 18]); c1 = data[pos + 19]; c2 = data[pos + 20]; range = new NameRange(sheet1,c1,r1,c2,r2); ranges.Add(range); pos += 21; } } else if (data[pos] == subExpression) { int sheet1 = 0; // int sheet2 = 0; int r1 = 0; int c1 = 0; int r2 = 0; int c2 = 0; NameRange range = null; // Consume unnecessary parsed tokens if (pos < data.Length && data[pos] != cellReference && data[pos] != areaReference) { if (data[pos] == subExpression) pos += 3; else if (data[pos] == union) pos += 1; } while (pos < data.Length) { sheet1 = IntegerHelper.getInt(data[pos + 11],data[pos + 12]); r1 = IntegerHelper.getInt(data[pos + 15],data[pos + 16]); r2 = IntegerHelper.getInt(data[pos + 17],data[pos + 18]); c1 = data[pos + 19]; c2 = data[pos + 20]; range = new NameRange(sheet1,c1,r1,c2,r2); ranges.Add(range); pos += 21; // Consume unnecessary parsed tokens if (pos < data.Length && data[pos] != cellReference && data[pos] != areaReference) { if (data[pos] == subExpression) pos += 3; else if (data[pos] == union) pos += 1; } } } } catch (Exception t1) { // Generate a warning // Names are really a nice to have, and we don't want to halt the // reading process for functionality that probably won't be used //logger.warn("Cannot read name."); name = "ERROR"; } }
/** * Constructor * * @param ws the workbook settings */ public SheetDrawingWriter(WorkbookSettings ws) { charts = new Chart[0]; }
/** * Constructor used when reading images * * @param mso the drawing record * @param obj the object record * @param dd the drawing data for all drawings on this sheet * @param dg the drawing group * @param ws the workbook settings */ public ComboBox(MsoDrawingRecord mso,ObjRecord obj,DrawingData dd, DrawingGroup dg,WorkbookSettings ws) { drawingGroup = dg; msoDrawingRecord = mso; drawingData = dd; objRecord = obj; initialized = false; workbookSettings = ws; origin = Origin.READ; drawingData.addData(msoDrawingRecord.getData()); drawingNumber = drawingData.getNumDrawings() - 1; drawingGroup.addDrawing(this); Assert.verify(mso != null && obj != null); initialize(); }
/** * Constructs this object from the raw data. We need to use the excelFile * to retrieve the string record which follows this formula record * * @param t the raw data * @param excelFile the excel file * @param fr the formatting records * @param es the external sheet records * @param nt the workbook * @param si the sheet impl * @param ws the workbook settings */ public StringFormulaRecord(Record t,File excelFile, FormattingRecords fr, ExternalSheet es, WorkbookMethods nt, SheetImpl si, WorkbookSettings ws) : base(t,fr,si) { externalSheet = es; nameTable = nt; data = getRecord().getData(); int pos = excelFile.getPos(); // Look for the string record in one of the records after the // formula. Put a cap on it to prevent looping Record nextRecord = excelFile.next(); int count = 0; while (nextRecord.getType() != Type.STRING && count < 4) { nextRecord = excelFile.next(); count++; } Assert.verify(count < 4," @ " + pos); byte[] stringData = nextRecord.getData(); // Read in any continuation records nextRecord = excelFile.peek(); while (nextRecord.getType() == Type.CONTINUE) { nextRecord = excelFile.next(); // move the pointer within the data byte[] d = new byte[stringData.Length + nextRecord.getLength() - 1]; System.Array.Copy(stringData,0,d,0,stringData.Length); System.Array.Copy(nextRecord.getData(),1,d, stringData.Length,nextRecord.getLength() - 1); stringData = d; nextRecord = excelFile.peek(); } readString(stringData,ws); }