コード例 #1
0
ファイル: LinkTable.cs プロジェクト: Reinakumiko/npoi
        /**
     * Register an external name in this workbook
     *
     * @param name  the name to register
     * @return a NameXPtg describing this name 
     */
        public NameXPtg AddNameXPtg(String name)
        {
            int extBlockIndex = -1;
            ExternalBookBlock extBlock = null;

            // find ExternalBlock for Add-In functions and remember its index
            for (int i = 0; i < _externalBookBlocks.Length; i++)
            {
                SupBookRecord ebr = _externalBookBlocks[i].GetExternalBookRecord();
                if (ebr.IsAddInFunctions)
                {
                    extBlock = _externalBookBlocks[i];
                    extBlockIndex = i;
                    break;
                }
            }
            // An ExternalBlock for Add-In functions was not found. Create a new one.
            if (extBlock == null)
            {
                extBlock = new ExternalBookBlock();

                extBlockIndex = ExtendExternalBookBlocks(extBlock);

                // add the created SupBookRecord before ExternSheetRecord
                int idx = FindFirstRecordLocBySid(ExternSheetRecord.sid);
                _workbookRecordList.Add(idx, extBlock.GetExternalBookRecord());

                // register the SupBookRecord in the ExternSheetRecord
                // -2 means that the scope of this name is Workbook and the reference applies to the entire workbook.
                _externSheetRecord.AddRef(_externalBookBlocks.Length - 1, -2, -2);
            }

            // create a ExternalNameRecord that will describe this name
            ExternalNameRecord extNameRecord = new ExternalNameRecord();
            extNameRecord.Text = (name);
            // The docs don't explain why Excel set the formula to #REF!
            extNameRecord.SetParsedExpression(new Ptg[] { ErrPtg.REF_INVALID });

            int nameIndex = extBlock.AddExternalName(extNameRecord);
            int supLinkIndex = 0;
            // find the posistion of the Add-In SupBookRecord in the workbook stream,
            // the created ExternalNameRecord will be appended to it
            for (IEnumerator iterator = _workbookRecordList.GetEnumerator(); iterator.MoveNext(); supLinkIndex++)
            {
                Record record = (Record)iterator.Current;
                if (record is SupBookRecord)
                {
                    if (((SupBookRecord)record).IsAddInFunctions) break;
                }
            }
            int numberOfNames = extBlock.NumberOfNames;
            // a new name is inserted in the end of the SupBookRecord, after the last name
            _workbookRecordList.Add(supLinkIndex + numberOfNames, extNameRecord);
            int fakeSheetIdx = -2; /* the scope is workbook*/
            int ix = _externSheetRecord.GetRefIxForSheet(extBlockIndex, fakeSheetIdx, fakeSheetIdx);
            return new NameXPtg(ix, nameIndex);
        }
コード例 #2
0
        public void TestUnicodeName_bug47384()
        {
            // data taken from bugzilla 47384 att 23830 at offset 0x13A0
            byte[] dataUN = NPOI.Util.HexRead.ReadFromString(
                    "23 00 22 00" +
                    "00 00 00 00 00 00 " +
                    "0C 01 " +
                    "59 01 61 00 7A 00 65 00 6E 00 ED 00 5F 00 42 00 69 00 6C 00 6C 00 61 00" +
                    "00 00");

            RecordInputStream in1 = TestcaseRecordInputStream.Create(dataUN);
            ExternalNameRecord enr;
            try
            {
                enr = new ExternalNameRecord(in1);
            }
            catch (RecordFormatException e)
            {
                if (e.Message.StartsWith("Expected to find a ContinueRecord in order to read remaining 242 of 268 chars"))
                {
                    throw new AssertionException("Identified bug 47384 - failed to read ENR with unicode name");
                }
                throw e;
            }
            Assert.AreEqual("\u0159azen\u00ED_Billa", enr.Text);
        }
コード例 #3
0
ファイル: LinkTable.cs プロジェクト: Reinakumiko/npoi
 public int AddExternalName(ExternalNameRecord rec)
 {
     ExternalNameRecord[] tmp = new ExternalNameRecord[_externalNameRecords.Length + 1];
     Array.Copy(_externalNameRecords, 0, tmp, 0, _externalNameRecords.Length);
     tmp[tmp.Length - 1] = rec;
     _externalNameRecords = tmp;
     return _externalNameRecords.Length - 1;
 }