public SupBookRecord(UnicodeString url, UnicodeString[] sheetNames)
 {
     field_1_number_of_sheets = (short)sheetNames.Length;
     field_2_encoded_url = url;
     field_3_sheet_names = sheetNames;
     _isAddInFunctions = false;
 }
 private SupBookRecord(bool IsAddInFuncs, short numberOfSheets)
 {
     // else not 'External References'
     field_1_number_of_sheets = numberOfSheets;
     field_2_encoded_url = null;
     field_3_sheet_names = null;
     _isAddInFunctions = IsAddInFuncs;
 }
 /**
  * This Is the starting point where strings are constructed.  Note that
  * strings may span across multiple continuations. Read the SST record
  * carefully before beginning to hack.
  */
 public void ManufactureStrings(int stringCount, RecordInputStream in1)
 {
     for (int i = 0; i < stringCount; i++)
     {
         //Extract exactly the count of strings from the SST record.
         UnicodeString str = new UnicodeString(in1);
         AddToStringTable(strings, str);
     }
 }
     /**
      * Note - a value of zero for <tt>amountUsedInCurrentRecord</tt> would only ever occur just
      * After a {@link ContinueRecord} had been started.  In the Initial {@link SSTRecord} this 
      * value starts at 8 (for the first {@link UnicodeString} written).  In general, it can be
      * any value between 0 and {@link #MAX_DATA_SIZE}
      */
     private static void ConfirmSize(int expectedSize, UnicodeString s, int amountUsedInCurrentRecord) {
     ContinuableRecordOutput out1 = ContinuableRecordOutput.CreateForCountingOnly();
     out1.WriteContinue();
     for(int i=amountUsedInCurrentRecord; i>0; i--) {
         out1.WriteByte(0);
     }
     int size0 = out1.TotalSize;
     s.Serialize(out1);
     int size1 = out1.TotalSize;
     int actualSize = size1-size0;
     Assert.AreEqual(expectedSize, actualSize);
 }
Exemple #5
0
 /**
  * This Is the starting point where strings are constructed.  Note that
  * strings may span across multiple continuations. Read the SST record
  * carefully before beginning to hack.
  */
 public void ManufactureStrings(int stringCount, RecordInputStream in1)
 {
     for (int i = 0; i < stringCount; i++)
     {
         // Extract exactly the count of strings from the SST record.
         UnicodeString str;
         if (in1.Available() == 0 && !in1.HasNextRecord)
         {
             System.Console.WriteLine("Ran out of data before creating all the strings! String at index " + i + "");
             str = new UnicodeString("");
         }
         else
         {
             str = new UnicodeString(in1);
         }
         AddToStringTable(strings, str);
     }
 }
Exemple #6
0
        /**
         * Add a string.
         *
         * @param string string to be Added
         *
         * @return the index of that string in the table
         */
        public int AddString(UnicodeString str)
        {
            field_1_num_strings++;
            UnicodeString ucs = (str == null) ? EMPTY_STRING
                    : str;
            int rval;
            int index = field_3_strings.GetIndex(ucs);

            if (index != -1)
            {
                rval = index;
            }
            else
            {
                // This is a new string -- we didn't see it among the
                // strings we've already collected
                rval = field_3_strings.Size;
                field_2_num_unique_strings++;
                SSTDeserializer.AddToStringTable(field_3_strings, ucs);
            }
            return rval;
        }
Exemple #7
0
        public DVRecord(int validationType, int operator1, int errorStyle, bool emptyCellAllowed,
            bool suppressDropDownArrow, bool isExplicitList,
            bool showPromptBox, String promptTitle, String promptText,
            bool showErrorBox, String errorTitle, String errorText,
            Ptg[] formula1, Ptg[] formula2,
            CellRangeAddressList regions)
        {

            int flags = 0;
            flags = opt_data_type.SetValue(flags, validationType);
            flags = opt_condition_operator.SetValue(flags, operator1);
            flags = opt_error_style.SetValue(flags, errorStyle);
            flags = opt_empty_cell_allowed.SetBoolean(flags, emptyCellAllowed);
            flags = opt_suppress_dropdown_arrow.SetBoolean(flags, suppressDropDownArrow);
            flags = opt_string_list_formula.SetBoolean(flags, isExplicitList);
            flags = opt_show_prompt_on_cell_selected.SetBoolean(flags, showPromptBox);
            flags = opt_show_error_on_invalid_value.SetBoolean(flags, showErrorBox);
            _option_flags = flags;
            _promptTitle = ResolveTitleText(promptTitle);
            _promptText = ResolveTitleText(promptText);
            _errorTitle = ResolveTitleText(errorTitle);
            _errorText = ResolveTitleText(errorText);
            _formula1 = NPOI.SS.Formula.Formula.Create(formula1);
            _formula2 = NPOI.SS.Formula.Formula.Create(formula2);
            _regions = regions;
        }
        public Object Clone()
        {
            UnicodeString str = new UnicodeString();
            str.field_1_charCount = field_1_charCount;
            str.field_2_optionflags = field_2_optionflags;
            str.field_3_string = field_3_string;
            if (field_4_format_runs != null)
            {
                str.field_4_format_runs = new ArrayList();
                int size = field_4_format_runs.Count;
                for (int i = 0; i < size; i++)
                {
                    FormatRun r = (FormatRun)field_4_format_runs[i];
                    str.field_4_format_runs.Add(new FormatRun(r.Char, r.FontIndex));
                }
            }
            if (field_5_ext_rst != null)
            {
                str.field_5_ext_rst = new byte[field_5_ext_rst.Length];
                Array.Copy(field_5_ext_rst, 0, str.field_5_ext_rst, 0,
                                 field_5_ext_rst.Length);
            }

            return str;
        }
Exemple #9
0
 private static void SerializeUnicodeString(UnicodeString us, ILittleEndianOutput out1)
 {
     StringUtil.WriteUnicodeString(out1, us.String);
 }
Exemple #10
0
 private static int GetUnicodeStringSize(UnicodeString us)
 {
     String str = us.String;
     return 3 + str.Length * (StringUtil.HasMultibyte(str) ? 2 : 1);
 }
Exemple #11
0
        private static int GetSheetIndex(UnicodeString[] sheetNames, String sheetName)
        {
            for (int i = 0; i < sheetNames.Length; i++)
            {
                if (sheetNames[i].String.Equals(sheetName))
                {
                    return i;
                }

            }
            throw new InvalidOperationException("External workbook does not contain sheet '" + sheetName + "'");
        }
Exemple #12
0
 private static String ResolveTitleString(UnicodeString us)
 {
     if (us == null || us.Equals(NULL_TEXT_STRING))
     {
         return null;
     }
     return us.String;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="HSSFRichTextString"/> class.
        /// </summary>
        /// <param name="book">The workbook.</param>
        /// <param name="record">The record.</param>
        public HSSFRichTextString(InternalWorkbook book, LabelSSTRecord record)
        {
            SetWorkbookReferences(book, record);

            this.str = book.GetSSTString(record.SSTIndex);
        }
Exemple #14
0
        public void TestHugeStrings()
        {
            SSTRecord record = new SSTRecord();
            byte[][] bstrings =
                {
                    new byte[9000], new byte[7433], new byte[9002],
                    new byte[16998]
                };
            UnicodeString[] strings = new UnicodeString[bstrings.Length];
            int total_length = 0;

            for (int k = 0; k < bstrings.Length; k++)
            {
                Arrays.Fill(bstrings[k], (byte)('a' + k));
                strings[k] = new UnicodeString(new String(ConvertByteToChar(bstrings[k])));
                record.AddString(strings[k]);
                total_length += 3 + bstrings[k].Length;
            }

            // add overhead of SST record
            total_length += 8;

            // add overhead of broken strings
            total_length += 4;

            // add overhead of six records
            total_length += (6 * 4);
            byte[] content = new byte[record.RecordSize];

            record.Serialize(0, content);
            Assert.AreEqual(total_length, content.Length);

            //Deserialize the record.
            RecordInputStream recStream = new RecordInputStream(new MemoryStream(content));
            recStream.NextRecord();
            record = new SSTRecord(recStream);

            Assert.AreEqual(strings.Length, record.NumStrings);
            Assert.AreEqual(strings.Length, record.NumUniqueStrings);
            Assert.AreEqual(strings.Length, record.CountStrings);
            for (int k = 0; k < strings.Length; k++)
            {
                Assert.AreEqual(strings[k], record.GetString(k));
            }
            record = new SSTRecord();
            bstrings[1] = new byte[bstrings[1].Length - 1];
            for (int k = 0; k < bstrings.Length; k++)
            {
                if ((bstrings[k].Length % 2) == 1)
                {
                    Arrays.Fill(bstrings[k], (byte)('a' + k));
                    strings[k] = new UnicodeString(new String(ConvertByteToChar(bstrings[k])));
                }
                else
                {
                    char[] data = new char[bstrings[k].Length / 2];

                    Arrays.Fill(data, (char)('\u2122' + k));
                    strings[k] = new UnicodeString(new String(data));
                }
                record.AddString(strings[k]);
            }
            content = new byte[record.RecordSize];
            record.Serialize(0, content);
            total_length--;
            Assert.AreEqual(total_length, content.Length);

            recStream = new RecordInputStream(new MemoryStream(content));
            recStream.NextRecord();
            record = new SSTRecord(recStream);

            Assert.AreEqual(strings.Length, record.NumStrings);
            Assert.AreEqual(strings.Length, record.NumUniqueStrings);
            Assert.AreEqual(strings.Length, record.CountStrings);
            for (int k = 0; k < strings.Length; k++)
            {
                Assert.AreEqual(strings[k], record.GetString(k));
            }
        }
 private static void ConfirmSize(int expectedSize, UnicodeString s)
 {
     ConfirmSize(expectedSize, s, 0);
 }
 /// <summary>
 /// Adds to SST if required.
 /// </summary>
 private void AddToSSTIfRequired()
 {
     if (book != null)
     {
         int index = book.AddSSTString(str);
         record.SSTIndex = (index);
         //The act of Adding the string to the SST record may have meant that
         //a extsing string was returned for the index, so update our local version
         str = book.GetSSTString(index);
     }
 }
 private static UnicodeString MakeUnicodeString(String s)
 {
     UnicodeString st = new UnicodeString(s);
     st.OptionFlags = (/*setter*/(byte)0);
     return st;
 }
Exemple #18
0
 public UnicodeStringTreeNode(UnicodeString record)
 {
     this.Record = record;
     this.Text = record.GetType().Name;
     this.ImageKey = "Binary";
 }
 public static SupBookRecord CreateExternalReferences(UnicodeString url, UnicodeString[] sheetNames)
 {
     return new SupBookRecord(url, sheetNames);
 }
        /// <summary>
        /// Applies a font to the specified Chars of a string.
        /// </summary>
        /// <param name="startIndex">The start index to apply the font to (inclusive).</param>
        /// <param name="endIndex">The end index to apply the font to (exclusive).</param>
        /// <param name="fontIndex">The font to use.</param>
        public void ApplyFont(int startIndex, int endIndex, short fontIndex)
        {
            if (startIndex > endIndex)
                throw new ArgumentException("Start index must be less than end index.");
            if (startIndex < 0 || endIndex > Length)
                throw new ArgumentException("Start and end index not in range.");
            if (startIndex == endIndex)
                return;

            //Need to Check what the font Is currently, so we can reapply it after
            //the range Is completed
            short currentFont = NO_FONT;
            if (endIndex != Length)
            {
                currentFont = this.GetFontAtIndex(startIndex);
            }

            //Need to clear the current formatting between the startIndex and endIndex
            str = CloneStringIfRequired();
            System.Collections.Generic.List<FormatRun> formatting = str.FormatIterator();

            ArrayList deletedFR = new ArrayList();
            if (formatting != null)
            {
                IEnumerator formats = formatting.GetEnumerator();
                while (formats.MoveNext())
                {
                    FormatRun r = (FormatRun)formats.Current;
                    if ((r.CharacterPos >= startIndex) && (r.CharacterPos < endIndex))
                    {
                        deletedFR.Add(r);
                    }
                }
            }
            foreach(FormatRun fr in deletedFR)
            {
                str.RemoveFormatRun(fr);
            }

            str.AddFormatRun(new FormatRun((short)startIndex, fontIndex));
            if (endIndex != Length)
                str.AddFormatRun(new FormatRun((short)endIndex, currentFont));

            AddToSSTIfRequired();
        }
Exemple #21
0
 private static int GetUnicodeStringSize(UnicodeString str)
 {
     return 3 + str.String.Length;
 }
 /// <summary>
 /// Removes any formatting that may have been applied to the string.
 /// </summary>
 public void ClearFormatting()
 {
     str = CloneStringIfRequired();
     str.ClearFormatting();
     AddToSSTIfRequired();
 }
        /**
         * Constructs a Extern Sheet record and Sets its fields appropriately.
         *
         * @param id     id must be 0x16 or an exception will be throw upon validation
         * @param size  the size of the data area of the record
         * @param data  data of the record (should not contain sid/len)
         */
        public SupBookRecord(RecordInputStream in1)
        {
            field_1_number_of_sheets = in1.ReadShort();

            if (in1.CurrentLength > SMALL_RECORD_SIZE)
            {
                // 5.38.1 External References
                _isAddInFunctions = false;

                field_2_encoded_url = in1.ReadUnicodeString();
                UnicodeString[] sheetNames = new UnicodeString[field_1_number_of_sheets];
                for (int i = 0; i < sheetNames.Length; i++)
                {
                    sheetNames[i] = in1.ReadUnicodeString();
                }
                field_3_sheet_names = sheetNames;
                return;
            }
            // else not 'External References'
            field_2_encoded_url = null;
            field_3_sheet_names = null;

            short nextShort = in1.ReadShort();
            if (nextShort == TAG_INTERNAL_REFERENCES)
            {
                // 5.38.2 'Internal References'
                _isAddInFunctions = false;
            }
            else if (nextShort == TAG_Add_IN_FUNCTIONS)
            {
                // 5.38.3 'Add-In Functions'
                _isAddInFunctions = true;
                if (field_1_number_of_sheets != 1)
                {
                    throw new Exception("Expected 0x0001 for number of sheets field in 'Add-In Functions' but got ("
                         + field_1_number_of_sheets + ")");
                }
            }
            else
            {
                throw new Exception("invalid EXTERNALBOOK code ("
                         + StringUtil.ToHexString(nextShort) + ")");
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="HSSFRichTextString"/> class.
 /// </summary>
 /// <param name="str">The string.</param>
 public HSSFRichTextString(String str)
 {
     if (str == null)
         str = "";
     this.str = new UnicodeString(str);
 }
Exemple #25
0
 static public void AddToStringTable(IntMapper<UnicodeString> strings, UnicodeString str)
 {
     strings.Add(str);
 }
        /**
         * Adds a string to the SST table and returns its index (if its a duplicate
         * just returns its index and update the counts) ASSUMES compressed Unicode
         * (meaning 8bit)
         *
         * @param string the string to be Added to the SSTRecord
         *
         * @return index of the string within the SSTRecord
         */

        public int AddSSTString(UnicodeString str)
        {
            //if (log.Check(POILogger.DEBUG))
            //    log.Log(DEBUG, "Insert to sst string='", str);
            if (sst == null)
            {
                InsertSST();
            }
            return sst.AddString(str);
        }
Exemple #27
0
        /**
         * Constructs a DV record and Sets its fields appropriately.
         *
         * @param in the RecordInputstream to Read the record from
         */

        public DVRecord(RecordInputStream in1)
        {
            _option_flags = in1.ReadInt();

            _promptTitle = ReadUnicodeString(in1);
            _errorTitle = ReadUnicodeString(in1);
            _promptText = ReadUnicodeString(in1);
            _errorText = ReadUnicodeString(in1);

            int field_size_first_formula = in1.ReadUShort();
            _not_used_1 = in1.ReadShort();

            //read first formula data condition
            _formula1 = NPOI.SS.Formula.Formula.Read(field_size_first_formula, in1);

            int field_size_sec_formula = in1.ReadUShort();
            _not_used_2 = in1.ReadShort();

            //read sec formula data condition
            _formula2 = NPOI.SS.Formula.Formula.Read(field_size_sec_formula, in1);

            //read cell range address list with all affected ranges
            _regions = new CellRangeAddressList(in1);
        }
Exemple #28
0
        public void TestSimpleAddString()
        {
            SSTRecord record = new SSTRecord();
            UnicodeString s1 = new UnicodeString("Hello world");

            // \u2122 is the encoding of the trademark symbol ...
            UnicodeString s2 = new UnicodeString("Hello world\u2122");

            Assert.AreEqual(0, record.AddString(s1));
            Assert.AreEqual(s1, record.GetString(0));
            Assert.AreEqual(1, record.CountStrings);
            Assert.AreEqual(1, record.NumStrings);
            Assert.AreEqual(1, record.NumUniqueStrings);
            Assert.AreEqual(0, record.AddString(s1));
            Assert.AreEqual(s1, record.GetString(0));
            Assert.AreEqual(1, record.CountStrings);
            Assert.AreEqual(2, record.NumStrings);
            Assert.AreEqual(1, record.NumUniqueStrings);
            Assert.AreEqual(1, record.AddString(s2));
            Assert.AreEqual(s2, record.GetString(1));
            Assert.AreEqual(2, record.CountStrings);
            Assert.AreEqual(3, record.NumStrings);
            Assert.AreEqual(2, record.NumUniqueStrings);
            IEnumerator iter = record.GetStrings();

            while (iter.MoveNext())
            {
                UnicodeString ucs = (UnicodeString)iter.Current;

                if (ucs.Equals(s1))
                {
                    Assert.AreEqual((byte)0, ucs.OptionFlags);
                }
                else if (ucs.Equals(s2))
                {
                    Assert.AreEqual((byte)1, ucs.OptionFlags);
                }
                else
                {
                    Assert.Fail("cannot match string: " + ucs.String);
                }
            }
        }
Exemple #29
0
 private static int SerializeUnicodeString(UnicodeString us, int offset, byte[] data)
 {
     UnicodeRecordStats urs = new UnicodeRecordStats();
     us.Serialize(urs, offset, data);
     return urs.recordSize;
 }