zoukankan      html  css  js  c++  java
  • IText 表格设置


    package test;

    import java.awt.Color;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import com.lowagie.text.Document;
    import com.lowagie.text.DocumentException;
    import com.lowagie.text.Element;
    import com.lowagie.text.Font;
    import com.lowagie.text.FontFactory;
    import com.lowagie.text.PageSize;
    import com.lowagie.text.Phrase;
    import com.lowagie.text.pdf.PdfPCell;
    import com.lowagie.text.pdf.PdfPTable;
    import com.lowagie.text.pdf.PdfWriter;

    public class PdfPTableRepeatHeader {

        public static void main(String[] args) {
            Document document = new Document(PageSize.A4.rotate());
            try {
                PdfWriter.getInstance(
                        document,
                        new FileOutputStream("report4.pdf"));
                document.open();
                PdfPTable datatable = new PdfPTable(10);
                datatable.setWidthPercentage(100);
                datatable.getDefaultCell().setPadding(5);
                PdfPCell cell = new PdfPCell(new Phrase(
                        "Administration - System Users Report", FontFactory.getFont(FontFactory.HELVETICA, 24, Font.BOLD)));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);

                cell.setBorderWidth(2);
                cell.setColspan(10);
                cell.setBackgroundColor(new Color(213, 141, 69));
                cell.setUseDescender(true);
                datatable.addCell(cell);
                datatable.getDefaultCell().setBorderWidth(2);
                datatable.getDefaultCell().setHorizontalAlignment(
                        Element.ALIGN_CENTER);

                datatable.addCell("User Id");
                datatable.addCell("Name Address");
                datatable.addCell("Company");
                datatable.addCell("Department");

                PdfPTable permissions = new PdfPTable(6);
                permissions.getDefaultCell().setBorderWidth(2);
                permissions.getDefaultCell().setHorizontalAlignment(
                        Element.ALIGN_CENTER);
                permissions.getDefaultCell().setColspan(6);
                permissions.addCell("Permissions");
                permissions.getDefaultCell().setColspan(1);
                permissions.addCell("Admin");
                permissions.addCell("Data");
                permissions.addCell("Expl");
                permissions.addCell("Prod");
                permissions.addCell("Proj");
                permissions.addCell("Online");
                PdfPCell permission = new PdfPCell(permissions);
                permission.setColspan(6);
                datatable.addCell(permission);
                datatable.setHeaderRows(2);
                datatable.getDefaultCell().setBorderWidth(1);
                for (int i = 1; i < 30; i++) {
                    datatable.getDefaultCell().setHorizontalAlignment(
                            Element.ALIGN_LEFT);
                    datatable.addCell("myUserId");
                    datatable.addCell("Somebody with a very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very long long name");
                    datatable.addCell("No Name Company");
                    datatable.addCell("D" + i);

                    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
                    for (int j = 0; j < 6; j++) {
                        datatable.addCell(Math.random() > .5 ? "Yes" : "No");
                    }
                }
                datatable.setSplitLate(false);
                document.add(datatable);
            } catch (DocumentException de) {
                System.err.println(de.getMessage());
            } catch (IOException ioe) {
                System.err.println(ioe.getMessage());
            }
            document.close();
        }
    }

  • 相关阅读:
    【BZOJ 2820】 YY的GCD (莫比乌斯+分块)
    【BZOJ 2005】[Noi2010]能量采集 (容斥原理| 欧拉筛+ 分块)
    【HDU 4898】 The Revenge of the Princess’ Knight (后缀数组+二分+贪心+...)
    【BZOJ 3473】 字符串 (后缀数组+RMQ+二分 | 广义SAM)
    【BZOJ3439】 Kpm的MC密码 (TRIE+主席树)
    【GDOI2014 DAY2】Beyond (扩展KMP)
    【转】【最大子矩阵问题】【悬线法】 学习笔记
    【HDU4333】Revolving Digits(扩展KMP+KMP)
    【转】各种字符串算法大总结
    【poj2478-Farey Sequence】递推求欧拉函数-欧拉函数的几个性质和推论
  • 原文地址:https://www.cnblogs.com/ae6623/p/4416654.html
Copyright © 2011-2022 走看看