C# iTextSharp 5.0.4 PdfCell Problem

roker002

Commander
Registriert
Dez. 2007
Beiträge
2.103
Hi... ich spiele gerade mit iTextSharp herum... will eine Tabelle erstelle... ja alles klappt prima. Naja es ist bisschen umständlicher als die API von MS Word aber was solls.

Mein Problem ist, es gibt ja bei PdfTable die Property DefaultCell. Damit kann man ja angeblich das StandardView oder aussehen der Zelle bestimmen. Nur das es einfach nicht in meine Zellen die ich zu der Tabelle Add'e, der Stil nicht übernohmen wird. Stattdessen habe ich immer die alten Standardwerte.

Ich glaube, wenn man versucht die Zelle hinzu zufügen dann arbeitet der Code nicht mehr mit DefaultCell, sonder mit ncell, was in der Methode erstellt wird.


Wenn man die Zelle hinzufügt von eine vorhandene Zelle.
Code:
        /**
        * Adds a cell element.
        * 
        * @param cell the cell element
        */    
        public void AddCell(PdfPCell cell) {
            rowCompleted = false;
[COLOR="Red"]            PdfPCell ncell = new PdfPCell(cell);[/COLOR]
            
            int colspan = ncell.Colspan;
            colspan = Math.Max(colspan, 1);
            colspan = Math.Min(colspan, currentRow.Length - currentRowIdx);
            ncell.Colspan = colspan;

            if (colspan != 1)
                isColspan = true;
            int rdir = ncell.RunDirection;
            if (rdir == PdfWriter.RUN_DIRECTION_DEFAULT)
                ncell.RunDirection = runDirection;
            
            SkipColsWithRowspanAbove();
            
            bool cellAdded = false;
            if (currentRowIdx < currentRow.Length) {  
                currentRow[currentRowIdx] = ncell;
                currentRowIdx += colspan;
                cellAdded = true;
            }

            SkipColsWithRowspanAbove();
            
            while (currentRowIdx >= currentRow.Length) {
                int numCols = NumberOfColumns;
                if (runDirection == PdfWriter.RUN_DIRECTION_RTL) {
                    PdfPCell[] rtlRow = new PdfPCell[numCols];
                    int rev = currentRow.Length;
                    for (int k = 0; k < currentRow.Length; ++k) {
                        PdfPCell rcell = currentRow[k];
                        int cspan = rcell.Colspan;
                        rev -= cspan;
                        rtlRow[rev] = rcell;
                        k += cspan - 1;
                    }
                    currentRow = rtlRow;
                }
                PdfPRow row = new PdfPRow(currentRow);
                if (totalWidth > 0) {
                    row.SetWidths(absoluteWidths);
                    totalHeight += row.MaxHeights;
                }
                rows.Add(row);
                currentRow = new PdfPCell[numCols];
                currentRowIdx = 0;
                SkipColsWithRowspanAbove();
                rowCompleted = true;
            }
            
            if (!cellAdded) {
                currentRow[currentRowIdx] = ncell;
                currentRowIdx += colspan;
            }
        }

Wenn man die Tabelle in die Zelle hinzufügt.
Code:
        /**
        * Adds a nested table.
        * @param table the table to be added to the cell
        */    
        public void AddCell(PdfPTable table) {
            [COLOR="Red"]defaultCell.Table = table;[/COLOR]
            AddCell(defaultCell);
            defaultCell.Table = null;
        }
 
Zurück
Oben