jasper 생성 excel 실례


/**
 jar 
commons-beanutils-1.9.0.jar
commons-collections-3.2.1.jar
commons-digester-2.1.jar
commons-logging-1.1.1.jar
groovy-all-2.0.1.jar
iText-2.1.7.jar
iText-2.1.7.js2.jar
iTextAsian.jar
jasperreports-6.1.0.jar
jasperreports-fonts-6.1.0.jar
jxl-2.6.10.jar
mysql-connector-java-5.1.7-bin.jar
*/
package jasper;

import java.io.File;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.HashMap;
import java.util.Map;

import net.sf.jasperreports.engine.JRAbstractExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.JExcelApiExporter;

public class ExcelJasperTest {
	public static void main(String[] args) throws Exception{
		String reportFile = "D:\\work\\jasper\\jasper\\report.jasper";

		Class.forName("com.mysql.jdbc.Driver");
		String url = "jdbc:mysql://localhost:3306/exam";
		String username = "root";
		String password = "huxc";

		Connection conn = DriverManager.getConnection(url, username, password);

		Map map = new HashMap();
		JasperPrint report = JasperFillManager.fillReport(reportFile, map, conn);
		JRAbstractExporter exporter = new JExcelApiExporter();
		FileOutputStream output = new FileOutputStream("D:\\work\\jasper\\jasper\\excel.xls");
		exporter.setParameter(JRExporterParameter.JASPER_PRINT, report);
		exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, output);
		exporter.exportReport();

	}
}


좋은 웹페이지 즐겨찾기