示例#1
0
        /// <summary>
        /// Generate the table
        /// </summary>
        public void GenerateTable()
        {
            // List all the tables
            foreach (var square in new SquareProcess().GetAll())
            {
                foreach (var table in square.Tables)
                {
                    Console.WriteLine("New table");
                    ListTables.Add(table);
                }
            }
            int i = 0;
            int y = 0;

            foreach (var table in ListTables)
            {
                table.TableLocation.posX = 48 + i;
                table.TableLocation.posY = 64 + y;
                i += 64;
                if (i == 384)
                {
                    y = 64;
                    i = 0;
                }
            }
        }
示例#2
0
        public void TestReadWrite()
        {
            FileInformationBlock fib = _hWPFDocFixture._fib;

            byte[] tableStream = _hWPFDocFixture._tableStream;

            int listOffset = fib.GetFcPlcfLst();
            int lfoOffset  = fib.GetFcPlfLfo();

            if (listOffset != 0 && fib.GetLcbPlcfLst() != 0)
            {
                ListTables listTables = new ListTables(tableStream, fib.GetFcPlcfLst(),
                                                       fib.GetFcPlfLfo());
                HWPFFileSystem fileSys = new HWPFFileSystem();

                HWPFStream tableOut = fileSys.GetStream("1Table");

                listTables.WriteListDataTo(tableOut);
                int offset = tableOut.Offset;
                listTables.WriteListOverridesTo(tableOut);

                ListTables newTables = new ListTables(tableOut.ToArray(), 0, offset);

                Assert.AreEqual(listTables, newTables);
            }
        }
示例#3
0
 public int RegisterList(HWPFList list)
 {
     if (_lt == null)
     {
         _lt = new ListTables();
     }
     return(_lt.AddList(list.GetListData(), list.GetOverride()));
 }
示例#4
0
        public static String GetBulletText(ListTables listTables,
                                           Paragraph paragraph, int listId)
        {
            ListLevel listLevel = listTables.GetLevel(listId,
                                                      paragraph.GetIlvl());

            if (listLevel.GetNumberText() == null)
            {
                return(string.Empty);
            }

            StringBuilder bulletBuffer = new StringBuilder();

            char[] xst = listLevel.GetNumberText().ToCharArray();
            foreach (char element in xst)
            {
                if (element < 9)//todo:review_antony
                {
                    ListLevel numLevel = listTables.GetLevel(listId, element);

                    int num = numLevel.GetStartAt();
                    bulletBuffer.Append(NumberFormatter.GetNumber(num,
                                                                  listLevel.GetNumberFormat()));

                    if (numLevel == listLevel)
                    {
                        numLevel.SetStartAt(numLevel.GetStartAt() + 1);
                    }
                }
                else
                {
                    bulletBuffer.Append(element);
                }
            }

            byte follow = listLevel.GetTypeOfCharFollowingTheNumber();

            switch (follow)
            {
            case 0:
                bulletBuffer.Append("\t");
                break;

            case 1:
                bulletBuffer.Append(" ");
                break;

            default:
                break;
            }

            return(bulletBuffer.ToString());
        }
示例#5
0
 internal ListEntry(PAPX papx, Range parent, ListTables tables)
     : base(papx, parent)
 {
     if (tables != null)
     {
         ListFormatOverride override1 = tables.GetOverride(_props.GetIlfo());
         _overrideLevel = override1.GetOverrideLevel(_props.GetIlvl());
         _level         = tables.GetLevel(override1.GetLsid(), _props.GetIlvl());
     }
     else
     {
         //log.log(POILogger.WARN, "No ListTables found for ListEntry - document probably partly corrupt, and you may experience problems");
     }
 }
示例#6
0
文件: Range.cs 项目: zzy092/npoi
        /**
         * Inserts a list into the beginning of this range.
         *
         * @param props
         *            The properties of the list entry. All list entries are
         *            paragraphs.
         * @param listID
         *            The id of the list that Contains the properties.
         * @param level
         *            The indentation level of the list.
         * @param styleIndex
         *            The base style's index in the stylesheet.
         * @return The empty ListEntry that is now part of the document.
         */
        public ListEntry InsertAfter(ParagraphProperties props, int listID, int level, int styleIndex)
        {
            ListTables lt = _doc.GetListTables();

            if (lt.GetLevel(listID, level) == null)
            {
                throw new InvalidDataException("The specified list and level do not exist");
            }
            int ilfo = lt.GetOverrideIndexFromListID(listID);

            props.SetIlfo(ilfo);
            props.SetIlvl((byte)level);

            return((ListEntry)InsertAfter(props, styleIndex));
        }
示例#7
0
 public void Update(DbStructure _structure)
 {
     if (structure.Tables.Count != 0)
     {
         structure = _structure;
         ListTables.UnselectAll();
         ListTables.Items.Clear();
         for (int i = 0; i < structure.Tables.Count; i++)
         {
             ListTables.Items.Add(structure.Tables[i].Name);
         }
         textBoxChangedDB.Text = structure.DataBaseName;
         ListColums.Items.Clear();
     }
 }
示例#8
0
        private void buttonChangedTable_Click(object sender, RoutedEventArgs e)
        {
            int index_table = ListTables.SelectedIndex;

            structure.Tables[index_table].Rename(textBoxChangedTable.Text, structure.Connection);

            ListTables.UnselectAll();
            ListColums.UnselectAll();
            ListTables.Items.Clear();
            ListColums.Items.Clear();
            structure.FillStructure(structure.Connection);
            for (int i = 0; i < structure.Tables.Count; i++)
            {
                ListTables.Items.Add(structure.Tables[i].Name);
            }
            ListTables.SelectedIndex = index_table;
        }
示例#9
0
        /// <summary>
        /// Generate the table
        /// </summary>
        public void GenerateTable()
        {
            // List all the tables
            foreach (var square in new SquareProcess().GetAll())
            {
                foreach (var table in square.Tables)
                {
                    ListTables.Add(table);
                }
            }
            int i = 0;
            int y = 0;

            foreach (var table in ListTables)
            {
                table.TableLocation.posX = 48 + i;
                table.TableLocation.posY = 384 + y;
                i += 48;
                if (i == 336)
                {
                    y = 80;
                }
            }
        }
示例#10
0
        protected void ProcessParagraphes(HWPFDocumentCore wordDocument,
                                          XmlElement flow, Range range, int currentTableLevel)
        {
            ListTables listTables      = wordDocument.GetListTables();
            int        currentListInfo = 0;

            int paragraphs = range.NumParagraphs;

            for (int p = 0; p < paragraphs; p++)
            {
                Paragraph paragraph = range.GetParagraph(p);

                if (paragraph.IsInTable() && paragraph.GetTableLevel() != currentTableLevel)
                {
                    if (paragraph.GetTableLevel() < currentTableLevel)
                    {
                        throw new InvalidOperationException(
                                  "Trying to process table cell with higher level ("
                                  + paragraph.GetTableLevel()
                                  + ") than current table level ("
                                  + currentTableLevel
                                  + ") as inner table part");
                    }

                    Table table = range.GetTable(paragraph);
                    ProcessTable(wordDocument, flow, table);

                    p += table.NumParagraphs;
                    p--;
                    continue;
                }

                if (paragraph.Text.Equals("\u000c"))
                {
                    ProcessPageBreak(wordDocument, flow);
                }

                if (paragraph.GetIlfo() != currentListInfo)
                {
                    currentListInfo = paragraph.GetIlfo();
                }

                if (currentListInfo != 0)
                {
                    if (listTables != null)
                    {
                        ListFormatOverride listFormatOverride = listTables.GetOverride(paragraph.GetIlfo());

                        String label = AbstractWordUtils.GetBulletText(listTables,
                                                                       paragraph, listFormatOverride.GetLsid());

                        ProcessParagraph(wordDocument, flow, currentTableLevel,
                                         paragraph, label);
                    }
                    else
                    {
                        logger.Log(POILogger.WARN,
                                   "Paragraph #" + paragraph.StartOffset + "-"
                                   + paragraph.EndOffset
                                   + " has reference to list structure #"
                                   + currentListInfo
                                   + ", but listTables not defined in file");

                        ProcessParagraph(wordDocument, flow, currentTableLevel,
                                         paragraph, string.Empty);
                    }
                }
                else
                {
                    ProcessParagraph(wordDocument, flow, currentTableLevel,
                                     paragraph, string.Empty);
                }
            }
        }
示例#11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HWPFDocument"/> class.
        /// </summary>
        /// <param name="directory">The directory.</param>
        public HWPFDocument(DirectoryNode directory)
            : base(directory)
        {
            _endnotes  = new NotesImpl(_endnotesTables);
            _footnotes = new NotesImpl(_footnotesTables);

            // Load the main stream and FIB
            // Also handles HPSF bits

            // Do the CP Split
            _cpSplit = new CPSplitCalculator(_fib);

            // Is this document too old for us?
            if (_fib.GetNFib() < 106)
            {
                throw new OldWordFileFormatException("The document is too old - Word 95 or older. Try HWPFOldDocument instead?");
            }

            // use the fib to determine the name of the table stream.
            String name = "0Table";

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

            // Grab the table stream.
            DocumentEntry tableProps;

            try
            {
                tableProps =
                    (DocumentEntry)directory.GetEntry(name);
            }
            catch (FileNotFoundException)
            {
                throw new InvalidOperationException("Table Stream '" + name + "' wasn't found - Either the document is corrupt, or is Word95 (or earlier)");
            }

            // read in the table stream.
            _tableStream = new byte[tableProps.Size];
            directory.CreatePOIFSDocumentReader(name).Read(_tableStream);

            _fib.FillVariableFields(_mainStream, _tableStream);

            // read in the data stream.
            try
            {
                DocumentEntry dataProps =
                    (DocumentEntry)directory.GetEntry("Data");
                _dataStream = new byte[dataProps.Size];
                directory.CreatePOIFSDocumentReader("Data").Read(_dataStream);
            }
            catch (FileNotFoundException)
            {
                _dataStream = new byte[0];
            }

            // Get the cp of the start of text in the main stream
            // The latest spec doc says this is always zero!
            int fcMin = 0;

            //fcMin = _fib.GetFcMin()

            // Start to load up our standard structures.
            _dop = new DocumentProperties(_tableStream, _fib.GetFcDop());
            _cft = new ComplexFileTable(_mainStream, _tableStream, _fib.GetFcClx(), fcMin);
            TextPieceTable _tpt = _cft.GetTextPieceTable();


            // Now load the rest of the properties, which need to be adjusted
            //  for where text really begin
            _cbt = new CHPBinTable(_mainStream, _tableStream, _fib.GetFcPlcfbteChpx(), _fib.GetLcbPlcfbteChpx(), _tpt);
            _pbt = new PAPBinTable(_mainStream, _tableStream, _dataStream, _fib.GetFcPlcfbtePapx(), _fib.GetLcbPlcfbtePapx(), _tpt);

            _text = _tpt.Text;

            /*
             * in this mode we preserving PAPX/CHPX structure from file, so text may
             * miss from output, and text order may be corrupted
             */
            bool preserveBinTables = false;

            try
            {
                preserveBinTables = Boolean.Parse(
                    ConfigurationManager.AppSettings[PROPERTY_PRESERVE_BIN_TABLES]);
            }
            catch (Exception)
            {
                // ignore;
            }

            if (!preserveBinTables)
            {
                _cbt.Rebuild(_cft);
                _pbt.Rebuild(_text, _cft);
            }

            /*
             * Property to disable text rebuilding. In this mode changing the text
             * will lead to unpredictable behavior
             */
            bool preserveTextTable = false;

            try
            {
                preserveTextTable = Boolean.Parse(
                    ConfigurationManager.AppSettings[PROPERTY_PRESERVE_TEXT_TABLE]);
            }
            catch (Exception)
            {
                // ignore;
            }
            if (!preserveTextTable)
            {
                _cft = new ComplexFileTable();
                _tpt = _cft.GetTextPieceTable();
                TextPiece textPiece = new SinglentonTextPiece(_text);
                _tpt.Add(textPiece);
                _text = textPiece.GetStringBuilder();
            }

            // Read FSPA and Escher information
            // _fspa = new FSPATable(_tableStream, _fib.getFcPlcspaMom(),
            // _fib.getLcbPlcspaMom(), getTextTable().getTextPieces());
            _fspaHeaders = new FSPATable(_tableStream, _fib,
                                         FSPADocumentPart.HEADER);
            _fspaMain = new FSPATable(_tableStream, _fib, FSPADocumentPart.MAIN);

            if (_fib.GetFcDggInfo() != 0)
            {
                _dgg = new EscherRecordHolder(_tableStream, _fib.GetFcDggInfo(), _fib.GetLcbDggInfo());
            }
            else
            {
                _dgg = new EscherRecordHolder();
            }

            // read in the pictures stream
            _pictures = new PicturesTable(this, _dataStream, _mainStream, _fspa, _dgg);
            // And the art shapes stream
            _officeArts = new ShapesTable(_tableStream, _fib);

            // And escher pictures
            _officeDrawingsHeaders = new OfficeDrawingsImpl(_fspaHeaders, _dgg, _mainStream);
            _officeDrawingsMain    = new OfficeDrawingsImpl(_fspaMain, _dgg, _mainStream);

            _st = new SectionTable(_mainStream, _tableStream, _fib.GetFcPlcfsed(), _fib.GetLcbPlcfsed(), fcMin, _tpt, _cpSplit);
            _ss = new StyleSheet(_tableStream, _fib.GetFcStshf());
            _ft = new FontTable(_tableStream, _fib.GetFcSttbfffn(), _fib.GetLcbSttbfffn());

            int listOffset = _fib.GetFcPlcfLst();
            int lfoOffset  = _fib.GetFcPlfLfo();

            if (listOffset != 0 && _fib.GetLcbPlcfLst() != 0)
            {
                _lt = new ListTables(_tableStream, _fib.GetFcPlcfLst(), _fib.GetFcPlfLfo());
            }

            int sbtOffset = _fib.GetFcSttbSavedBy();
            int sbtLength = _fib.GetLcbSttbSavedBy();

            if (sbtOffset != 0 && sbtLength != 0)
            {
                _sbt = new SavedByTable(_tableStream, sbtOffset, sbtLength);
            }

            int rmarkOffset = _fib.GetFcSttbfRMark();
            int rmarkLength = _fib.GetLcbSttbfRMark();

            if (rmarkOffset != 0 && rmarkLength != 0)
            {
                _rmat = new RevisionMarkAuthorTable(_tableStream, rmarkOffset, rmarkLength);
            }


            _bookmarksTables = new BookmarksTables(_tableStream, _fib);
            _bookmarks       = new BookmarksImpl(_bookmarksTables);

            _endnotesTables  = new NotesTables(NoteType.ENDNOTE, _tableStream, _fib);
            _endnotes        = new NotesImpl(_endnotesTables);
            _footnotesTables = new NotesTables(NoteType.FOOTNOTE, _tableStream, _fib);
            _footnotes       = new NotesImpl(_footnotesTables);

            _fieldsTables = new FieldsTables(_tableStream, _fib);
            _fields       = new FieldsImpl(_fieldsTables);
        }