iTextSharp.text.Table.SetWidths C# (CSharp) Method

SetWidths() public method

Sets the widths of the different columns (percentages).
You can give up relative values of borderwidths. The sum of these values will be considered 100%. The values will be recalculated as percentages of this sum.
public SetWidths ( int widths ) : void
widths int an array with values
return void
        public void SetWidths(int[] widths) {
            float[] tb = new float[widths.Length];
            for (int k = 0; k < widths.Length; ++k)
                tb[k] = widths[k];
            this.Widths = tb;
        }
        // methods to retrieve the membervariables

Usage Example

コード例 #1
0
        protected static DocumentPDF printTable(StampaVO.Table tableTmp, DataTable dt, DocumentPDF docPDF)
        {
            if (dt == null)
            {
                return(docPDF);
            }

            //** Operazioni Preliminari
            //reupero del numero di colonne dal DataTable
            int col         = tableTmp.columns.Length;
            int col_visible = 0;

            for (int j = 0; j < tableTmp.columns.Length; j++)
            {
                if (tableTmp.columns[j].visible)
                {
                    col_visible++;
                }
            }

            try
            {
                //creazione della tabella
                iTextSharp.text.Table aTable = new iTextSharp.text.Table(col_visible);

                //Adattamento delle colonne al contenuto
                aTable.Padding   = tableTmp.padding;
                aTable.Spacing   = tableTmp.spacing;
                aTable.Width     = 100;
                aTable.Alignment = Utils.getAlign(tableTmp.align);
                int[] widths = getColWidths(tableTmp, col_visible);

                aTable.SetWidths(widths);
                aTable.TableFitsPage = true;

                //** Aggiunta automatica dell'header della tabella
                for (int k = 0; k < col; k++)
                {
                    if (((StampaVO.Column)tableTmp.columns[k]).visible)
                    {
                        StampaVO.Font font  = tableTmp.headerTable.font;
                        Font          font1 = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color));
                        string        testo = ((StampaVO.Column)tableTmp.columns[k]).alias;
                        Cell          c     = new Cell(new Phrase(testo, font1));
                        c.HorizontalAlignment = Utils.getAlign(tableTmp.headerTable.align);
                        c.VerticalAlignment   = Utils.getAlign(tableTmp.headerTable.vAlign);
                        //c.NoWrap=true;
                        c.BackgroundColor = Utils.getColor(tableTmp.headerTable.bgColor);
                        aTable.AddCell(c);
                    }
                }

                aTable.EndHeaders();

                //** Popolamento automatico della tabella
                //Scansione dei dati
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    //Creazione delle celle
                    for (int h = 0; h < col; h++)
                    {
                        if (((StampaVO.Column)tableTmp.columns[h]).visible)
                        {
                            StampaVO.Font font        = tableTmp.dataTable.font;
                            Font          font1       = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color));
                            string        column_name = tableTmp.columns[h].name;
                            Cell          c1          = new Cell(new Phrase(dt.Rows[i][column_name].ToString(), font1));
                            c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align);
                            c1.VerticalAlignment   = Utils.getAlign(tableTmp.columns[h].vAlign);
                            if (!string.IsNullOrEmpty(tableTmp.columns[h].bgColor))
                            {
                                c1.BackgroundColor = Utils.getColor(tableTmp.columns[h].bgColor);
                            }
                            aTable.AddCell(c1, new System.Drawing.Point(i + 1, h));
                        }
                    }
                }

                docPDF.Add(aTable);
            }
            catch (Exception ex)
            {
                docPDF.Close();
                writer.Close();
                throw new ReportException(ErrorCode.IncompletePDFFile, "Errore nella scrittura dei dati: " + ex.Message);
            }
            return(docPDF);
        }
All Usage Examples Of iTextSharp.text.Table::SetWidths