itest和jfree使用心得

import org.jfree.data.category.CategoryDataset;
import com.lowagie.text.*;
import bmas.UniqueStringGenerator; /*这个东东是根据时间生成一个唯一的字符串,用来根据不同的用户在不同的时间产生唯一的文件名。
.
.
.
static String CreadPDF(String Title,String [] headerCH,String [] headerEN,int widthsHD[],ArrayList DatList) throws DocumentException, IOException{
   Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);  //定义纸张类型及方向,页边距
      String PDFFile =  new String();  
      PDFFile=UniqueStringGenerator.getUniqueString()+".pdf";
   try {
         BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);//设置中文字体
         Font headFont = new Font(bfChinese, 10, Font.BOLD);//设置字体大小
         Font headFont1 = new Font(bfChinese, 8, Font.BOLD);//设置字体大小
         Font headFont2 = new Font(bfChinese, 10, Font.NORMAL);//设置字体大小
         PdfWriter.getInstance(document,new FileOutputStream("d://"+PDFFile));
         document.open();
         Paragraph p = new Paragraph(Title, headFont2);
         document.add(p);
         int NumColumns = headerCH.length; //定义表格列数
         PdfPTable datatable = new PdfPTable(NumColumns); //创建新表.
         int headerwidths[] = widthsHD; // percentage 定义表格头宽度
         datatable.setWidths(headerwidths);
         datatable.setWidthPercentage(100); // percentage
         datatable.getDefaultCell().setPadding(3);
         datatable.getDefaultCell().setBorderWidth(2);
         datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
  
         //以下是填充表头
         for(int   i=0;i<NumColumns;i++){
          datatable.addCell(new Paragraph(headerCH,headFont2));
         }        
         datatable.setHeaderRows(1); // this is the end of the table header
         datatable.getDefaultCell().setBorderWidth(1);
         for(int  record=0;record<DatList.size();record++){
           HashMap  MAP =(HashMap) DatList.get(record);      
           for(int  HD=0;HD<NumColumns;HD++){
            datatable.addCell(new Paragraph((String)MAP.get(headerEN[HD]),headFont2));
           }  
         }
         document.add(datatable);  //加载新表
}
        catch(DocumentException de) {
            de.printStackTrace();
            System.err.println("document: " + de.getMessage());
        }
        // step 5: we close the document (the outputstream is also closed internally)
        document.close();
        return "d://"+PDFFile;
    }



package bmas;
public class UniqueStringGenerator
{
       UniqueStringGenerator() {}
       public static synchronized String getUniqueString()
       {
           if(generateCount > 99999)
               generateCount = 0;
           String uniqueNumber = Long.toString(System.currentTimeMillis()) + Integer.toString(generateCount);
           generateCount++;
           return uniqueNumber;
       }
       private static final int MAX_GENERATE_COUNT = 99999;
       private static int generateCount = 0;
   }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值