Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ else if (element instanceof JRPrintRectangle)
}
else if (element instanceof JRPrintEllipse)
{
exportRectangle((JRPrintEllipse)element, gridCell, colIndex, rowIndex);
exportEllipse((JRPrintEllipse)element, gridCell, colIndex, rowIndex);
}
else if (element instanceof JRPrintImage)
{
Expand Down Expand Up @@ -2404,7 +2404,9 @@ protected void configureDefinedNames(PropertySuffix propertySuffix)

protected abstract void exportImage(JRPrintImage image, JRExporterGridCell cell, int colIndex, int rowIndex, int emptyCols, int yCutsRow, JRGridLayout layout) throws JRException;

protected abstract void exportRectangle(JRPrintGraphicElement element, JRExporterGridCell cell, int colIndex, int rowIndex) throws JRException;
protected abstract void exportRectangle(JRPrintRectangle element, JRExporterGridCell cell, int colIndex, int rowIndex) throws JRException;

protected abstract void exportEllipse(JRPrintEllipse element, JRExporterGridCell cell, int colIndex, int rowIndex) throws JRException;

protected abstract void exportLine(JRPrintLine line, JRExporterGridCell cell, int colIndex, int rowIndex) throws JRException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ else if (element instanceof JRPrintRectangle)
}
else if (element instanceof JRPrintEllipse)
{
exportRectangle((JRPrintEllipse)element);
exportEllipse((JRPrintEllipse)element);
}
else if (element instanceof JRPrintImage)
{
Expand Down Expand Up @@ -547,7 +547,12 @@ public void exportImage(JRPrintImage image, JRExporterGridCell cell, int colInde
}

@Override
protected void exportRectangle(JRPrintGraphicElement element, JRExporterGridCell cell, int colIndex, int rowIndex) throws JRException
protected void exportRectangle(JRPrintRectangle element, JRExporterGridCell cell, int colIndex, int rowIndex) throws JRException
{
}

@Override
protected void exportEllipse(JRPrintEllipse element, JRExporterGridCell cell, int colIndex, int rowIndex) throws JRException
{
}

Expand Down Expand Up @@ -617,7 +622,9 @@ protected void setRowHeight(int rowIndex, int lastRowHeight) throws JRException

public abstract void exportImage(JRPrintImage image) throws JRException;

protected abstract void exportRectangle(JRPrintGraphicElement element) throws JRException;
protected abstract void exportRectangle(JRPrintRectangle element) throws JRException;

protected abstract void exportEllipse(JRPrintEllipse element) throws JRException;

protected abstract void exportLine(JRPrintLine line) throws JRException;

Expand Down
235 changes: 165 additions & 70 deletions jasperreports/src/net/sf/jasperreports/engine/export/JRXlsExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
import org.apache.poi.hssf.usermodel.HSSFPrintSetup;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFShape;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFSimpleShape;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HeaderFooter;
import org.apache.poi.hssf.util.HSSFColor;
Expand All @@ -91,11 +93,13 @@
import net.sf.jasperreports.engine.JRLineBox;
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.JRPrintHyperlink;
import net.sf.jasperreports.engine.JRPrintImage;
import net.sf.jasperreports.engine.JRPrintLine;
import net.sf.jasperreports.engine.JRPrintRectangle;
import net.sf.jasperreports.engine.JRPrintText;
import net.sf.jasperreports.engine.JRPropertiesUtil;
import net.sf.jasperreports.engine.JRRuntimeException;
Expand All @@ -111,6 +115,7 @@
import net.sf.jasperreports.engine.export.type.ImageAnchorTypeEnum;
import net.sf.jasperreports.engine.type.ImageTypeEnum;
import net.sf.jasperreports.engine.type.LineDirectionEnum;
import net.sf.jasperreports.engine.type.LineStyleEnum;
import net.sf.jasperreports.engine.type.ModeEnum;
import net.sf.jasperreports.engine.type.OrientationEnum;
import net.sf.jasperreports.engine.type.RunDirectionEnum;
Expand Down Expand Up @@ -151,7 +156,7 @@ public class JRXlsExporter extends JRXlsAbstractExporter<XlsReportConfiguration,
public static short MAX_COLOR_INDEX = 56;
public static short MIN_COLOR_INDEX = 10; /* Indexes from 0 to 9 are reserved */
private static short A2_PAPERSIZE = (short)66; /* A2_PAPERSIZE defined locally since it is not declared in HSSFPrintSetup */

private static Map<HSSFColor, short[]> hssfColorsRgbs;

static
Expand Down Expand Up @@ -739,99 +744,161 @@ protected void addOccupiedCell(OccupiedGridCell occupiedGridCell, int colIndex,
@Override
protected void exportLine(JRPrintLine line, JRExporterGridCell gridCell, int colIndex, int rowIndex)
{
short forecolor = getWorkbookColor(line.getLinePen().getLineColor()).getIndex();

int side = BoxStyle.TOP;
float ratio = line.getWidth() / line.getHeight();
if (ratio > 1)
int row1 = rowIndex;
int row2 = rowIndex;
if (line.getDirectionValue() == LineDirectionEnum.TOP_DOWN)
{
if (line.getDirectionValue() == LineDirectionEnum.TOP_DOWN)
{
side = BoxStyle.TOP;
}
else
{
side = BoxStyle.BOTTOM;
}
row2 += gridCell.getRowSpan();
}
else
{
if (line.getDirectionValue() == LineDirectionEnum.TOP_DOWN)
{
side = BoxStyle.LEFT;
}
else
row1 += gridCell.getRowSpan();
}
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) colIndex, row1, (short) (colIndex + gridCell.getColSpan()), row2);
HSSFSimpleShape shape = patriarch.createSimpleShape(anchor);
shape.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE );
JRPen pen = line.getLinePen();

if (pen.getLineWidth() > 0)
{
shape.setLineWidth(LengthUtil.emu(Math.round(pen.getLineWidth())));
switch (pen.getLineStyleValue())
{
side = BoxStyle.RIGHT;
case DASHED :
{
shape.setLineStyle(HSSFShape.LINESTYLE_DASHGEL);
break;
}
case DOTTED :
{
shape.setLineStyle(HSSFShape.LINESTYLE_DOTSYS);
break;
}
case DOUBLE :
case SOLID :
default :
{
shape.setLineStyle(HSSFShape.LINESTYLE_SOLID);
break;
}
}
}
BoxStyle boxStyle = new BoxStyle(side, line.getLinePen());

FillPatternType mode = backgroundMode;
short backcolor = whiteIndex;
if (!Boolean.TRUE.equals(sheetInfo.ignoreCellBackground) && gridCell.getCellBackcolor() != null)
Color penColor = pen.getLineColor();
shape.setLineStyleColor(penColor.getRed(), penColor.getGreen(), penColor.getBlue());

if (line.getModeValue() == ModeEnum.OPAQUE && line.getBackcolor() != null)
{
mode = FillPatternType.SOLID_FOREGROUND;
backcolor = getWorkbookColor(gridCell.getCellBackcolor()).getIndex();
Color bgcolor = line.getBackcolor();
shape.setFillColor(bgcolor.getRed(), bgcolor.getGreen(), bgcolor.getBlue());
shape.setNoFill(true);
}
else
{
shape.setNoFill(true);
}
createMergeRegion(gridCell, colIndex, rowIndex);
}

HSSFCellStyle cellStyle =
getLoadedCellStyle(
mode,
backcolor,
HorizontalAlignment.LEFT,
VerticalAlignment.TOP,
(short)0,
getLoadedFont(getDefaultFont(), forecolor, null, getLocale()),
boxStyle,
false,
isCellLocked(line),
isCellHidden(line),
isShrinkToFit(line)
);

createMergeRegion(gridCell, colIndex, rowIndex, cellStyle);
@Override
protected void exportRectangle(JRPrintRectangle element, JRExporterGridCell gridCell, int colIndex, int rowIndex)
{
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) colIndex, rowIndex, (short) (colIndex + gridCell.getColSpan()), rowIndex + gridCell.getRowSpan());
HSSFSimpleShape shape = patriarch.createSimpleShape(anchor);
shape.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE );
JRPen pen = element.getLinePen();

cell = row.createCell(colIndex);
cell.setCellStyle(cellStyle);
}
if (pen.getLineWidth() > 0)
{
shape.setLineWidth(LengthUtil.emu(Math.round(pen.getLineWidth())));
switch (pen.getLineStyleValue())
{
case DASHED :
{
shape.setLineStyle(HSSFShape.LINESTYLE_DASHGEL);
break;
}
case DOTTED :
{
shape.setLineStyle(HSSFShape.LINESTYLE_DOTSYS);
break;
}
case DOUBLE :
case SOLID :
default :
{
shape.setLineStyle(HSSFShape.LINESTYLE_SOLID);
break;
}
}
}

Color penColor = pen.getLineColor();
shape.setLineStyleColor(penColor.getRed(), penColor.getGreen(), penColor.getBlue());

if (element.getModeValue() == ModeEnum.OPAQUE && element.getBackcolor() != null)
{
Color bgcolor = element.getBackcolor();
shape.setFillColor(bgcolor.getRed(), bgcolor.getGreen(), bgcolor.getBlue());
shape.setNoFill(false);
}
else
{
shape.setNoFill(true);
}
createMergeRegion(gridCell, colIndex, rowIndex);
}

@Override
protected void exportRectangle(JRPrintGraphicElement element, JRExporterGridCell gridCell, int colIndex, int rowIndex)
protected void exportEllipse(JRPrintEllipse element, JRExporterGridCell gridCell, int colIndex, int rowIndex)
{
short forecolor = getWorkbookColor(element.getLinePen().getLineColor()).getIndex();
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) colIndex, rowIndex, (short) (colIndex + gridCell.getColSpan()), rowIndex + gridCell.getRowSpan());
HSSFSimpleShape shape = patriarch.createSimpleShape(anchor);
shape.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL);
JRPen pen = element.getLinePen();

FillPatternType mode = backgroundMode;
short backcolor = whiteIndex;
if (!Boolean.TRUE.equals(sheetInfo.ignoreCellBackground) && gridCell.getCellBackcolor() != null)
if (pen.getLineWidth() > 0)
{
mode = FillPatternType.SOLID_FOREGROUND;
backcolor = getWorkbookColor(gridCell.getCellBackcolor()).getIndex();
shape.setLineWidth(LengthUtil.emu(Math.round(pen.getLineWidth())));
switch (pen.getLineStyleValue())
{
case DASHED :
{
shape.setLineStyle(HSSFShape.LINESTYLE_DASHGEL);
break;
}
case DOTTED :
{
shape.setLineStyle(HSSFShape.LINESTYLE_DOTSYS);
break;
}
case DOUBLE :
case SOLID :
default :
{
shape.setLineStyle(HSSFShape.LINESTYLE_SOLID);
break;
}
}
}

HSSFCellStyle cellStyle =
getLoadedCellStyle(
mode,
backcolor,
HorizontalAlignment.LEFT,
VerticalAlignment.TOP,
(short)0,
getLoadedFont(getDefaultFont(), forecolor, null, getLocale()),
gridCell,
isWrapText(element),
isCellLocked(element),
isCellHidden(element),
isShrinkToFit(element)
);

createMergeRegion(gridCell, colIndex, rowIndex, cellStyle);
Color penColor = pen.getLineColor();
shape.setLineStyleColor(penColor.getRed(), penColor.getGreen(), penColor.getBlue());

cell = row.createCell(colIndex);
cell.setCellStyle(cellStyle);
if (element.getModeValue() == ModeEnum.OPAQUE && element.getBackcolor() != null)
{
Color bgcolor = element.getBackcolor();
shape.setFillColor(bgcolor.getRed(), bgcolor.getGreen(), bgcolor.getBlue());
shape.setNoFill(false);
}
else
{
shape.setNoFill(true);
}
createMergeRegion(gridCell, colIndex, rowIndex);
}


@Override
public void exportText(JRPrintText textElement, JRExporterGridCell gridCell, int colIndex, int rowIndex) throws JRException
{
Expand Down Expand Up @@ -1146,6 +1213,34 @@ protected void createMergeRegion(JRExporterGridCell gridCell, int colIndex, int
}
}

protected void createMergeRegion(JRExporterGridCell gridCell, int colIndex, int rowIndex)
{
boolean isCollapseRowSpan = getCurrentItemConfiguration().isCollapseRowSpan();
int rowSpan = isCollapseRowSpan ? 1 : gridCell.getRowSpan();
if (gridCell.getColSpan() > 1 || rowSpan > 1)
{
sheet.addMergedRegion(new CellRangeAddress(rowIndex, (rowIndex + rowSpan - 1),
colIndex, (colIndex + gridCell.getColSpan() - 1)));

for(int i = 0; i < rowSpan; i++)
{
HSSFRow spanRow = sheet.getRow(rowIndex + i);
if (spanRow == null)
{
spanRow = sheet.createRow(rowIndex + i);
}
for(int j = 0; j < gridCell.getColSpan(); j++)
{
HSSFCell spanCell = spanRow.getCell((colIndex + j));
if (spanCell == null)
{
spanCell = spanRow.createCell((colIndex + j));
}
}
}
}
}

private HorizontalAlignment getHorizontalAlignment(TextAlignHolder alignment)
{
switch (alignment.horizontalAlignment)
Expand Down
Loading