簡表api導出各種格式文件實例

今天用了半個小時研究了一下簡表。具體簡表是什麼我就不說了。想知道的話百度一下。

 

下面是一個簡單的例子。想用就拿走吧。

 

package org.yangzc.report;

import jatools.ReportDocument;
import jatools.designer.export.LocalReportJob;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class ReportDemo {


    public static final int DHTML2 = 0;
    public static final int MHT = 1;
    public static final int PDF = 2;
    public static final int XLS = 3;
    public static final int XLS1 = 4;
    public static final int RTF = 5;
    public static final int CVS = 6;
    public static final int PS = 7;
    public static final int PNG = 8;
	
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		//文件路徑
		String path = "C:/Documents and Settings/Administrator/桌面/財務利潤表.xml";
		//導出文件路徑
		String exportPath = "C:/Documents and Settings/Administrator/桌面/財務利潤表.pdf";
		int type = PDF;
		try {
			//加載報表文件
			ReportDocument doc = ReportDocument.load(new File(path));
            Map parameters = new HashMap();
            //導出報表
            LocalReportJob job = new LocalReportJob(doc, parameters, new File(exportPath));
            try {
                if (type == DHTML2) {
                    job.printAsDHTML();
                } else if (type == PDF) {
                    job.printAsPDF();
                } else if (type == XLS) {
                    job.printAsXLS();
                } else if (type == XLS1) {
                    job.printAsXLS1();
                } else if (type == RTF) {
                    job.printAsRTF();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

 

注:這裏需要JOR源代碼。並且拷貝jatools.properties到工程下。

發佈了27 篇原創文章 · 獲贊 0 · 訪問量 4902
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章