コード例 #1
0
ファイル: TestHSSFEventFactory.cs プロジェクト: xoposhiy/npoi
        public void TestWithCrazyContinueRecords()
        {
            // Some files have crazy ordering of their continue records
            // Check that we don't break on them (bug #42844)

            HSSFRequest req = new HSSFRequest();
            MockHSSFListener mockListen = new MockHSSFListener();
            req.AddListenerForAllRecords(mockListen);

            POIFSFileSystem fs = new POIFSFileSystem(OpenSample("ContinueRecordProblem.xls"));
            HSSFEventFactory factory = new HSSFEventFactory();
            factory.ProcessWorkbookEvents(req, fs);

            Record[] recs = mockListen.GetRecords();
            // Check we got the records
            Assert.IsTrue(recs.Length > 100);

            // And none of them are continue ones
            for (int i = 0; i < recs.Length; i++)
            {
                Assert.IsFalse(recs[i] is ContinueRecord);
            }

            // Check that the last few records are as we expect
            // (Makes sure we don't accidently skip the end ones)
            int numRec = recs.Length;
            Assert.AreEqual(typeof(DVALRecord), recs[numRec - 3].GetType());
            Assert.AreEqual(typeof(DVRecord), recs[numRec - 2].GetType());
            Assert.AreEqual(typeof(EOFRecord), recs[numRec - 1].GetType());
        }
コード例 #2
0
        public void TestOpenBOOK()
        {
            Stream is1 = HSSFTestDataSamples.OpenSampleFileStream(xlsB);

            POIFSFileSystem fs = new POIFSFileSystem(is1);

            // Ensure that we have a BOOK entry
            fs.Root.GetEntry("BOOK");
            Assert.IsTrue(true);

            // But not a Workbook one
            try
            {
                fs.Root.GetEntry("Workbook");
                Assert.Fail();
            }
            catch (FileNotFoundException) { }
            // And not a Summary one
            try
            {
                fs.Root.GetEntry("\005SummaryInformation");
                Assert.Fail();
            }
            catch (FileNotFoundException) { }

            // Try to open the workbook
            HSSFWorkbook wb = new HSSFWorkbook(fs);
        }
コード例 #3
0
ファイル: HWPFDocFixture.cs プロジェクト: ctddjyds/npoi
        public void SetUp()
        {
            POIFSFileSystem filesystem = new POIFSFileSystem(
                    POIDataSamples.GetDocumentInstance().OpenResourceAsStream("test.doc"));

            DocumentEntry documentProps =
              (DocumentEntry)filesystem.Root.GetEntry("WordDocument");
            _mainStream = new byte[documentProps.Size];
            filesystem.CreateDocumentInputStream("WordDocument").Read(_mainStream);

            // use the fib to determine the name of the table stream.
            _fib = new FileInformationBlock(_mainStream);

            String name = "0Table";
            if (_fib.IsFWhichTblStm())
            {
                name = "1Table";
            }

            // read in the table stream.
            DocumentEntry tableProps =
              (DocumentEntry)filesystem.Root.GetEntry(name);
            _tableStream = new byte[tableProps.Size];
            filesystem.CreateDocumentInputStream(name).Read(_tableStream);

            _fib.FillVariableFields(_mainStream, _tableStream);
        }
コード例 #4
0
        public void TestRecord()
        {
            POIFSFileSystem fs = new POIFSFileSystem(
                    HSSFTestDataSamples.OpenSampleFileStream("WithFormattedGraphTitle.xls"));

            // Check we can Open the file via usermodel
            HSSFWorkbook hssf = new HSSFWorkbook(fs);

            // Now process it through eventusermodel, and
            //  look out for the title records
            ChartTitleFormatRecordGrabber grabber = new ChartTitleFormatRecordGrabber();
            Stream din = fs.CreateDocumentInputStream("Workbook");
            HSSFRequest req = new HSSFRequest();
            req.AddListenerForAllRecords(grabber);
            HSSFEventFactory factory = new HSSFEventFactory();
            factory.ProcessEvents(req, din);
            din.Close();

            // Should've found one
            Assert.AreEqual(1, grabber.chartTitleFormatRecords.Count);
            // And it should be of something interesting
            AlRunsRecord r =
                (AlRunsRecord)grabber.chartTitleFormatRecords[0];
            Assert.AreEqual(3, r.GetFormatCount());
        }
コード例 #5
0
        public void TestFail()  
        {
            Stream is1 = HSSFTestDataSamples.OpenSampleFileStream("Simple.xls");
            POIFSFileSystem fs = new POIFSFileSystem(is1);

            HSSFWorkbook wb = new HSSFWorkbook(fs);

            //set POIFS properties after constructing HSSFWorkbook
            //(a piece of code that used to work up to POI 3.0.2)
            SummaryInformation summary1 = (SummaryInformation)PropertySetFactory.Create(fs.CreateDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
            summary1.Title=(title);
            //Write the modified property back to POIFS
            fs.Root.GetEntry(SummaryInformation.DEFAULT_STREAM_NAME).Delete();
            fs.CreateDocument(summary1.ToStream(), SummaryInformation.DEFAULT_STREAM_NAME);

            //save the workbook and read the property
            MemoryStream out1 = new MemoryStream();
            wb.Write(out1);
            out1.Close();

            POIFSFileSystem fs2 = new POIFSFileSystem(new MemoryStream(out1.ToArray()));
            SummaryInformation summary2 = (SummaryInformation)PropertySetFactory.Create(fs2.CreateDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));

            //Assert.Failing assertion
            Assert.AreEqual(title, summary2.Title);
        }
コード例 #6
0
        public void Test4KBlocks()
        {
            Stream inp = _samples.OpenResourceAsStream("BlockSize4096.zvi");

            // First up, check that we can process the header properly
            HeaderBlock header_block = new HeaderBlock(inp);
            POIFSBigBlockSize bigBlockSize = header_block.BigBlockSize;
            Assert.AreEqual(4096, bigBlockSize.GetBigBlockSize());

            // Check the fat info looks sane
            Assert.AreEqual(1, header_block.BATArray.Length);
            Assert.AreEqual(1, header_block.BATCount);
            Assert.AreEqual(0, header_block.XBATCount);

            // Now check we can get the basic fat
            RawDataBlockList data_blocks = new RawDataBlockList(inp, bigBlockSize);

            // Now try and open properly
            POIFSFileSystem fs = new POIFSFileSystem(
                  _samples.OpenResourceAsStream("BlockSize4096.zvi")
            );
            Assert.IsTrue(fs.Root.EntryCount > 3);

            // Check we can get at all the contents
            CheckAllDirectoryContents(fs.Root);

            // Finally, check we can do a similar 512byte one too
            fs = new POIFSFileSystem(
                 _samples.OpenResourceAsStream("BlockSize512.zvi")
               );
            Assert.IsTrue(fs.Root.EntryCount > 3);
            CheckAllDirectoryContents(fs.Root);
        }
コード例 #7
0
        public void TestWrite()
        {
            Stream is1 = HSSFTestDataSamples.OpenSampleFileStream(xlsA);
            POIFSFileSystem fs = new POIFSFileSystem(is1);

            // Open the workbook, not preserving nodes
            HSSFWorkbook wb = new HSSFWorkbook(fs);
            MemoryStream out1 = new MemoryStream();
            wb.Write(out1);

            // Check now
            MemoryStream in1 = new MemoryStream(out1.ToArray());
            POIFSFileSystem fs2 = new POIFSFileSystem(in1);

            // Check that we have the new entries
            fs2.Root.GetEntry("Workbook");
            try
            {
                fs2.Root.GetEntry("WORKBOOK");
                Assert.Fail();
            }
            catch (FileNotFoundException) { }

            // And it can be Opened
            HSSFWorkbook wb2 = new HSSFWorkbook(fs2);
        }
コード例 #8
0
ファイル: POIFSLister.cs プロジェクト: babywzazy/Server
 public static void ViewFile(String filename)
 {
     POIFSFileSystem fs = new POIFSFileSystem(
             new FileStream(filename, FileMode.Open)
     );
     DisplayDirectory(fs.Root, "");
 }
コード例 #9
0
ファイル: Program.cs プロジェクト: 89sos98/npoi
        static void Main(string[] args)
        {
            POIFSFileSystem fs = new POIFSFileSystem();

            //get the root directory
            DirectoryEntry dir = fs.Root;

            //create a entry of DocumentSummaryInformation
            DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
            dsi.Company = "NPOI Team";
            CustomProperties customProperties = dsi.CustomProperties;
            if (customProperties == null)
                customProperties = new CustomProperties();
            customProperties.Put("测试", "value A");
            customProperties.Put("BB", "value BB");
            customProperties.Put("CCC", "value CCC");
            dsi.CustomProperties = customProperties;
            //Write the stream data of the DocumentSummaryInformation entry to the root directory
            dsi.Write(dir, DocumentSummaryInformation.DEFAULT_STREAM_NAME);


            //create a POIFS file called Foo.poifs
            FileStream output = new FileStream("Foo.xls", FileMode.OpenOrCreate);
            fs.WriteFileSystem(output);
            output.Close();
        }
コード例 #10
0
ファイル: TestOle10Native.cs プロジェクト: hijson/npoi
        public void TestOleNative()
        {
            POIFSFileSystem fs = new POIFSFileSystem(dataSamples.OpenResourceAsStream("oleObject1.bin"));

            Ole10Native ole = Ole10Native.CreateFromEmbeddedOleObject(fs);

            Assert.AreEqual("File1.svg", ole.Label);
            Assert.AreEqual("D:\\Documents and Settings\\rsc\\My Documents\\file1.svg", ole.Command);
        }
コード例 #11
0
ファイル: TestEntryUtils.cs プロジェクト: 89sos98/npoi
        public void TestCopyRecursively()
        {
            POIFSFileSystem fsD = new POIFSFileSystem();
            POIFSFileSystem fs = new POIFSFileSystem();
            DirectoryEntry dirA = fs.CreateDirectory("DirA");
            DirectoryEntry dirB = fs.CreateDirectory("DirB");

            DocumentEntry entryR = fs.CreateDocument(new ByteArrayInputStream(dataSmallA), "EntryRoot");
            DocumentEntry entryA1 = dirA.CreateDocument("EntryA1", new ByteArrayInputStream(dataSmallA));
            DocumentEntry entryA2 = dirA.CreateDocument("EntryA2", new ByteArrayInputStream(dataSmallB));

            // Copy docs
            Assert.AreEqual(0, fsD.Root.EntryCount);
            EntryUtils.CopyNodeRecursively(entryR, fsD.Root);

            Assert.AreEqual(1, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("EntryRoot"));

            EntryUtils.CopyNodeRecursively(entryA1, fsD.Root);
            Assert.AreEqual(2, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("EntryRoot"));
            Assert.IsNotNull(fsD.Root.GetEntry("EntryA1"));

            EntryUtils.CopyNodeRecursively(entryA2, fsD.Root);
            Assert.AreEqual(3, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("EntryRoot"));
            Assert.IsNotNull(fsD.Root.GetEntry("EntryA1"));
            Assert.IsNotNull(fsD.Root.GetEntry("EntryA2"));

            // Copy directories
            fsD = new POIFSFileSystem();
            Assert.AreEqual(0, fsD.Root.EntryCount);

            EntryUtils.CopyNodeRecursively(dirB, fsD.Root);
            Assert.AreEqual(1, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("DirB"));
            Assert.AreEqual(0, ((DirectoryEntry)fsD.Root.GetEntry("DirB")).EntryCount);

            EntryUtils.CopyNodeRecursively(dirA, fsD.Root);
            Assert.AreEqual(2, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("DirB"));
            Assert.AreEqual(0, ((DirectoryEntry)fsD.Root.GetEntry("DirB")).EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("DirA"));
            Assert.AreEqual(2, ((DirectoryEntry)fsD.Root.GetEntry("DirA")).EntryCount);

            // Copy the whole lot
            fsD = new POIFSFileSystem();
            Assert.AreEqual(0, fsD.Root.EntryCount);

            EntryUtils.CopyNodes(fs, fsD, new List<String>());
            Assert.AreEqual(3, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry(dirA.Name));
            Assert.IsNotNull(fsD.Root.GetEntry(dirB.Name));
            Assert.IsNotNull(fsD.Root.GetEntry(entryR.Name));
            Assert.AreEqual(0, ((DirectoryEntry)fsD.Root.GetEntry("DirB")).EntryCount);
            Assert.AreEqual(2, ((DirectoryEntry)fsD.Root.GetEntry("DirA")).EntryCount);
        }
コード例 #12
0
 protected void setUp()
 {
     fs = new POIFSFileSystem();
     dirA = fs.CreateDirectory("DirA");
     dirB = fs.CreateDirectory("DirB");
     dirAA = dirA.CreateDirectory("DirAA");
     eRoot = fs.Root.CreateDocument("Root", new ByteArrayInputStream(new byte[] { }));
     eA = dirA.CreateDocument("NA", new ByteArrayInputStream(new byte[] { }));
     eAA = dirAA.CreateDocument("NAA", new ByteArrayInputStream(new byte[] { }));
 }
コード例 #13
0
ファイル: TestDecryptor.cs プロジェクト: myblindy/npoi
        public void TestPasswordVerification()
        {
            POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.GetPOIFSInstance().OpenResourceAsStream("protect.xlsx"));

            EncryptionInfo info = new EncryptionInfo(fs);

            Decryptor d = Decryptor.GetInstance(info);

            Assert.IsTrue(d.VerifyPassword(Decryptor.DEFAULT_PASSWORD));
        }
コード例 #14
0
ファイル: TestDecryptor.cs プロジェクト: myblindy/npoi
        public void TestDecrypt()
        {
            POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.GetPOIFSInstance().OpenResourceAsStream("protect.xlsx"));

            EncryptionInfo info = new EncryptionInfo(fs);

            Decryptor d = Decryptor.GetInstance(info);

            d.VerifyPassword(Decryptor.DEFAULT_PASSWORD);

            ZipOk(fs, d);
        }
コード例 #15
0
ファイル: TestDirectoryNode.cs プロジェクト: 89sos98/npoi
        public void TestEmptyConstructor()
        {
            POIFSFileSystem fs = new POIFSFileSystem();
            DirectoryProperty property1 = new DirectoryProperty("parent");
            DirectoryProperty property2 = new DirectoryProperty("child");
            DirectoryNode parent = new DirectoryNode(property1, fs, null);
            DirectoryNode node = new DirectoryNode(property2, fs, parent);

            Assert.AreEqual(0, parent.Path.Length);
            Assert.AreEqual(1, node.Path.Length);
            Assert.AreEqual("child", node.Path.GetComponent(0));

            // Verify that GetEntries behaves correctly
            int count = 0;
            IEnumerator iter = node.Entries;

            while (iter.MoveNext())
            {
                count++;
            }
            Assert.AreEqual(0, count);

            // Verify behavior of IsEmpty
            Assert.IsTrue(node.IsEmpty);

            // Verify behavior of EntryCount
            Assert.AreEqual(0, node.EntryCount);

            // Verify behavior of Entry
            try
            {
                node.GetEntry("foo");
                Assert.Fail("Should have caught FileNotFoundException");
            }
            catch (FileNotFoundException )
            {

                // as expected
            }

            // Verify behavior of isDirectoryEntry
            Assert.IsTrue(node.IsDirectoryEntry);

            // Verify behavior of GetName
            Assert.AreEqual(property2.Name, node.Name);

            // Verify behavior of isDocumentEntry
            Assert.IsTrue(!node.IsDocumentEntry);

            // Verify behavior of GetParent
            Assert.AreEqual(parent, node.Parent);
        }
コード例 #16
0
ファイル: TestDecryptor.cs プロジェクト: myblindy/npoi
        public void TestAgile()
        {
            POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.GetPOIFSInstance().OpenResourceAsStream("protected_agile.docx"));

            EncryptionInfo info = new EncryptionInfo(fs);

            Assert.IsTrue(info.VersionMajor == 4 && info.VersionMinor == 4);

            Decryptor d = Decryptor.GetInstance(info);

            Assert.IsTrue(d.VerifyPassword(Decryptor.DEFAULT_PASSWORD));

            ZipOk(fs, d);
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: JnS-Software-LLC/npoi
        static void Main(string[] args)
        {
            FileStream stream = new FileStream("thumbs.db", FileMode.Open, FileAccess.Read);
            POIFSFileSystem poifs = new POIFSFileSystem(stream);
            var entries = poifs.Root.Entries;
            //POIFSDocumentReader catalogdr = poifs.CreatePOIFSDocumentReader("Catalog");
            //byte[] b1=new byte[catalogdr.Length-4];
            //catalogdr.Read(b1,4,b1.Length);
            //Dictionary<string, string> indexList = new Dictionary<string, string>();
            //for (int j = 0; j < b1.Length; j++)
            //{ 
            //    if(b1[0]
            //}

            while (entries.MoveNext())
            {
                DocumentNode entry = entries.Current as DocumentNode;
                DocumentInputStream dr = poifs.CreateDocumentInputStream(entry.Name);

                if (entry.Name.ToLower() == "catalog")
                    continue;

                byte[] buffer = new byte[dr.Length];
                dr.Read(buffer);
                int startpos = 0;

                //detect jfif header
                for (int i = 3; i < buffer.Length; i++)
                {
                    if (buffer[i - 3] == 0xFF
                        && buffer[i - 2] == 0xD8
                        && buffer[i - 1] == 0xFF
                        && buffer[i] == 0xE0)
                    {
                        startpos = i - 3;
                        break;
                    }
                }
                if (startpos == 0)
                    continue;

                FileStream jpeg = File.Create(entry.Name + ".jpeg");
                jpeg.Write(buffer, startpos, buffer.Length - startpos);
                jpeg.Close();
            }

            stream.Close();
        }
コード例 #18
0
        /**
         * Write out, with any properties changes, but nothing else
         */
        public override void Write(Stream out1)
        {
            POIFSFileSystem fs = new POIFSFileSystem();

            // For tracking what we've written out, so far
            List<String> excepts = new List<String>(1);

            // Write out our HPFS properties, with any changes
            WriteProperties(fs, excepts);
        
            // Copy over everything else unchanged
            EntryUtils.CopyNodes(directory, fs.Root, excepts);
        
            // Save the resultant POIFSFileSystem to the output stream
            fs.WriteFileSystem(out1);
        }
コード例 #19
0
ファイル: MainForm.cs プロジェクト: xoposhiy/npoi
        private void OpenDocument(string path)
        {
            HSSFWorkbook hssfworkbook = null;
            //HWPFDocument hwpf = null;

            using (var stream = File.OpenRead(path))
            {
                try
                {
                    _currentFileSystem = new POIFSFileSystem(stream);
                    //supposing every Excel file has .xls as the extension 
                    if (path.ToLower().IndexOf(".xls")>0)
                    {
                        hssfworkbook = new HSSFWorkbook(_currentFileSystem);
                    }
                    //else if (path.ToLower().IndexOf(".doc") > 0)
                    //{
                    //    hwpf =new HWPFDocument(_currentFileSystem);
                    //}
                }
                catch (Exception)
                {
                    MessageBox.Show("Error opening file. Possibly the file is not an OLE2 Compund file.",
                        "Open File Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            if (_currentFileSystem != null)
            {
                this.Text = string.Format("POIFS Browser - {0}", path);
                documentTreeView.BeginUpdate();
                documentTreeView.Nodes.Clear();

                TreeNode[] children=null;
                if (hssfworkbook != null)
                {
                    children = DirectoryTreeNode.GetChildren(_currentFileSystem.Root, hssfworkbook);
                }
                else
                {
                    children = DirectoryTreeNode.GetChildren(_currentFileSystem.Root, null);
                }
                documentTreeView.Nodes.AddRange(children);
                documentTreeView.EndUpdate();

            }
        }
コード例 #20
0
ファイル: Program.cs プロジェクト: hanwangkun/npoi
        static void Main(string[] args)
        {
            POIFSFileSystem fs = new POIFSFileSystem();

            //get the root directory
            DirectoryEntry dir = fs.Root;
            //create a document entry
            dir.CreateDocument("Foo", new MemoryStream(new byte[] {0x01,0x02,0x03 }));

            //create a folder
            dir.CreateDirectory("Hello");

            //create a POIFS file called Foo.poifs
            FileStream output = new FileStream("Foo.poifs", FileMode.OpenOrCreate);
            fs.WriteFileSystem(output);
            output.Close();
        }
コード例 #21
0
ファイル: TestDecryptor.cs プロジェクト: myblindy/npoi
        private void ZipOk(POIFSFileSystem fs, Decryptor d)
        {
            ZipInputStream zin = new ZipInputStream(d.GetDataStream(fs));
            while (true)
            {
                ZipEntry entry = zin.GetNextEntry();
                if (entry == null)
                {
                    break;
                }

                while (zin.Available > 0)
                {
                    zin.Skip(zin.Available);
                }
            }
        }
コード例 #22
0
        public void TestEncryptionInfo1()
        {
            POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.GetPOIFSInstance().OpenResourceAsStream("protect.xlsx"));

            EncryptionInfo info = new EncryptionInfo(fs);

            Assert.AreEqual(3, info.VersionMajor);
            Assert.AreEqual(2, info.VersionMinor);

            Assert.AreEqual(EncryptionHeader.ALGORITHM_AES_128, info.Header.Algorithm);
            Assert.AreEqual(EncryptionHeader.HASH_SHA1, info.Header.HashAlgorithm);
            Assert.AreEqual(128, info.Header.KeySize);
            Assert.AreEqual(EncryptionHeader.PROVIDER_AES, info.Header.ProviderType);
            Assert.AreEqual("Microsoft Enhanced RSA and AES Cryptographic Provider", info.Header.CspName);

            Assert.AreEqual(32, info.Verifier.VerifierHash.Length);
        }
コード例 #23
0
        private void ProcessFile(String filename)
        {
            HSSFRequest req = new HSSFRequest();
            mockListen = new MockHSSFListener();
            listener = new FormatTrackingHSSFListener(mockListen);
            req.AddListenerForAllRecords(listener);

            HSSFEventFactory factory = new HSSFEventFactory();
            try
            {
                Stream is1 = HSSFTestDataSamples.OpenSampleFileStream(filename);
                POIFSFileSystem fs = new POIFSFileSystem(is1);
                factory.ProcessWorkbookEvents(req, fs);
            }
            catch (IOException)
            {
                throw;
            }
        }
コード例 #24
0
        public void SetUp()
        {
            HSSFRequest req = new HSSFRequest();
            mockListen = new MockHSSFListener();
            listener = new EventWorkbookBuilder.SheetRecordCollectingListener(mockListen);
            req.AddListenerForAllRecords(listener);

            HSSFEventFactory factory = new HSSFEventFactory();
            try
            {
                Stream is1 = HSSFTestDataSamples.OpenSampleFileStream("3dFormulas.xls");
                POIFSFileSystem fs = new POIFSFileSystem(is1);
                factory.ProcessWorkbookEvents(req, fs);
            }
            catch (IOException)
            {
                throw;
            }
        }
コード例 #25
0
ファイル: Program.cs プロジェクト: 89sos98/npoi
        static void Main(string[] args)
        {
            // POI apparently can't create a document from scratch,
            // so we need an existing empty dummy document
            POIFSFileSystem fs = new POIFSFileSystem(File.OpenRead("empty.doc"));
            HWPFDocument doc = new HWPFDocument(fs);

            // centered paragraph with large font size
            Range range = doc.GetRange();
            CharacterRun run1 = range.InsertAfter("one");
            //par1.SetSpacingAfter(200);
            //par1.SetJustification((byte)1);
            // justification: 0=left, 1=center, 2=right, 3=left and right

            //CharacterRun run1 = par1.InsertAfter("one");
            run1.SetFontSize(2 * 18);
            // font size: twice the point size

            // paragraph with bold typeface
            Paragraph par2 = run1.InsertAfter(new ParagraphProperties(), 0);
            par2.SetSpacingAfter(200);
            CharacterRun run2 = par2.InsertAfter("two two two two two two two two two two two two two");
            run2.SetBold(true);

            // paragraph with italic typeface and a line indent in the first line
            Paragraph par3 = run2.InsertAfter(new ParagraphProperties(), 0);
            par3.SetFirstLineIndent(200);
            par3.SetSpacingAfter(200);
            CharacterRun run3 = par3.InsertAfter("three three three three three three three three three "
                + "three three three three three three three three three three three three three three "
                + "three three three three three three three three three three three three three three");
            run3.SetItalic(true);

            // add a custom document property (needs POI 3.5; POI 3.2 doesn't save custom properties)
            DocumentSummaryInformation dsi = doc.DocumentSummaryInformation;
            CustomProperties cp = dsi.CustomProperties;
            if (cp == null)
                cp = new CustomProperties();
            cp.Put("myProperty", "foo bar baz");

            doc.Write(File.OpenWrite("new-hwpf-file.doc"));
        }
コード例 #26
0
ファイル: TestDecryptor.cs プロジェクト: xoposhiy/npoi
        private void ZipOk(POIFSFileSystem fs, Decryptor d)
        {
            ZipInputStream zin = new ZipInputStream(d.GetDataStream(fs));
            while (true)
            {
                int pos = zin.ReadByte();
                if (pos == -1)
                    break;
            //    ZipEntry entry = zin.GetNextEntry();
            //    if (entry == null)
            //    {
            //        break;
            //    }

                //while (zin.available() > 0)
                //{
                //    zin.skip(zin.available());
                //}
            }
        }
コード例 #27
0
        protected DirectoryNode[] openSamples(Stream[] inps, bool oldFails)
        {
            NPOIFSFileSystem nfs = new NPOIFSFileSystem(inps[0]);
            if (openedFSs == null) openedFSs = new List<NPOIFSFileSystem>();
            openedFSs.Add(nfs);

            POIFSFileSystem ofs = null;
            try
            {
                ofs = new POIFSFileSystem(inps[1]);
                if (oldFails) Assert.Fail("POIFSFileSystem should have failed but didn't");
            }
            catch (Exception e)
            {
                if (!oldFails) throw e;
            }

            if (ofs == null) return new DirectoryNode[] { nfs.Root };
            return new DirectoryNode[] { ofs.Root, nfs.Root };
        }
コード例 #28
0
        private void ReadRecords(String sampleFileName)
        {
            HSSFRequest req = new HSSFRequest();
            MockHSSFListener mockListen = new MockHSSFListener();
            MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(mockListen);
            req.AddListenerForAllRecords(listener);

            HSSFEventFactory factory = new HSSFEventFactory();
            try
            {
                Stream is1 = HSSFTestDataSamples.OpenSampleFileStream(sampleFileName);
                POIFSFileSystem fs = new POIFSFileSystem(is1);
                factory.ProcessWorkbookEvents(req, fs);
            }
            catch (IOException)
            {
                throw;
            }

            r = mockListen.GetRecords();
            Assert.IsTrue(r.Length > 100);
        }
コード例 #29
0
ファイル: TestHSSFEventFactory.cs プロジェクト: xoposhiy/npoi
        public void TestWithMissingRecords()
        {

            HSSFRequest req = new HSSFRequest();
            MockHSSFListener mockListen = new MockHSSFListener();
            req.AddListenerForAllRecords(mockListen);

            POIFSFileSystem fs = new POIFSFileSystem(OpenSample("SimpleWithSkip.xls"));
            HSSFEventFactory factory = new HSSFEventFactory();
            factory.ProcessWorkbookEvents(req, fs);

            Record[] recs = mockListen.GetRecords();
            // Check we got the records
            Assert.IsTrue(recs.Length > 100);

            // Check that the last few records are as we expect
            // (Makes sure we don't accidently skip the end ones)
            int numRec = recs.Length;
            Assert.AreEqual(typeof(WindowTwoRecord), recs[numRec - 3].GetType());
            Assert.AreEqual(typeof(SelectionRecord), recs[numRec - 2].GetType());
            Assert.AreEqual(typeof(EOFRecord), recs[numRec - 1].GetType());
        }
コード例 #30
0
        public void TestNormalUnicodeProperties()
        {
            POIFSFileSystem fs = new POIFSFileSystem(_samples.OpenResourceAsStream("TestUnicode.xls"));
            HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
            string text = ext.Text;

            // Check each bit in turn
            String sinfText = ext.SummaryInformationText;
            String dinfText = ext.DocumentSummaryInformationText;

            Assert.IsTrue(sinfText.IndexOf("AUTHOR = marshall") > -1);
            Assert.IsTrue(sinfText.IndexOf("TITLE = Titel: \u00c4h") > -1);
            Assert.IsTrue(dinfText.IndexOf("COMPANY = Schreiner") > -1);
            Assert.IsTrue(dinfText.IndexOf("SCALE = False") > -1);

            // Now overall
            text = ext.Text;
            Assert.IsTrue(text.IndexOf("AUTHOR = marshall") > -1);
            Assert.IsTrue(text.IndexOf("TITLE = Titel: \u00c4h") > -1);
            Assert.IsTrue(text.IndexOf("COMPANY = Schreiner") > -1);
            Assert.IsTrue(text.IndexOf("SCALE = False") > -1);
        }
コード例 #31
0
 /**
  * Copies all nodes from one POIFS to the other
  *
  * @param source
  *            is the source POIFS to copy from
  * @param target
  *            is the target POIFS to copy to
  */
 public static void CopyNodes(POIFSFileSystem source,
                              POIFSFileSystem target)
 {
     CopyNodes(source.Root, target.Root);
 }
コード例 #32
0
ファイル: DirectoryNode.cs プロジェクト: Cy-Team/npoi
 public DirectoryNode(DirectoryProperty property,
                      POIFSFileSystem fileSystem,
                      DirectoryNode parent)
     : this(property, parent, fileSystem, (NPOIFSFileSystem)null)
 {
 }
コード例 #33
0
        public ToxyMetadata Parse()
        {
            if (!System.IO.File.Exists(Context.Path))
            {
                throw new System.IO.FileNotFoundException("File " + Context.Path + " is not found");
            }

            ToxyMetadata metadata = new ToxyMetadata();

            using (Stream stream = File.OpenRead(Context.Path))
            {
                POIFSFileSystem poifs = new NPOI.POIFS.FileSystem.POIFSFileSystem(stream);
                DirectoryNode   root  = poifs.Root;

                SummaryInformation         si  = null;
                DocumentSummaryInformation dsi = null;
                if (root.HasEntry(SummaryInformation.DEFAULT_STREAM_NAME))
                {
                    PropertySet ps = GetPropertySet(root, SummaryInformation.DEFAULT_STREAM_NAME);
                    if (ps is SummaryInformation)
                    {
                        si = ps as SummaryInformation;

                        if (si.Author != null)
                        {
                            metadata.Add("Author", si.Author);
                        }
                        if (si.ApplicationName != null)
                        {
                            metadata.Add("ApplicationName", si.ApplicationName);
                        }
                        if (si.ClassID != null)
                        {
                            metadata.Add("ClassID", si.ClassID.ToString());
                        }
                        if (si.CharCount != 0)
                        {
                            metadata.Add("CharCount", si.CharCount);
                        }
                        if (si.ByteOrder != 0)
                        {
                            metadata.Add("ByteOrder", si.ByteOrder);
                        }
                        if (si.CreateDateTime != null)
                        {
                            metadata.Add("CreateDateTime", si.CreateDateTime);
                        }
                        if (si.LastAuthor != null)
                        {
                            metadata.Add("LastAuthor", si.LastAuthor);
                        }
                        if (si.Keywords != null)
                        {
                            metadata.Add("Keywords", si.Keywords);
                        }
                        if (si.LastPrinted != null)
                        {
                            metadata.Add("LastPrinted", si.LastPrinted);
                        }
                        if (si.LastSaveDateTime != null)
                        {
                            metadata.Add("LastSaveDateTime", si.LastSaveDateTime);
                        }
                        if (si.PageCount != 0)
                        {
                            metadata.Add("PageCount", si.PageCount);
                        }
                        if (si.WordCount != 0)
                        {
                            metadata.Add("WordCount", si.WordCount);
                        }
                        if (si.Comments != null)
                        {
                            metadata.Add("Comments", si.Comments);
                        }
                        if (si.EditTime != 0)
                        {
                            metadata.Add("EditTime", si.EditTime);
                        }
                        if (si.RevNumber != null)
                        {
                            metadata.Add("RevNumber", si.RevNumber);
                        }
                        if (si.Security != 0)
                        {
                            metadata.Add("Security", si.Security);
                        }
                        if (si.Subject != null)
                        {
                            metadata.Add("Subject", si.Subject);
                        }
                        if (si.Title != null)
                        {
                            metadata.Add("Title", si.Title);
                        }
                        if (si.Template != null)
                        {
                            metadata.Add("Template", si.Template);
                        }
                    }
                }

                if (root.HasEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME))
                {
                    PropertySet ps = GetPropertySet(root, DocumentSummaryInformation.DEFAULT_STREAM_NAME);
                    if (ps is DocumentSummaryInformation)
                    {
                        dsi = ps as DocumentSummaryInformation;
                        if (dsi.ByteCount > 0)
                        {
                            metadata.Add("ByteCount", dsi.ByteCount);
                        }
                        else if (dsi.Company != null)
                        {
                            metadata.Add("Company", dsi.Company);
                        }
                        else if (dsi.Format > 0)
                        {
                            metadata.Add("Format", dsi.Format);
                        }
                        else if (dsi.LineCount > 0)
                        {
                            metadata.Add("LineCount", dsi.LineCount);
                        }
                        else if (dsi.LinksDirty)
                        {
                            metadata.Add("LinksDirty", true);
                        }
                        else if (dsi.Manager != null)
                        {
                            metadata.Add("Manager", dsi.Manager);
                        }
                        else if (dsi.NoteCount > 0)
                        {
                            metadata.Add("NoteCount", dsi.NoteCount);
                        }
                        else if (dsi.Scale)
                        {
                            metadata.Add("Scale", dsi.Scale);
                        }
                        else if (dsi.HiddenCount > 0)
                        {
                            metadata.Add("HiddenCount", dsi.Company);
                        }
                        else if (dsi.MMClipCount > 0)
                        {
                            metadata.Add("MMClipCount", dsi.MMClipCount);
                        }
                        else if (dsi.ParCount > 0)
                        {
                            metadata.Add("ParCount", dsi.ParCount);
                        }
                    }
                }
            }
            return(metadata);
        }
コード例 #34
0
 /// <summary>
 /// Creates an instance of this class from an embedded OLE Object. The OLE Object is expected
 /// to include a stream &quot;{01}Ole10Native&quot; which Contains the actual
 /// data relevant for this class.
 /// </summary>
 /// <param name="poifs">poifs POI Filesystem object</param>
 /// <returns>Returns an instance of this class</returns>
 public static Ole10Native CreateFromEmbeddedOleObject(POIFSFileSystem poifs)
 {
     return(CreateFromEmbeddedOleObject(poifs.Root));
 }