Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* JasperReports - Free Java Reporting Library.
* Copyright (C) 2001 - 2011 Jaspersoft Corporation. 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 .
*/
/*
* Contributors:
* Greg Hilton
*/
package net.sf.jasperreports.engine.export;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TimeZone;
import net.sf.jasperreports.charts.type.EdgeEnum;
import net.sf.jasperreports.engine.DefaultJasperReportsContext;
import net.sf.jasperreports.engine.JRAbstractExporter;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JRFont;
import net.sf.jasperreports.engine.JRGenericPrintElement;
import net.sf.jasperreports.engine.JRPen;
import net.sf.jasperreports.engine.JRPrintElement;
import net.sf.jasperreports.engine.JRPrintEllipse;
import net.sf.jasperreports.engine.JRPrintFrame;
import net.sf.jasperreports.engine.JRPrintGraphicElement;
import net.sf.jasperreports.engine.JRPrintImage;
import net.sf.jasperreports.engine.JRPrintLine;
import net.sf.jasperreports.engine.JRPrintPage;
import net.sf.jasperreports.engine.JRPrintRectangle;
import net.sf.jasperreports.engine.JRPrintText;
import net.sf.jasperreports.engine.JRPropertiesUtil;
import net.sf.jasperreports.engine.JRStyledTextAttributeSelector;
import net.sf.jasperreports.engine.JasperReportsContext;
import net.sf.jasperreports.engine.base.JRBasePrintText;
import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter;
import net.sf.jasperreports.engine.type.HorizontalAlignEnum;
import net.sf.jasperreports.engine.type.ModeEnum;
import net.sf.jasperreports.engine.type.RotationEnum;
import net.sf.jasperreports.engine.type.RunDirectionEnum;
import net.sf.jasperreports.engine.type.VerticalAlignEnum;
import net.sf.jasperreports.engine.util.JRDataUtils;
import net.sf.jasperreports.engine.util.JRStyledText;
/**
* @author Teodor Danciu ([email protected])
* @version $Id: JRXlsAbstractExporter.java 5363 2012-05-10 11:17:17Z teodord $
*/
public abstract class JRXlsAbstractExporter extends JRAbstractExporter
{
protected static final String XLS_EXPORTER_PROPERTIES_PREFIX = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.";
/**
* Property that stores the formula which has to be applied to a given cell in an excel sheet.
*/
public static final String PROPERTY_CELL_FORMULA = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.formula";
/**
* Property that stores the pattern which has to be applied to a given cell in an excel sheet.
*/
public static final String PROPERTY_CELL_PATTERN = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.pattern";
/**
* This property indicates whether text wrapping is allowed in a given cell.
*
* The property itself defaults to true.
*
* @see JRPropertiesUtil
*/
public static final String PROPERTY_WRAP_TEXT = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.wrap.text";
/**
* This property indicates the number of pages wide to fit the sheet in.
*
* @see JRPropertiesUtil
*/
public static final String PROPERTY_FIT_WIDTH = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.fit.width";
/**
* This property indicates the number of pages height to fit the sheet in.
*
* @see JRPropertiesUtil
*/
public static final String PROPERTY_FIT_HEIGHT = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.fit.height";
/**
* This property indicates whether the cell is locked.
*
* @see JRPropertiesUtil
*/
public static final String PROPERTY_CELL_LOCKED = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.cell.locked";
/**
* This property indicates whether the cell content is hidden.
*
* @see JRPropertiesUtil
*/
public static final String PROPERTY_CELL_HIDDEN = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.cell.hidden";
/**
* This property stores the text content of the sheet header's left side.
*
* @see JRPropertiesUtil
*/
public static final String PROPERTY_SHEET_HEADER_LEFT = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.sheet.header.left";
/**
* This property stores the text content of the sheet header's center.
*
* @see JRPropertiesUtil
*/
public static final String PROPERTY_SHEET_HEADER_CENTER = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.sheet.header.center";
/**
* This property stores the text content of the sheet header's right side.
*
* @see JRPropertiesUtil
*/
public static final String PROPERTY_SHEET_HEADER_RIGHT = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.sheet.header.right";
/**
* This property stores the text content of the sheet footer's left side.
*
* @see JRPropertiesUtil
*/
public static final String PROPERTY_SHEET_FOOTER_LEFT = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.sheet.footer.left";
/**
* This property stores the text content of the sheet footer's center.
*
* @see JRPropertiesUtil
*/
public static final String PROPERTY_SHEET_FOOTER_CENTER = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.sheet.footer.center";
/**
* This property stores the text content of the sheet footer's right side.
*
* @see JRPropertiesUtil
*/
public static final String PROPERTY_SHEET_FOOTER_RIGHT = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.sheet.footer.right";
/**
* This property indicates if the sheet is left-to-right or right-to-left oriented. Possible values are:
*
*
LTR - meaning left-to-right
*
RTL - meaning right-to-left
*
* The default value is LTR.
* @see JRPropertiesUtil
* @see RunDirectionEnum
*/
public static final String PROPERTY_SHEET_DIRECTION = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.sheet.direction";
/**
* Specifies the index of the first unlocked row in document's sheets. All rows above this will be 'frozen'.
* Allowed values are represented by positive integers in the 1..65536 range. Negative values are not considered.
* The property should be used when all sheets in the document have the same freeze row index.
*/
public static final String PROPERTY_FREEZE_ROW = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.freeze.row";
/**
* Indicates the name of the first unlocked column in document's sheets. All columns to the left of this one will be 'frozen'.
* Allowed values are letters or letter combinations representing valid column names in Excel, such as A, B, AB, AC, etc.
* The property should be used when all document sheets have the same freeze column name.
*/
public static final String PROPERTY_FREEZE_COLUMN = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.freeze.column";
/**
* This property indicates the horizontal edge of the freeze pane, relative to the current cell. If set, it overrides the
* PROPERTY_FREEZE_ROW value.
* Allowed values are:
*
*
Top - The current row is the first unlocked row in the sheet. All rows above are 'frozen'.
*
Bottom - The current row is the last 'frozen' row in the sheet. All rows below are unlocked.
*
*/
public static final String PROPERTY_FREEZE_ROW_EDGE = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.freeze.row.edge";
/**
* This property indicates the vertical edge of the freeze pane, relative to the current cell. If set, it overrides the
* PROPERTY_FREEZE_COLUMN and PROPERTY_FREEZE_SHEET_COLUMNS values.
* Allowed values are:
*
*
Left - The current column is the first unlocked column in the sheet. All columns to the left are 'frozen'.
*
Right - The current column is the last 'frozen' column in the sheet. All columns to the right are unlocked.
*
*/
public static final String PROPERTY_FREEZE_COLUMN_EDGE = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.freeze.column.edge";
/**
* Flag property that indicates whether Excel should autofit the current row height.
* Allowed values are:
*
*
true
*
false - this is the default value.
*
*
* @see JRPropertiesUtil
* @since 4.5.1
*/
public static final String PROPERTY_AUTO_FIT_ROW = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.auto.fit.row";
/**
* Flag property that indicates whether Excel should autofit the current column width.
* Allowed values are:
*
*
true
*
false - this is the default value.
*
*
* @see JRPropertiesUtil
* @since 4.5.1
*/
public static final String PROPERTY_AUTO_FIT_COLUMN = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.auto.fit.column";
/**
* This element-level property is used to indicate the boundaries of the autofilter data range in the current sheet.
* Allowed values are:
*
*
Start - The current cell will be marked as autofilter heading cell, and column data below/to the right of
* this cell can be considered as part of the autofilter data range. The starting point of the autofilter data range will be
* the next cell below the current cell (ie if the current cell reference is B4, the autofilter range will start with the "B5"
* cell reference: "B5:M20").
*
* If multiple autofilter Start values are found in the same sheet, only the last one will be considered. If the
* Start value is present but no End value is found in the sheet, then only the current column will
* be considered for the data range.
*
* If the autofilter Start value is set on the same row as the autofilter End value, the data range
* will include all data below this heading row, placed between the start column and the end column.
*
End - The current cell will be marked as autofilter ending cell, and column data in this cell and
* above/to the left can be considered as part of the autofilter data range. The ending cell in the data range is the
* current cell reference (ie if the current cell reference is M20, the autofilter range will end in "M20": "B5:M20").
* The heading cell for the current column will be placed in the same column on the row containing the autofilter Start value.
*
* Caution: If no autofilter Start value is found in the sheet, the autofilter End value will be considered
* as Start value instead.
*
* If multiple autofilter End value are found in the same sheet, only the last one will be considered.
*
* If the autofilter Start value is set on the same row as the autofilter End value, the data range
* will include all data below this heading row, placed between the start column and the end column.
*
*
* @see JRPropertiesUtil
*/
public static final String PROPERTY_AUTO_FILTER = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.auto.filter";
/**
* Element-level property used to adjust the column width to values suitable for Excel output, taking into account
* that column widths are measured in Excel in Normal style default character width units. The pixel-to-character width
* translation depends on the default normal style character width, so it cannot be always accurately fitted. In this case,
* one can adjust the current column width by setting this property with an integer value measured in pixels. The JR engine
* will perform the pixel-to-character width mapping using this value instead of the element's width attribute.
*
* If defined, this property will override the {@link #PROPERTY_COLUMN_WIDTH_RATIO PROPERTY_COLUMN_WIDTH_RATIO} value for the current column
*
* @see #PROPERTY_COLUMN_WIDTH_RATIO
* @see JRPropertiesUtil
*/
public static final String PROPERTY_COLUMN_WIDTH = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.column.width";
/**
* Property used to adjust all column widths in a document or sheet with the same width ratio, in order to get column width
* values suitable for Excel output. Usually column widths are measured by Excel in Normal style default character width
* units, while the JR engine uses pixels as default size units. When exporting the report to the Excel output format, the
* pixel-to-character width translation depends on the normal style default character width provided by the Excel instance,
* so it cannot be always accurately fitted. In this case, one can alter the generated column widths by setting this property
* with a float value representing the adjustment ratio. The property can be set:
*
*
globally - then all the columns in all documents exported to the Excel output format will be adjusted with the same width ratio
*
at report level - then all the columns in the document will be adjusted with the same width ratio
*
at element level - then all the columns in the current sheet will be adjusted with the same width ratio
*
* Global settings are overriden by report level settings and report level settings are overriden by element level settings. If
* present, a {@link #PROPERTY_COLUMN_WIDTH PROPERTY_COLUMN_WIDTH} property will override the
* {@link #PROPERTY_COLUMN_WIDTH_RATIO PROPERTY_COLUMN_WIDTH_RATIO} value for that column only.
*
* @see #PROPERTY_COLUMN_WIDTH
* @see JRPropertiesUtil
*/
public static final String PROPERTY_COLUMN_WIDTH_RATIO = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.column.width.ratio";
/**
* Property prefix used to indicate the current outline row level, and when necessary, the ending row of the current outline row
* group with the given level. The suffix
* of these properties is associated with the outline level, while the property value indicates if the current row group should
* continue or should end. The most recommended practice is to use the outline level itself as property suffix, although this is not
* mandatory. The suffix may take any other string value, but one has to keep in mind that suffixes are used as sorted row level
* descriptors. For instance, because "aaa" < "bbb", the outline level associated with the "aaa" suffix will be smaller than
* the level associated with the "bbb" suffix. The most intuitive representation of the row levels uses the row level as property suffix.
*
* In such a case, The net.sf.jasperreports.export.xls.outline.level.2 property means that its value is correlated with
* the outline level 2, so the current row belongs to a level 2 row group. Based on Office Open XML specs, allowed values for outline
* levels are positive integers from 1 to 7.
*
* The value of this property could be any expression (including null). When such a property occurrence is met, the suffix
* indicates the outline level for that row. If multiple properties with the same prefix are defined for the same row, the deepest
* outline level is considered for that row. To end an outline row group one has to set the related outline level property with the
* End value. This is a special property value instructing the JR engine that the current row group of that level ends
* on the current row.
*
* @see JRPropertiesUtil
*/
public static final String PROPERTY_ROW_OUTLINE_LEVEL_PREFIX = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.row.outline.level.";
/**
* Property that determines whether date values are to be translated to the timezone
* that was used to fill the report.
*
*
* By default, date values are exported to Excel using the default timezone of the system.
* Setting this property to true instructs the exporter to use he report fill
* timezone to export date values.
*
*
* The property only has effect when {@link JRXlsAbstractExporterParameter#IS_DETECT_CELL_TYPE} is set.
*
*
* The property can be set globally, at report level and at element level.
* The default value is false.
*
* @since 4.5.0
*/
public static final String PROPERTY_USE_TIMEZONE = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.use.timezone";
/**
* Property used to store the location of an existing workbook template. The content of an existing workbook document
* or template can be embedded into exported document if the template location is known. In this case the content of
* the template will be exported first and the content of the exported report will be appended to this one. Macros and
* other settings in the existing template will be also preserved in the generated document. Templates can be loaded from
* Excel template files (*.xlt) as well as from valid Excel documents (*.xls).
*
* This property is used in Excel exporters based either on Apache POI APIs ({@link JRXlsExporter}) or on JExcelApi library
* ({@link JExcelApiExporter}). There's no similar property for the {@link JRXlsxExporter}.
*
* @see JRPropertiesUtil
* @since 4.5.1
*/
public static final String PROPERTY_WORKBOOK_TEMPLATE = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.workbook.template";
/**
* Flag property that specifies whether to keep the sheets of the existing template into generated document. Sometimes
* is important to embed in a generated document only macros and/or other global settings from an existing template, but
* without keeping the own sheets of the template document. If set to false, this property prevent the template sheets
* to be exported.
*
* This property is used in conjunction with {@link JRXlsAbstractExporter#PROPERTY_WORKBOOK_TEMPLATE}.
*
* Allowed values are:
*
*
true
*
false - this is the default value.
*
*
* @see JRPropertiesUtil
* @since 4.5.1
*/
public static final String PROPERTY_WORKBOOK_TEMPLATE_KEEP_SHEETS = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.workbook.template.keep.sheets";
/**
* Flag property that indicates whether local anchors should be ignored when elements are exported to Excel. The default value is false.
*
* Property scope:
*
*
Global
*
Report
*
*/
public static final String PROPERTY_IGNORE_ANCHORS = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.ignore.anchors";
/**
* Property used to adjust the page content to a given percent of the normal size in the print preview pane. Allowed values are
* positive integers from 10 to 400, representing percents of the normal size.
*
* Property scope:
*
*
Global
*
Report
*
Element - this setting can be used to set the page scale per sheet
*
* Global settings are overriden by report level settings; report level settings are overriden by element (sheet) level settings.
*
* The property overrides the {@link #PROPERTY_FIT_WIDTH PROPERTY_FIT_WIDTH} and {@link #PROPERTY_FIT_HEIGHT PROPERTY_FIT_HEIGHT} values.
*
* @see JRXlsAbstractExporter#PROPERTY_FIT_WIDTH
* @see JRXlsAbstractExporter#PROPERTY_FIT_HEIGHT
* @see JRPropertiesUtil
*/
public static final String PROPERTY_PAGE_SCALE = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.page.scale";
/**
* Property that specifies the first page number in the page setup dialog.
*
* Property scope:
*
*
Global
*
Report
*
Element - this setting can be used to set the first page number per sheet.
*
* Global settings are overriden by report level settings; report level settings are overriden by element (sheet) level settings.
*
* @see JRPropertiesUtil
*/
public static final String PROPERTY_FIRST_PAGE_NUMBER = JRPropertiesUtil.PROPERTY_PREFIX + "export.xls.first.page.number";
protected static class TextAlignHolder
{
public final HorizontalAlignEnum horizontalAlignment;
public final VerticalAlignEnum verticalAlignment;
public final RotationEnum rotation;
public TextAlignHolder(HorizontalAlignEnum horizontalAlignment, VerticalAlignEnum verticalAlignment, RotationEnum rotation)
{
this.horizontalAlignment = horizontalAlignment;
this.verticalAlignment = verticalAlignment;
this.rotation = rotation;
}
}
/**
*
*/
protected List