iTextSharp.text.Table.AddCell C# (CSharp) Метод

AddCell() публичный Метод

Adds a Cell to the Table at a certain location.
public AddCell ( Cell aCell, object aLocation ) : void
aCell Cell The Cell to add
aLocation object The location where the Cell will be added
Результат void
        public void AddCell(Cell aCell, object aLocation) {
            System.Drawing.Point p;
            if (aCell == null) throw new Exception("addCell - cell has null-value");
            if (aLocation == null)
                throw new Exception("addCell - point has null-value");
            else
                p = (System.Drawing.Point)aLocation;

            if (aCell.IsTable()) {
                IEnumerator i = aCell.Elements.GetEnumerator();
                i.MoveNext();
                InsertTable((Table)i.Current, p);
            }
            if (p.X < 0) throw new BadElementException("row coordinate of location must be >= 0");
            if ((p.Y <= 0) && (p.Y > columns)) throw new BadElementException("column coordinate of location must be >= 0 and < nr of columns");
            if (!IsValidLocation(aCell, p)) throw new BadElementException("Adding a cell at the location (" + p.X + "," + p.Y + ") with a colspan of " + aCell.Colspan + " and a rowspan of " + aCell.Rowspan + " is illegal (beyond boundaries/overlapping).");
            if (aCell.Border == UNDEFINED) aCell.Border = defaultCell.Border;
            aCell.Fill();
            PlaceCell(rows, aCell, p);
            CurrentLocationToNextValidPosition = p;
        }

Same methods

Table::AddCell ( Cell cell ) : void
Table::AddCell ( Cell aCell, int row, int column ) : void
Table::AddCell ( Phrase content ) : void
Table::AddCell ( Phrase content, System location ) : void
Table::AddCell ( string content ) : void
Table::AddCell ( string content, System location ) : void

Usage Example

Пример #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            Page.Title = "Contact List";
            MemoryStream PDFData = new MemoryStream();

            // step 1: creation of a document-object
            Document document = new Document();

            // step 2:
            // we create a writer that listens to the document
            // and directs a PDF-stream to a file

            PdfWriter.GetInstance(document, PDFData);

            // step 3: we open the document
            document.Open();

            // step 4: we add a paragraph to the document
            document.Add(new Paragraph(DateTime.Now.ToString()));
            Contact oContact = new Contact();
            DataTable dtContact = oContact.LoadAll();
            int numRow = dtContact.Rows.Count;
            int numCol = 5;
            iTextSharp.text.Table aTable = new iTextSharp.text.Table(numCol, numRow);
            aTable.AutoFillEmptyCells = true;
            aTable.Padding = 1;
            aTable.Spacing = 1;

            Cell cell = new Cell(new Phrase("Contact List", FontFactory.GetFont(FontFactory.TIMES, 14, Font.BOLD)));
            cell.Header = true;
            cell.Colspan = numCol;
            cell.BackgroundColor = Color.LIGHT_GRAY;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;

            aTable.AddCell(cell);

            for (int i = 0; i < dtContact.Rows.Count; i++)
            {
                for (int n = 1; n <= numCol; n++)
                    aTable.AddCell(dtContact.Rows[i][n].ToString());

            }
            document.Add(aTable);
            // step 5: we close the document
            document.Close();

            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = "application/pdf";
            Response.Charset = string.Empty;
            Response.Cache.SetCacheability(System.Web.HttpCacheability.Public);
            Response.AddHeader("Content-Disposition",
                "attachment; filename=" + Title.Replace(" ", "").Replace(":", "-") + ".pdf");

            Response.OutputStream.Write(PDFData.GetBuffer(), 0, PDFData.GetBuffer().Length);
            Response.OutputStream.Flush();
            Response.OutputStream.Close();
            Response.End();
        }
All Usage Examples Of iTextSharp.text.Table::AddCell