Пример #1
0
 /**
 * Creates a Table object based on this TableAttributes object.
 * @return a com.lowagie.text.Table object
 * @throws BadElementException
 */
 public Table CreateTable() {
     if (content.Count == 0) throw new BadElementException("Trying to create a table without rows.");
     SimpleCell rowx = (SimpleCell)content[0];
     int columns = 0;
     foreach (SimpleCell cell in rowx.Content) {
         columns += cell.Colspan;
     }
     float[] widths = new float[columns];
     float[] widthpercentages = new float[columns];
     Table table = new Table(columns);
     table.Alignment = alignment;
     table.Spacing = cellspacing;
     table.Padding = cellpadding;
     table.CloneNonPositionParameters(this);
     int pos;
     foreach (SimpleCell row in content) {
         pos = 0;
         foreach (SimpleCell cell in row.Content) {
             table.AddCell(cell.CreateCell(row));
             if (cell.Colspan == 1) {
                 if (cell.Width > 0) widths[pos] = cell.Width;
                 if (cell.Widthpercentage > 0) widthpercentages[pos] = cell.Widthpercentage;
             }
             pos += cell.Colspan;
         }
     }
     float sumWidths = 0f;
     for (int i = 0; i < columns; i++) {
         if (widths[i] == 0) {
             sumWidths = 0;
             break;
         }
         sumWidths += widths[i];
     }
     if (sumWidths > 0) {
         table.Width = sumWidths;
         table.Locked = true;
         table.Widths = widths;
     }
     else {
         for (int i = 0; i < columns; i++) {
             if (widthpercentages[i] == 0) {
                 sumWidths = 0;
                 break;
             }
             sumWidths += widthpercentages[i];
         }
         if (sumWidths > 0) {
             table.Widths = widthpercentages;
         }
     }
     if (width > 0) {
         table.Width = width;
         table.Locked = true;
     }
     else if (widthpercentage > 0) {
         table.Width = widthpercentage;
     }
     return table;
 }
Пример #2
0
        /**
         * Creates a Table object based on this TableAttributes object.
         * @return a com.lowagie.text.Table object
         * @throws BadElementException
         */
        public Table CreateTable()
        {
            if (content.Count == 0)
            {
                throw new BadElementException(MessageLocalization.GetComposedMessage("trying.to.create.a.table.without.rows"));
            }
            SimpleCell rowx    = (SimpleCell)content[0];
            int        columns = 0;

            foreach (SimpleCell cell in rowx.Content)
            {
                columns += cell.Colspan;
            }
            float[] widths           = new float[columns];
            float[] widthpercentages = new float[columns];
            Table   table            = new Table(columns);

            table.Alignment = alignment;
            table.Spacing   = cellspacing;
            table.Padding   = cellpadding;
            table.CloneNonPositionParameters(this);
            int pos;

            foreach (SimpleCell row in content)
            {
                pos = 0;
                foreach (SimpleCell cell in row.Content)
                {
                    table.AddCell(cell.CreateCell(row));
                    if (cell.Colspan == 1)
                    {
                        if (cell.Width > 0)
                        {
                            widths[pos] = cell.Width;
                        }
                        if (cell.Widthpercentage > 0)
                        {
                            widthpercentages[pos] = cell.Widthpercentage;
                        }
                    }
                    pos += cell.Colspan;
                }
            }
            float sumWidths = 0f;

            for (int i = 0; i < columns; i++)
            {
                if (widths[i] == 0)
                {
                    sumWidths = 0;
                    break;
                }
                sumWidths += widths[i];
            }
            if (sumWidths > 0)
            {
                table.Width  = sumWidths;
                table.Locked = true;
                table.Widths = widths;
            }
            else
            {
                for (int i = 0; i < columns; i++)
                {
                    if (widthpercentages[i] == 0)
                    {
                        sumWidths = 0;
                        break;
                    }
                    sumWidths += widthpercentages[i];
                }
                if (sumWidths > 0)
                {
                    table.Widths = widthpercentages;
                }
            }
            if (width > 0)
            {
                table.Width  = width;
                table.Locked = true;
            }
            else if (widthpercentage > 0)
            {
                table.Width = widthpercentage;
            }
            return(table);
        }
        /// <summary>
        /// Creates a Table object based on this TableAttributes object.
        /// @throws BadElementException
        /// </summary>
        /// <returns>a com.lowagie.text.Table object</returns>
        public Table CreateTable()
        {
            if (_content.Count == 0)
            {
                throw new BadElementException("Trying to create a table without rows.");
            }
            SimpleCell rowx    = (SimpleCell)_content[0];
            int        columns = 0;

            foreach (SimpleCell cell in rowx.Content)
            {
                columns += cell.Colspan;
            }
            float[] widths           = new float[columns];
            float[] widthpercentages = new float[columns];
            Table   table            = new Table(columns);

            table.Alignment = _alignment;
            table.Spacing   = _cellspacing;
            table.Padding   = _cellpadding;
            table.CloneNonPositionParameters(this);
            int pos;

            foreach (SimpleCell row in _content)
            {
                pos = 0;
                foreach (SimpleCell cell in row.Content)
                {
                    table.AddCell(cell.CreateCell(row));
                    if (cell.Colspan == 1)
                    {
                        if (cell.Width > 0)
                        {
                            widths[pos] = cell.Width;
                        }
                        if (cell.Widthpercentage > 0)
                        {
                            widthpercentages[pos] = cell.Widthpercentage;
                        }
                    }
                    pos += cell.Colspan;
                }
            }
            float sumWidths = 0f;

            for (int i = 0; i < columns; i++)
            {
                if (widths[i].ApproxEquals(0))
                {
                    sumWidths = 0;
                    break;
                }
                sumWidths += widths[i];
            }
            if (sumWidths > 0)
            {
                table.Width  = sumWidths;
                table.Locked = true;
                table.Widths = widths;
            }
            else
            {
                for (int i = 0; i < columns; i++)
                {
                    if (widthpercentages[i].ApproxEquals(0))
                    {
                        sumWidths = 0;
                        break;
                    }
                    sumWidths += widthpercentages[i];
                }
                if (sumWidths > 0)
                {
                    table.Widths = widthpercentages;
                }
            }
            if (_width > 0)
            {
                table.Width  = _width;
                table.Locked = true;
            }
            else if (_widthpercentage > 0)
            {
                table.Width = _widthpercentage;
            }
            return(table);
        }