001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * ExcelReportUtil.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.modules.output.table.xls;
030:
031: import java.io.BufferedOutputStream;
032: import java.io.FileOutputStream;
033: import java.io.IOException;
034: import java.io.OutputStream;
035:
036: import org.jfree.report.JFreeReport;
037: import org.jfree.report.ReportProcessingException;
038: import org.jfree.report.modules.output.table.base.FlowReportProcessor;
039:
040: /**
041: * Utility class to provide an easy to use default implementation of excel exports.
042: *
043: * @author Thomas Morgner
044: */
045: public final class ExcelReportUtil {
046: /**
047: * DefaultConstructor.
048: */
049: private ExcelReportUtil() {
050: }
051:
052: /**
053: * Saves a report to Excel format.
054: *
055: * @param report the report.
056: * @param filename target file name.
057: * @throws ReportProcessingException if the report processing failed.
058: * @throws IOException if there was an IOerror while processing the
059: * report.
060: */
061: public static void createXLS(final JFreeReport report,
062: final String filename) throws IOException,
063: ReportProcessingException {
064: OutputStream fout = new BufferedOutputStream(
065: new FileOutputStream(filename));
066: try {
067: final FlowExcelOutputProcessor target = new FlowExcelOutputProcessor(
068: report.getConfiguration(), fout);
069: final FlowReportProcessor reportProcessor = new FlowReportProcessor(
070: report, target);
071: reportProcessor.processReport();
072: reportProcessor.close();
073: fout.close();
074: fout = null;
075: } finally {
076: if (fout != null) {
077: try {
078: fout.close();
079: } catch (Exception e) {
080: // ignore
081: }
082: }
083: }
084: }
085:
086: /**
087: * Saves a report to Excel format.
088: *
089: * @param report the report.
090: * @param filename target file name.
091: * @throws ReportProcessingException if the report processing failed.
092: * @throws IOException if there was an IOerror while processing the
093: * report.
094: */
095: public static void createXLS(final JFreeReport report,
096: final String filename, final boolean strict)
097: throws IOException, ReportProcessingException {
098: report
099: .getReportConfiguration()
100: .setConfigProperty(
101: "org.jfree.report.modules.output.table.base.StrictLayout",
102: String.valueOf(strict));
103:
104: OutputStream fout = new BufferedOutputStream(
105: new FileOutputStream(filename));
106: try {
107: final FlowExcelOutputProcessor target = new FlowExcelOutputProcessor(
108: report.getConfiguration(), fout);
109: final FlowReportProcessor reportProcessor = new FlowReportProcessor(
110: report, target);
111: reportProcessor.processReport();
112: reportProcessor.close();
113: fout.close();
114: fout = null;
115: } finally {
116: if (fout != null) {
117: try {
118: fout.close();
119: } catch (Exception e) {
120: // ignore
121: }
122: }
123: }
124: }
125:
126: public static void createXLS(final JFreeReport report,
127: final OutputStream outputStream)
128: throws ReportProcessingException {
129: final FlowExcelOutputProcessor target = new FlowExcelOutputProcessor(
130: report.getConfiguration(), outputStream);
131: final FlowReportProcessor reportProcessor = new FlowReportProcessor(
132: report, target);
133: reportProcessor.processReport();
134: reportProcessor.close();
135: }
136: }
|