0

是否可以将单个单元格扩展到多行而不影响行宽。

假设我的 PdfTable 有 5 列,我想将第 2 行第 3 列的单元格扩展到第 5 行而不影响任何其他单元格到任何其他行

4

2 回答 2

0

请参阅此示例以及PdfPCell.setRowspan(int)PdfPCell.setColspan(int)

于 2012-08-11T08:52:08.100 回答
0

嗨,请检查这个....代码

    Document doc = new Document();
    PdfWriter docWrite = null;
    DecimalFormat df = new DecimalFormat("0.00");

    DB.getPlayerName_OrderBy( TID1 , Match_ID); 

     try {
            String path =  Environment.getExternalStorageDirectory().getPath() + "/Cric";

            Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0));
            Font bf12 = new Font(FontFamily.TIMES_ROMAN, 12);

            File dir = new File(path);

                if(!dir.exists()){dir.mkdirs();}

            Log.d("PDFCreator", "PDF Path: " + path);                 

            File file = new File(dir, "cric_sample.pdf");
            FileOutputStream fOut = new FileOutputStream(file);

            docWrite = PdfWriter.getInstance(doc, fOut);          

            doc.addTitle("Cricket Scord Card 2013 PDF");
            doc.addCreationDate();
            doc.open(); 
            Paragraph p1 = new Paragraph(teamBatting + " Socre Card 2013 ");

            float[] columnWidths = {5f, 5f, 2f, 2f,2f,2f,2f};
            PdfPTable table = new PdfPTable(columnWidths);
            table.setWidthPercentage(90f);

            insertCell(table, "Player Names", Element.ALIGN_LEFT, 1, bfBold12);
            insertCell(table, "Wicket Status", Element.ALIGN_LEFT, 1, bfBold12);
            insertCell(table, "Runs", Element.ALIGN_LEFT, 1, bfBold12);
            insertCell(table, "Balls", Element.ALIGN_LEFT, 1, bfBold12);
            insertCell(table, "6's", Element.ALIGN_LEFT, 1, bfBold12);
            insertCell(table, "4's", Element.ALIGN_LEFT, 1, bfBold12);
            insertCell(table, "SR", Element.ALIGN_LEFT, 1, bfBold12);

            table.setHeaderRows(1);

            for(int x= 0; x<DatabaseHandler.Player_SD.size(); x++){

                float SR;

                if(DatabaseHandler.Player_SD.get(x).StrikerName == null)
                {
                    break;
                }
                else
                {

                     if(DatabaseHandler.Player_SD.get(x).Mrun !=0 &&DatabaseHandler.Player_SD.get(x).MBolls !=0)
                     {
                         SR= (((float)DatabaseHandler.Player_SD.get(x).Mrun/(float)DatabaseHandler.Player_SD.get(x).MBolls)) * 100;
                     }
                     else
                     {
                         SR =(float) 0.00;
                     }

                        insertCell(table, String.valueOf(DatabaseHandler.Player_SD.get(x).StrikerName), Element.ALIGN_LEFT, 1, bf12);
                        insertCell(table, String.valueOf(DatabaseHandler.Player_SD.get(x).MOut), Element.ALIGN_LEFT, 1, bf12);
                        insertCell(table, String.valueOf(DatabaseHandler.Player_SD.get(x).Mrun) , Element.ALIGN_LEFT, 1, bf12);
                        insertCell(table, String.valueOf(DatabaseHandler.Player_SD.get(x).MBolls), Element.ALIGN_LEFT, 1, bf12);
                        insertCell(table, String.valueOf(DatabaseHandler.Player_SD.get(x).MSix), Element.ALIGN_LEFT, 1, bf12);
                        insertCell(table, String.valueOf(DatabaseHandler.Player_SD.get(x).MFour), Element.ALIGN_LEFT, 1, bf12);                    
                        insertCell(table, String.valueOf(String.format("%.1f",SR)), Element.ALIGN_LEFT, 1, bf12);
                }
               }

           // p1.setAlignment(Paragraph.ALIGN_CENTER);  
            p1.add(table);
            doc.add(p1);

     } catch (DocumentException de) {
             Log.e("PDFCreator", "DocumentException:" + de);
     } catch (IOException e) {
             Log.e("PDFCreator", "ioException:" + e);
     }
     finally
     {
         if(doc != null)
         {
             doc.close();
         }
         if(docWrite != null)
         {
             docWrite.close();
         }
     }
于 2013-10-03T11:07:07.457 回答