TestLinkTable.cs :  » GUI » NPOI » TestCases » HSSF » UserModel » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » NPOI 
NPOI » TestCases » HSSF » UserModel » TestLinkTable.cs
namespace TestCases.HSSF.UserModel{
    using System;
    using NPOI.HSSF.UserModel;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using TestCases.HSSF;
    /**
     * Tests for LinkTable
     *
     * @author Josh Micich
     */
    [TestClass]
    public class TestLinkTable
    {

        /**
         * The example file attached to bugzilla 45046 is a Clear example of Name records being present
         * without an External Book (SupBook) record.  Excel has no trouble reading this file.<br/>
         * TODO get OOO documentation updated to reflect this (that EXTERNALBOOK is optional).
         *
         * It's not Clear what exact steps need to be taken in Excel to Create such a workbook
         */
        [TestMethod]
        public void TestLinkTableWithoutExternalBookRecord_bug45046()
        {
            HSSFWorkbook wb;

            try
            {
                wb = HSSFTestDataSamples.OpenSampleWorkbook("ex45046-21984.xls");
            }
            catch (Exception e)
            {
                if ("DEFINEDNAME is part of LinkTable".Equals(e.Message))
                {
                    throw new AssertFailedException("Identified bug 45046 b");
                }
                throw e;
            }
            // some other sanity Checks
            Assert.AreEqual(3, wb.NumberOfSheets);
            String formula = wb.GetSheetAt(0).GetRow(4).GetCell(13).CellFormula;

            if ("ipcSummenproduktIntern($P5,N$6,$A$9,N$5)".Equals(formula))
            {
                // The reported symptom of this bugzilla is an earlier bug (already fixed)
                throw new AssertFailedException("Identified bug 41726");
                // This is observable in version 3.0
            }

            Assert.AreEqual("ipcSummenproduktIntern($C5,N$2,$A$9,N$1)", formula);
        }
        [TestMethod]
        public void TestMultipleExternSheetRecords_bug45698()
        {
            HSSFWorkbook wb;

            try
            {
                wb = HSSFTestDataSamples.OpenSampleWorkbook("ex45698-22488.xls");
            }
            catch (Exception e)
            {
                if ("Extern sheet is part of LinkTable".Equals(e.Message))
                {
                    throw new AssertFailedException("Identified bug 45698");
                }
                throw e;
            }
            // some other sanity Checks
            Assert.AreEqual(7, wb.NumberOfSheets);
        }
        [TestMethod]
        public void TestExtraSheetRefs_bug45978()
        {
            HSSFWorkbook wb = HSSFTestDataSamples.OpenSampleWorkbook("ex45978-extraLinkTableSheets.xls");
            /*
            ex45978-extraLinkTableSheets.xls is a cut-down version of attachment 22561.
            The original file produces the same error.

            This bug was caused by a combination of invalid sheet indexes in the EXTERNSHEET
            record, and eager initialisation of the extern sheet references. Note - the worbook
            has 2 sheets, but the EXTERNSHEET record refers to sheet indexes 0, 1 and 2.

            Offset 0x3954 (14676)
            recordid = 0x17, size = 32
            [EXTERNSHEET]
               numOfRefs   = 5
            refrec     #0: extBook=0 firstSheet=0 lastSheet=0
            refrec     #1: extBook=1 firstSheet=2 lastSheet=2
            refrec     #2: extBook=2 firstSheet=1 lastSheet=1
            refrec     #3: extBook=0 firstSheet=-1 lastSheet=-1
            refrec     #4: extBook=0 firstSheet=1 lastSheet=1
            [/EXTERNSHEET]

            As it turns out, the formula in question doesn't even use externSheetIndex #1 - it
            uses #4, which resolves to sheetIndex 1 -> 'Data'.

            It is not Clear exactly what externSheetIndex #4 would refer to.  Excel seems to
            display such a formula as "''!$A2", but then complains of broken link errors.
            */

            NPOI.SS.UserModel.Cell cell = wb.GetSheetAt(0).GetRow(1).GetCell(1);
            String cellFormula;
            try
            {
                cellFormula = cell.CellFormula;
            }
            catch (IndexOutOfRangeException e)
            {
                if (e.Message.Equals("Index: 2, Size: 2"))
                {
                    throw new AssertFailedException("Identified bug 45798");
                }
                throw e;
            }
            Assert.AreEqual("Data!$A2", cellFormula);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.