net.sf.jasperreports.engine.export.ooxml.DocxStyleHelper Maven / Gradle / Ivy
/*
* JasperReports - Free Java Reporting Library.
* Copyright (C) 2001 - 2014 TIBCO Software Inc. All rights reserved.
* http://www.jaspersoft.com
*
* Unless you have purchased a commercial license agreement from Jaspersoft,
* the following license terms apply:
*
* This program is part of JasperReports.
*
* JasperReports 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.
*
* JasperReports 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JasperReports. If not, see .
*/
package net.sf.jasperreports.engine.export.ooxml;
import java.io.Writer;
import java.util.List;
import net.sf.jasperreports.engine.JRStyle;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReportsContext;
import net.sf.jasperreports.engine.design.JRDesignStyle;
import net.sf.jasperreports.engine.util.JRDataUtils;
import net.sf.jasperreports.export.ExporterInput;
import net.sf.jasperreports.export.ExporterInputItem;
/**
* @author Teodor Danciu ([email protected])
*/
public class DocxStyleHelper extends BaseHelper
{
/**
*
*/
private DocxParagraphHelper paragraphHelper;
private DocxRunHelper runHelper;
/**
*
*/
public DocxStyleHelper(JasperReportsContext jasperReportsContext, Writer writer, String exporterKey)
{
super(jasperReportsContext, writer);
paragraphHelper = new DocxParagraphHelper(jasperReportsContext, writer, false);
runHelper = new DocxRunHelper(jasperReportsContext, writer, exporterKey);
}
/**
*
*/
public void export(ExporterInput exporterInput)
{
write("\n");
write("\n");
write(" \n");
write(" \n");
write(" \n");
write(" \n");
write(" \n");
write(" \n");
write(" \n");
write(" \n");
write(" \n");
write(" \n");
write(" \n");
write(" \n");
List items = exporterInput.getItems();
for(int reportIndex = 0; reportIndex < items.size(); reportIndex++)
{
ExporterInputItem item = items.get(reportIndex);
JasperPrint jasperPrint = item.getJasperPrint();
String localeCode = jasperPrint.getLocaleCode();
if (reportIndex == 0)
{
JRDesignStyle style = new JRDesignStyle();
style.setName("EMPTY_CELL_STYLE");
style.setParentStyle(jasperPrint.getDefaultStyle());
style.setFontSize(0f);
exportHeader(style);
paragraphHelper.exportProps(style);
runHelper.exportProps(style, (localeCode == null ? null : JRDataUtils.getLocale(localeCode)));//FIXMEDOCX reuse exporter
exportFooter();
}
JRStyle[] styles = jasperPrint.getStyles();
if (styles != null)
{
for(int i = 0; i < styles.length; i++)
{
JRStyle style = styles[i];
exportHeader(style);
paragraphHelper.exportProps(style);
runHelper.exportProps(style, (localeCode == null ? null : JRDataUtils.getLocale(localeCode)));//FIXMEDOCX reuse exporter
exportFooter();
}
}
}
write(" \n");
}
/**
*
*/
private void exportHeader(JRStyle style)
{
//write(" \n");
write(" \n");
write(" \n");
write(" \n");
String styleNameReference = style.getStyle() == null ? null : style.getStyle().getName();//FIXMEDOCX why getStyleNameReference is not working?
if (styleNameReference != null)
{
write(" \n");
}
}
/**
*
*/
private void exportFooter()
{
write(" \n");
}
}