如何在C/S下打印报表

时间:2023-03-09 18:52:34
如何在C/S下打印报表


java应用有不少是C/S模式,在C/S模式下,同样可以调用API接口运算报表。CSReport是C/S模式下的报表控件类,在这个类中可以获得报表的显示面板、获得报表的打印面板、显示报表打印窗口、直接打印报表等等。

我们来看一下示例代码:

import javax.swing.JFrame;

import com.runqian.report4.model.ReportDefine;


import com.runqian.report4.usermodel.CSReport;

import com.runqian.report4.usermodel.Context;

import com.runqian.report4.usermodel.Engine;

import com.runqian.report4.usermodel.IReport;

import com.runqian.report4.util.ReportUtils;

import com.runqian.report4.util.ReportUtils2;

public class CsPrint {

/**

* @param args

* @throws Throwable

*/

public static void main(String[] args) throws Throwable {

// 读取报表模版的定义

ReportDefine rd = (ReportDefine)ReportUtils.read(“c://a.raq”);

//创建上下文环境

Context ctx = new Context();

//加载引擎

Engine e = new Engine(rd, ctx);

//计算报表

IReport ir = e.calc();

//创建CS报表对象

CSReport csr = new CSReport(ir);

//CS中报表的swing界面的设置等等,需要客户自行根据实际情况完成

JFrame j = new JFrame();

//打印报表

csr.print(j);

//如果是普通的BS结构,可以按照下面的方法来进行打印

/**

* ReportUtils2类:

* 将报表发送到打印机进行打印

* @param report 要打印的报表

* @param needSelectPrinter 是否需要选择打印机

* @throws java.lang.Exception

*/

ReportUtils2.print(ir, true);

}

}

我们可以根据上述的代码,对CS中展现的报表来进行打印.