/// <summary> Accessor for the binary data - used when copying /// /// </summary> /// <returns> the binary data /// </returns> public override sbyte[] getData() { // Palette was read in, but has not been changed if (read && !dirty) { return(getRecord().Data); } sbyte[] data = new sbyte[numColours * 4 + 2]; int pos = 0; // Set the number of records IntegerHelper.getTwoBytes(numColours, data, pos); // Set the rgb content for (int i = 0; i < numColours; i++) { pos = i * 4 + 2; data[pos] = (sbyte)rgbColours[i].red; data[pos + 1] = (sbyte)rgbColours[i].green; data[pos + 2] = (sbyte)rgbColours[i].blue; } return(data); }
/// <summary> Used when writing out records. This portion of the method handles the /// biff code and the .Length of the record and appends on the data retrieved /// from the subclasses /// /// </summary> /// <returns> the full record data to be written out to the compound file /// </returns> public sbyte[] getBytes() { sbyte[] data = getData(); int dataLength = data.Length; // Don't the call the automatic continuation code for now // Assert.verify(dataLength <= maxRecordLength - 4); // If the bytes .Length is greater than the max record .Length // then split out the data set into continue records if (data.Length > maxRecordLength - 4) { dataLength = maxRecordLength - 4; data = handleContinueRecords(data); } sbyte[] bytes = new sbyte[data.Length + 4]; Array.Copy(data, 0, bytes, 4, data.Length); IntegerHelper.getTwoBytes(Code, bytes, 0); IntegerHelper.getTwoBytes(dataLength, bytes, 2); return(bytes); }
/// <summary> Gets the binary data for output to file /// /// </summary> /// <returns> the binary data /// </returns> public override sbyte[] getData() { sbyte[] data = new sbyte[2]; // Hard code in the information for now IntegerHelper.getTwoBytes(wsoptions, data, 0); return(data); }
/// <summary> Used to get the data when writing out the format record /// /// </summary> /// <returns> the raw data /// </returns> public override sbyte[] getData() { data = new sbyte[formatString.Length * 2 + 3 + 2]; IntegerHelper.getTwoBytes(indexCode, data, 0); IntegerHelper.getTwoBytes(formatString.Length, data, 2); data[4] = (sbyte)1; // unicode indicator StringHelper.getUnicodeBytes(formatString, data, 5); return(data); }
/// <summary> Gets the byte data for writing out /// /// </summary> /// <returns> the raw data /// </returns> public override sbyte[] getData() { sbyte[] data = new sbyte[16 + name.Length * 2]; // Excel expects font heights in 1/20ths of a point IntegerHelper.getTwoBytes(pointHeight * EXCEL_UNITS_PER_POINT, data, 0); // Set the font attributes to be zero for now if (italic) { data[2] |= 0x2; } if (struckout) { data[2] |= 0x08; } // Set the index to the colour palette IntegerHelper.getTwoBytes(colourIndex, data, 4); // Bold style IntegerHelper.getTwoBytes(boldWeight, data, 6); // Script style IntegerHelper.getTwoBytes(scriptStyle, data, 8); // Underline style data[10] = (sbyte)underlineStyle; // Set the font family to be 0 data[11] = fontFamily; // Set the character set to be zero data[12] = characterSet; // Set the reserved bit to be zero data[13] = 0; // Set the .Length of the font name data[14] = (sbyte)name.Length; data[15] = (sbyte)1; // Copy in the string StringHelper.getUnicodeBytes(name, data, 16); return(data); }
/// <summary> Constructs an empty property set. Used when writing the file /// /// </summary> /// <param name="name">the property storage name /// </param> public PropertyStorage(BaseCompoundFile enclosingInstance, string name) { InitBlock(enclosingInstance); data = new sbyte[NExcel.Biff.BaseCompoundFile.PROPERTY_STORAGE_BLOCK_SIZE]; Assert.verify(name.Length < 32); IntegerHelper.getTwoBytes((name.Length + 1) * 2, data, NExcel.Biff.BaseCompoundFile.SIZE_OF_NAME_POS); // add one to the name .Length to allow for the null character at // the end for (int i = 0; i < name.Length; i++) { data[i * 2] = (sbyte)name[i]; } }
/// <summary> Abstract method implementation to get the raw byte data ready to write out /// /// </summary> /// <returns> The byte data /// </returns> public override sbyte[] getData() { sbyte[] data = new sbyte[4]; IntegerHelper.getTwoBytes(xfIndex, data, 0); // Set the built in bit data[1] |= (sbyte)-0x80; data[2] = (sbyte)styleNumber; // Set the outline level data[3] = (sbyte)-0x01; return(data); }
/// <summary> The number of bytes for this record exceeds the maximum record /// .Length, so a continue is required /// </summary> /// <param name="data">the raw data /// </param> /// <returns> the continued data /// </returns> private sbyte[] handleContinueRecords(sbyte[] data) { // Deduce the number of continue records int continuedData = data.Length - maxRecordLength - 4; int numContinueRecords = continuedData / (maxRecordLength - 4) + 1; // Create the new byte array, allowing for the continue records // code and .Length sbyte[] newdata = new sbyte[data.Length + numContinueRecords * 4]; // Copy the bona fide record data into the beginning of the super // record Array.Copy(data, 0, newdata, 0, maxRecordLength - 4); int oldarraypos = maxRecordLength - 4; int newarraypos = maxRecordLength - 4; // Now handle all the continue records for (int i = 0; i < numContinueRecords; i++) { // The number of bytes to add into the new array int length = System.Math.Min(data.Length - oldarraypos, maxRecordLength - 4); // Add in the continue record code IntegerHelper.getTwoBytes(NExcel.Biff.Type.CONTINUE.Value, newdata, newarraypos); IntegerHelper.getTwoBytes(length, newdata, newarraypos + 2); // Copy in as much as the new data as possible Array.Copy(data, oldarraypos, newdata, newarraypos + 4, length); // Update the position counters oldarraypos += length; newarraypos += length + 4; } return(newdata); }
/// <summary> Converts the various fields into binary data. If this object has /// been read from an Excel file rather than being requested by a user (ie. /// if the read flag is TRUE) then /// no processing takes place and the raw data is simply returned. /// /// </summary> /// <returns> the raw data for writing /// </returns> public override sbyte[] getData() { // Format rationalization process means that we always want to // regenerate the format info - even if the spreadsheet was // read in if (!formatInfoInitialized) { initializeFormatInformation(); } sbyte[] data = new sbyte[20]; IntegerHelper.getTwoBytes(fontIndex, data, 0); IntegerHelper.getTwoBytes(formatIndex, data, 2); // Do the cell attributes int cellAttributes = 0; if (this.Locked) { cellAttributes |= 0x01; } if (Hidden) { cellAttributes |= 0x02; } if (xfFormatType == style) { cellAttributes |= 0x04; parentFormat = 0xffff; } cellAttributes |= (parentFormat << 4); IntegerHelper.getTwoBytes(cellAttributes, data, 4); int alignMask = align.Value; if (wrap) { alignMask |= 0x08; } alignMask |= (valign.Value << 4); alignMask |= (orientation.Value << 8); IntegerHelper.getTwoBytes(alignMask, data, 6); // Set the borders int borderMask = leftBorder.Value; borderMask |= (rightBorder.Value << 4); borderMask |= (topBorder.Value << 8); borderMask |= (bottomBorder.Value << 12); IntegerHelper.getTwoBytes(borderMask, data, 10); // Set the border palette information if border mask is non zero // Hard code the colours to be black if (borderMask != 0) { sbyte lc = (sbyte)leftBorderColour.Value; sbyte rc = (sbyte)rightBorderColour.Value; sbyte tc = (sbyte)topBorderColour.Value; sbyte bc = (sbyte)bottomBorderColour.Value; data[12] = (sbyte)((lc & 0x7f) | ((rc & 0x01) << 7)); data[13] = (sbyte)((rc & 0x7f) >> 1); data[14] = (sbyte)((tc & 0x7f) | ((bc & 0x01) << 7)); data[15] = (sbyte)((bc & 0x7f) >> 1); } // Set the background pattern IntegerHelper.getTwoBytes(pattern.Value, data, 16); // Set the colour palette int colourPaletteMask = backgroundColour.Value; colourPaletteMask |= (0x40 << 7); IntegerHelper.getTwoBytes(colourPaletteMask, data, 18); // Set the cell options if (shrinkToFit) { options |= 0x10; } else { options &= 0xffef; } IntegerHelper.getTwoBytes(options, data, 8); return(data); }