xdev.tableexport.export.writer.XlsToOutputStreamWriter Maven / Gradle / Ivy
package xdev.tableexport.export.writer;
/*-
* #%L
* XDEV BI Suite
* %%
* Copyright (C) 2011 - 2020 XDEV Software
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import java.io.OutputStream;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import xdev.tableexport.utils.ExportUtils;
/**
* Write the generated report object into XLS format.
*
*
* The generated XLS content is placed into a {@code OutputStream}.
*
*
* @author XDEV Software(FHAE)
*/
public class XlsToOutputStreamWriter implements ExportWriter
{
private final OutputStream stream;
private final String sheetName;
private final Boolean freezeHeadline;
/**
* Constructs a {@link XlsToOutputStreamWriter} object given a {@link OutputStream} object.
* No freeze headline are created.
*
*
* Note - Excel allows sheet names up to 31 chars in length but other applications allow more.
* Excel does not crash with names longer than 31 chars, but silently truncates such names to
* 31 chars.
*
*
* @param stream a {@link OutputStream} object to write to.
* @param sheetName the excel sheet name
*/
public XlsToOutputStreamWriter(final OutputStream stream, final String sheetName)
{
this(stream,sheetName,false);
}
/**
* Constructs a {@link XlsToOutputStreamWriter} object given a {@link OutputStream} object.
*
*
* Note - Excel allows sheet names up to 31 chars in length but other applications allow more.
* Excel does not crash with names longer than 31 chars, but silently truncates such names to
* 31 chars.
*
*
* @param stream a {@link OutputStream} object to write to.
* @param freezeHeadline if true
the freeze pane for the first row is
* created
* @param sheetName the excel sheet name
*/
public XlsToOutputStreamWriter(final OutputStream stream, final String sheetName, final Boolean freezeHeadline)
{
this.stream = stream;
this.sheetName = sheetName;
this.freezeHeadline = freezeHeadline;
}
/**
* {@inheritDoc}
*/
@Override
public void write(JasperPrint jasperPrint) throws ExportWriterException
{
final JRXlsExporter exporterXLS = new JRXlsExporter();
try
{
ExportUtils.prepareExcelExporter(exporterXLS,jasperPrint,this.sheetName,this.freezeHeadline,this.stream);
exporterXLS.exportReport();
}
catch(JRException e)
{
throw new ExportWriterException(e);
}
catch(IllegalArgumentException ie)
{
throw new ExportWriterException(ie);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy