/** * Gets the token representation of this item in RPN * * @return the bytes applicable to this formula */ public override byte[] getBytes() { byte[] data = new byte[5]; data[0] = !useAlternateCode() ? Token.REF.getCode() : Token.REF.getCode2(); IntegerHelper.getTwoBytes(row, data, 1); int grcol = column; // Set the row/column relative bits if applicable if (rowRelative) { grcol |= 0x8000; } if (columnRelative) { grcol |= 0x4000; } IntegerHelper.getTwoBytes(grcol, data, 3); return(data); }
/// <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> /// <param name="dummy">dummy overload to indicate a biff 7 workbook /// </param> public LabelRecord(Record t, FormattingRecords fr, SheetImpl si, WorkbookSettings ws, Biff7 dummy) : base(t, fr, si) { sbyte[] data = getRecord().Data; length = IntegerHelper.getInt(data[6], data[7]); _Value = StringHelper.getString(data, length, 8, ws); }
/** * Constructor * * @param pw the password */ public PasswordRecord(string pw) : base(Type.PASSWORD) { password = pw; if (pw == null) { data = new byte[2]; IntegerHelper.getTwoBytes(0, data, 0); } else { // System.Text.ASCIIEncoding encoder = new System.Text.ASCIIEncoding(); System.Text.UnicodeEncoding encoder = new System.Text.UnicodeEncoding(); byte[] passwordBytes = encoder.GetBytes(pw); int passwordHash = 0; for (int a = 0; a < passwordBytes.Length; a++) { int shifted = rotLeft15Bit(passwordBytes[a], a + 1); passwordHash ^= shifted; } passwordHash ^= passwordBytes.Length; passwordHash ^= 0xCE4B; data = new byte[2]; IntegerHelper.getTwoBytes(passwordHash, data, 0); } }
/** * Expose the protected function to the SheetImpl in this package * * @return the raw record data */ public override byte[] getData() { if (data != null) { return(data); } data = new byte[18]; // the options int options = 0; options |= (0x1 << 1); // horizontal alignment - left options |= (0x1 << 4); // vertical alignment - top options |= (0x1 << 9); // lock text IntegerHelper.getTwoBytes(options, data, 0); // the rotation // no rotation // Length of text IntegerHelper.getTwoBytes(textLength, data, 10); // Length of formatting runs IntegerHelper.getTwoBytes(0x10, data, 12); return(data); }
public override object OnValue(Type type) { if (type == typeof(bool)) { return(Stream.ReadUInt8() == 1); } else if (type == typeof(char)) { return((char)Stream.ReadUInt8()); } else if (type == typeof(short)) { return(IntegerHelper.DecodeZigzag(Stream.ReadVarUInt16())); } else if (type == typeof(int)) { return(IntegerHelper.DecodeZigzag(Stream.ReadVarUInt32())); } else if (type == typeof(Int64)) { return(IntegerHelper.DecodeZigzag(Stream.ReadVarUInt64())); } else if (type == typeof(byte)) { return(Stream.ReadUInt8()); } else if (type == typeof(ushort)) { return(Stream.ReadVarUInt16()); } else if (type == typeof(uint)) { return(Stream.ReadVarUInt32()); } else if (type == typeof(UInt64)) { return(Stream.ReadVarUInt64()); } else if (type == typeof(float)) { return(Stream.ReadFloat()); } else if (type == typeof(double)) { return(Stream.ReadDouble()); } else { if (type.IsEnum) { return(Stream.ReadVarUInt32()); } else { Logger.ErrorLine("Invalid value type:{0}", type); } } return(null); }
/// <summary> Reads the ptg data from the array starting at the specified position /// /// </summary> /// <param name="data">the RPN array /// </param> /// <param name="pos">the current position in the array, excluding the ptg identifier /// </param> /// <returns> the number of bytes read /// </returns> public virtual int read(sbyte[] data, int pos) { int ixti = IntegerHelper.getInt(data[pos], data[pos + 1]); int ilbl = IntegerHelper.getInt(data[pos + 2], data[pos + 3]); return(6); }
/** * Reads the properties */ private void readProperties() { properties = new ArrayList(); int pos = 0; byte[] bytes = getBytes(); for (int i = 0; i < numProperties; i++) { int val = IntegerHelper.getInt(bytes[pos], bytes[pos + 1]); int id = val & 0x3fff; int value = IntegerHelper.getInt(bytes[pos + 2], bytes[pos + 3], bytes[pos + 4], bytes[pos + 5]); Property p = new Property(id, (val & 0x4000) != 0, (val & 0x8000) != 0, value); pos += 6; properties.Add(p); } foreach (Property p in properties) { if (p.complex) { p.StringValue = StringHelper.getUnicodeString(bytes, p.value / 2, pos); pos += p.value; } } }
/** * Constructor * * @param w the default column width */ public DefaultColumnWidth(int w) : base(Type.DEFCOLWIDTH) { width = w; data = new byte[2]; IntegerHelper.getTwoBytes(width, data, 0); }
/// <summary> Reads the small block depot entries</summary> private void readSmallBlockDepot() { int pos = 0; int index = 0; int sbdBlock = sbdStartBlock; smallBlockChain = new int[0]; while (sbdBlock != -2) { // Allocate some more space to the small block chain int[] oldChain = smallBlockChain; smallBlockChain = new int[smallBlockChain.Length + BIG_BLOCK_SIZE / 4]; Array.Copy(oldChain, 0, smallBlockChain, 0, oldChain.Length); pos = (sbdBlock + 1) * BIG_BLOCK_SIZE; for (int j = 0; j < BIG_BLOCK_SIZE / 4; j++) { smallBlockChain[index] = IntegerHelper.getInt(data[pos], data[pos + 1], data[pos + 2], data[pos + 3]); pos += 4; index++; } sbdBlock = bigBlockChain[sbdBlock]; } }
/** * Gets the raw data for output to file * * @return the data to write to file */ public override byte[] getData() { byte[] data = new byte[ranges.Count * 8 + 2]; // Set the number of ranges IntegerHelper.getTwoBytes(ranges.Count, data, 0); int pos = 2; Range range = null; for (int i = 0; i < ranges.Count; i++) { range = (Range)ranges[i]; // Set the various cell records Cell tl = range.getTopLeft(); Cell br = range.getBottomRight(); IntegerHelper.getTwoBytes(tl.getRow(), data, pos); IntegerHelper.getTwoBytes(br.getRow(), data, pos + 2); IntegerHelper.getTwoBytes(tl.getColumn(), data, pos + 4); IntegerHelper.getTwoBytes(br.getColumn(), data, pos + 6); pos += 8; } return(data); }
/** * Expose the protected function to the SheetImpl in this package * * @return the raw record data */ public override byte[] getData() { if (data != null) { return(data); } string author = string.Empty; data = new byte[8 + author.Length + 4]; // the row IntegerHelper.getTwoBytes(row, data, 0); // the column IntegerHelper.getTwoBytes(column, data, 2); // the object id IntegerHelper.getTwoBytes(objectId, data, 6); // the length of the string IntegerHelper.getTwoBytes(author.Length, data, 8); // the string // StringHelper.getBytes(author, data, 11); // data[data.Length-1]=(byte)0x24; return(data); }
/** * 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); } }
/** * Gets the raw bytes for the formula. This will include the * parsed tokens array. Used when copying spreadsheets * * @return the raw record data * @exception FormulaException */ public override byte[] getFormulaData() { if (!getSheet().getWorkbookBof().isBiff8()) { throw new FormulaException(FormulaException.BIFF8_SUPPORTED); } // Get the tokens, taking into account the mapping from shared // formula specific values into normal values FormulaParser fp = new FormulaParser (getTokens(), this, getExternalSheet(), getNameTable(), getSheet().getWorkbook().getSettings()); fp.parse(); byte[] rpnTokens = fp.getBytes(); byte[] data = new byte[rpnTokens.Length + 22]; // Set the standard info for this cell IntegerHelper.getTwoBytes(getRow(), data, 0); IntegerHelper.getTwoBytes(getColumn(), data, 2); IntegerHelper.getTwoBytes(getXFIndex(), data, 4); DoubleHelper.getIEEEBytes(value, data, 6); // Now copy in the parsed tokens System.Array.Copy(rpnTokens, 0, data, 22, rpnTokens.Length); IntegerHelper.getTwoBytes(rpnTokens.Length, data, 20); // Lop off the standard information byte[] d = new byte[data.Length - 6]; System.Array.Copy(data, 6, d, 0, data.Length - 6); return(d); }
/** * Gets the ObjRecord subrecords for a picture * * @return the binary data for the picture */ private byte[] getPictureData() { int dataLength = COMMON_DATA_LENGTH + CLIPBOARD_FORMAT_LENGTH + PICTURE_OPTION_LENGTH + END_LENGTH; int pos = 0; byte[] data = new byte[dataLength]; // The jxl.common.data // record id IntegerHelper.getTwoBytes(0x15, data, pos); // record length IntegerHelper.getTwoBytes(COMMON_DATA_LENGTH - 4, data, pos + 2); // object type IntegerHelper.getTwoBytes(type.value, data, pos + 4); // object id IntegerHelper.getTwoBytes(objectId, data, pos + 6); // the options IntegerHelper.getTwoBytes(0x6011, data, pos + 8); pos += COMMON_DATA_LENGTH; // The clipboard format // record id IntegerHelper.getTwoBytes(0x7, data, pos); // record length IntegerHelper.getTwoBytes(CLIPBOARD_FORMAT_LENGTH - 4, data, pos + 2); // the data IntegerHelper.getTwoBytes(0xffff, data, pos + 4); pos += CLIPBOARD_FORMAT_LENGTH; // Picture option flags // record id IntegerHelper.getTwoBytes(0x8, data, pos); // record length IntegerHelper.getTwoBytes(PICTURE_OPTION_LENGTH - 4, data, pos + 2); // the data IntegerHelper.getTwoBytes(0x1, data, pos + 4); pos += CLIPBOARD_FORMAT_LENGTH; // End record id IntegerHelper.getTwoBytes(0x0, data, pos); // record length IntegerHelper.getTwoBytes(END_LENGTH - 4, data, pos + 2); // the data pos += END_LENGTH; return(data); }
/** * Constructs this object from the raw data * * @param t the raw data * @param s the sheet */ public MergedCellsRecord(Record t, Sheet s) : base(t) { byte[] data = getRecord().getData(); int numRanges = IntegerHelper.getInt(data[0], data[1]); ranges = new Range[numRanges]; int pos = 2; int firstRow = 0; int lastRow = 0; int firstCol = 0; int lastCol = 0; for (int i = 0; i < numRanges; i++) { firstRow = IntegerHelper.getInt(data[pos], data[pos + 1]); lastRow = IntegerHelper.getInt(data[pos + 2], data[pos + 3]); firstCol = IntegerHelper.getInt(data[pos + 4], data[pos + 5]); lastCol = IntegerHelper.getInt(data[pos + 6], data[pos + 7]); ranges[i] = new SheetRangeImpl(s, firstCol, firstRow, lastCol, lastRow); pos += 8; } }
/** * Constructor * * @param dg the escher stream data * @param p the current position in the stream */ public EscherRecordData(EscherStream dg, int p) { escherStream = dg; pos = p; byte[] data = escherStream.getData(); streamLength = data.Length; // First two bytes contain instance and version int value = IntegerHelper.getInt(data[pos], data[pos + 1]); // Instance value is the first 12 bits instance = (value & 0xfff0) >> 4; // Version is the last four bits version = value & 0xf; // Bytes 2 and 3 are the record id recordId = IntegerHelper.getInt(data[pos + 2], data[pos + 3]); // Length is bytes 4,5,6 and 7 length = IntegerHelper.getInt(data[pos + 4], data[pos + 5], data[pos + 6], data[pos + 7]); if (version == 0x0f) { container = true; } else { container = false; } }
/// <summary> Constructs this object from the raw data /// /// </summary> /// <param name="t">the raw data /// </param> /// <param name="ws">the workbook settings /// </param> internal ExternalSheetRecord(Record t, WorkbookSettings ws) : base(t) { sbyte[] data = getRecord().Data; 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; } }
/// <summary> Constructs the dimensions from the raw data /// /// </summary> /// <param name="t">the raw data /// </param> public PaneRecord(Record t) : base(t) { sbyte[] data = t.Data; columnsVisible = IntegerHelper.getInt(data[0], data[1]); rowsVisible = IntegerHelper.getInt(data[2], data[3]); }
/// <summary> Gets the raw bytes for the formula. This will include the /// parsed tokens array. Used when copying spreadsheets /// /// </summary> /// <returns> the raw record data /// </returns> /// <exception cref=""> FormulaException /// </exception> public override sbyte[] getFormulaData() { // Get the tokens, taking into account the mapping from shared // formula specific values into normal values FormulaParser fp = new FormulaParser(getTokens(), this, ExternalSheet, NameTable, Sheet.Workbook.Settings); fp.parse(); sbyte[] rpnTokens = fp.Bytes; sbyte[] data = new sbyte[rpnTokens.Length + 22]; // Set the standard info for this cell IntegerHelper.getTwoBytes(Row, data, 0); IntegerHelper.getTwoBytes(Column, data, 2); IntegerHelper.getTwoBytes(XFIndex, data, 4); DoubleHelper.getIEEEBytes(Value, data, 6); // Now copy in the parsed tokens Array.Copy(rpnTokens, 0, data, 22, rpnTokens.Length); IntegerHelper.getTwoBytes(rpnTokens.Length, data, 20); // Lop off the standard information sbyte[] d = new sbyte[data.Length - 6]; Array.Copy(data, 6, d, 0, data.Length - 6); return(d); }
/** * Constructor * * @param erd the escher record data */ public ClientAnchor(EscherRecordData erd) : base(erd) { byte[] bytes = getBytes(); // The properties properties = IntegerHelper.getInt(bytes[0], bytes[1]); // The x1 cell int x1Cell = IntegerHelper.getInt(bytes[2], bytes[3]); int x1Fraction = IntegerHelper.getInt(bytes[4], bytes[5]); x1 = x1Cell + (double)x1Fraction / (double)1024; // The y1 cell int y1Cell = IntegerHelper.getInt(bytes[6], bytes[7]); int y1Fraction = IntegerHelper.getInt(bytes[8], bytes[9]); y1 = y1Cell + (double)y1Fraction / (double)256; // The x2 cell int x2Cell = IntegerHelper.getInt(bytes[10], bytes[11]); int x2Fraction = IntegerHelper.getInt(bytes[12], bytes[13]); x2 = x2Cell + (double)x2Fraction / (double)1024; // The y1 cell int y2Cell = IntegerHelper.getInt(bytes[14], bytes[15]); int y2Fraction = IntegerHelper.getInt(bytes[16], bytes[17]); y2 = y2Cell + (double)y2Fraction / (double)256; }
/** * Constructs this object from the raw data * * @param t the raw data */ public BOFRecord(Record t) : base(t) { byte[] data = getRecord().getData(); version = IntegerHelper.getInt(data[0], data[1]); substreamType = IntegerHelper.getInt(data[2], data[3]); }
/** * Gets the data for writing out * * @return the binary data */ public override byte[] getData() { numClusters = clusters.Count; data = new byte[16 + numClusters * 4]; // The max shape id IntegerHelper.getFourBytes(1024 + shapesSaved, data, 0); // The number of clusters IntegerHelper.getFourBytes(numClusters, data, 4); // The number of shapes saved IntegerHelper.getFourBytes(shapesSaved, data, 8); // The number of drawings saved // IntegerHelper.getFourBytes(drawingsSaved, data, 12); IntegerHelper.getFourBytes(1, data, 12); int pos = 16; for (int i = 0; i < numClusters; i++) { Cluster c = (Cluster)clusters[i]; IntegerHelper.getTwoBytes(c.drawingGroupId, data, pos); IntegerHelper.getTwoBytes(c.shapeIdsUsed, data, pos + 2); pos += 4; } return(setHeaderData(data)); }
/** * Gets the binary data for output to file * * @return the binary data */ public override byte[] getData() { byte[] data = new byte[rknumbers.Length * 6 + 6]; // Set up the row and the first column IntegerHelper.getTwoBytes(row, data, 0); IntegerHelper.getTwoBytes(colFirst, data, 2); // Add all the rk numbers int pos = 4; int rkValue = 0; byte[] rkBytes = new byte[4]; for (int i = 0; i < rknumbers.Length; i++) { IntegerHelper.getTwoBytes(xfIndices[i], data, pos); // To represent an int as an Excel RK value, we have to // undergo some outrageous jiggery pokery, as follows: // Gets the bit representation of the number rkValue = rknumbers[i] << 2; // Set the integer bit rkValue |= 0x2; IntegerHelper.getFourBytes(rkValue, data, pos + 2); pos += 6; } // Write the number of rk numbers in this record IntegerHelper.getTwoBytes(colLast, data, pos); return(data); }
/** * Gets the binary data to be written to the output file * * @return the data to write to file */ public override byte[] getData() { data = new byte[0x0c]; IntegerHelper.getTwoBytes(column, data, 0); IntegerHelper.getTwoBytes(column, data, 2); IntegerHelper.getTwoBytes(width, data, 4); IntegerHelper.getTwoBytes(xfIndex, data, 6); // int options = 0x2; int options = 0x6 | (outlineLevel << 8); if (hidden) { options |= 0x1; } outlineLevel = ((options & 0x700) / 0x100); if (collapsed) { options |= 0x1000; } IntegerHelper.getTwoBytes(options, data, 8); // IntegerHelper.getTwoBytes(2, data, 10); return(data); }
public Sp(EscherRecordData erd) : base(erd) { shapeType = Instance; sbyte[] bytes = Bytes; shapeId = IntegerHelper.getInt(bytes[0], bytes[1], bytes[2], bytes[3]); persistenceFlags = IntegerHelper.getInt(bytes[4], bytes[5], bytes[6], bytes[7]); }
/** * Constructor * * @param t the record */ public SaveRecalcRecord(Record t) : base(t) { byte[] data = t.getData(); int mode = IntegerHelper.getInt(data[0],data[1]); recalculateOnSave = (mode == 1); }
/** * Gets the data * * @return the binary data */ public override byte[] getData() { data = new byte[8]; IntegerHelper.getFourBytes(shapeId, data, 0); IntegerHelper.getFourBytes(persistenceFlags, data, 4); return(setHeaderData(data)); }
/** * Writes outStream the big block chain * * @param startBlock the starting block of the big block chain * @param numBlocks the number of blocks in the chain * @exception IOException */ private void writeBlockChain(int startBlock, int numBlocks) { int blocksToWrite = numBlocks - 1; int blockNumber = startBlock + 1; while (blocksToWrite > 0) { int bbdBlocks = System.Math.Min(blocksToWrite, (BIG_BLOCK_SIZE - bbdPos) / 4); for (int i = 0; i < bbdBlocks; i++) { IntegerHelper.getFourBytes(blockNumber, bigBlockDepot, bbdPos); bbdPos += 4; blockNumber++; } blocksToWrite -= bbdBlocks; checkBbdPos(); } // Write the end of the block chain IntegerHelper.getFourBytes(-2, bigBlockDepot, bbdPos); bbdPos += 4; checkBbdPos(); }
/** * Gets the token representation of this item in RPN * * @return the bytes applicable to this formula */ public override byte[] getBytes() { // Get the data for the operands ParseItem[] operands = getOperands(); byte[] data = new byte[0]; for (int i = 0; i < operands.Length; i++) { byte[] opdata = operands[i].getBytes(); // Grow the array byte[] newdata = new byte[data.Length + opdata.Length]; System.Array.Copy(data, 0, newdata, 0, data.Length); System.Array.Copy(opdata, 0, newdata, data.Length, opdata.Length); data = newdata; } // Add on the operator byte byte[] fixedData = new byte[data.Length + 3]; System.Array.Copy(data, 0, fixedData, 0, data.Length); fixedData[data.Length] = !useAlternateCode() ? Token.FUNCTION.getCode() : Token.FUNCTION.getCode2(); IntegerHelper.getTwoBytes(function.getCode(), fixedData, data.Length + 1); return(fixedData); }
private IntegerHelper SetUpHelper(IInterpreterInteger parent) { IntegerHelper integerHelper = new IntegerHelper(); integerHelper.SetInterpreter(parent); return(integerHelper); }