Exemple #1
0
        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();
            }
        }
Exemple #2
0
        internal static TreeNode[] GetChildren(DirectoryNode node, object innerDoc)
        {
            var children = new List <AbstractTreeNode>();

            var entries = node.Entries;

            while (entries.MoveNext())
            {
                EntryNode        entry = entries.Current as EntryNode;
                AbstractTreeNode treeNode;
                if (entry is DirectoryNode)
                {
                    treeNode = new DirectoryTreeNode(entry as DirectoryNode);

                    var o = entry as DirectoryNode;
                }
                else
                {
                    var o = entry as DocumentNode;

                    treeNode = new DocumentTreeNode(entry as DocumentNode);

                    #region handle Excel BIFF records

                    if (treeNode.Text.ToLower() == "workbook")
                    {
                        HandleWorkbook(treeNode, (HSSFWorkbook)innerDoc);
                    }
                    //else if(treeNode.Text.ToLower() == "worddocument")
                    //{
                    //    HandleWord(treeNode, (HWPFDocument)innerDoc);
                    //}

                    #endregion
                }

                children.Add(treeNode);
            }

            children.Sort();

            return(children.ToArray());
        }