* @param templateSheet - template sheet
* @param resultSheet - result sheet
*/
protected void writeHorizontalBand(BandData band, HSSFSheet templateSheet, HSSFSheet resultSheet) {
String rangeName = band.getName();
AreaReference templateRange = getAreaForRange(templateWorkbook, rangeName);
if (templateRange == null) {
throw wrapWithReportingException(String.format("No such named range in xls file: %s", rangeName));
}
CellReference[] crefs = templateRange.getAllReferencedCells();
CellReference topLeft, bottomRight;
AreaReference resultRange;
int rowsAddedByHorizontalBandBackup = rowsAddedByHorizontalBand;
int rownumBackup = rownum;
if (crefs != null) {
addRangeBounds(band, crefs);
ArrayList<HSSFRow> resultRows = new ArrayList<HSSFRow>();
int currentRowNum = -1;
int currentRowCount = -1;
int currentColumnCount = 0;
int offset = 0;
topLeft = new CellReference(rownum + rowsAddedByHorizontalBand, 0);
// no child bands - merge regions now
if (band.getChildrenList().isEmpty()) {
copyMergeRegions(resultSheet, rangeName, rownum + rowsAddedByHorizontalBand,
getCellFromReference(crefs[0], templateSheet).getColumnIndex());
}
for (CellReference cellRef : crefs) {
HSSFCell templateCell = getCellFromReference(cellRef, templateSheet);
HSSFRow resultRow;
if (templateCell.getRowIndex() != currentRowNum) { //create new row
resultRow = resultSheet.createRow(rownum + rowsAddedByHorizontalBand);
copyPageBreaks(templateSheet, resultSheet, templateCell.getRowIndex(), resultRow.getRowNum());
rowsAddedByHorizontalBand += 1;
//todo move to options
if (templateCell.getCellStyle().getParentStyle() != null
&& templateCell.getCellStyle().getParentStyle().getUserStyleName() != null
&& templateCell.getCellStyle().getParentStyle().getUserStyleName().equals(DYNAMIC_HEIGHT_STYLE)
) {
//resultRow.setHeight(templateCell.getRow().getHeight());
} else {
resultRow.setHeight(templateCell.getRow().getHeight());
}
resultRows.add(resultRow);
currentRowNum = templateCell.getRowIndex();
currentRowCount++;
currentColumnCount = 0;
offset = templateCell.getColumnIndex();
} else { // or write cell to current row
resultRow = resultRows.get(currentRowCount);
currentColumnCount++;
}
copyCellFromTemplate(templateCell, resultRow, offset + currentColumnCount, band);
}
bottomRight = new CellReference(rownum + rowsAddedByHorizontalBand - 1, offset + currentColumnCount);
resultRange = new AreaReference(topLeft, bottomRight);
areaDependencyManager.addDependency(new Area(band.getName(), Area.AreaAlign.HORIZONTAL, templateRange),
new Area(band.getName(), Area.AreaAlign.HORIZONTAL, resultRange));
bandsToResultRanges.put(band, new Range(resultSheet.getSheetName(),
resultRange.getFirstCell().getCol() + 1, resultRange.getFirstCell().getRow() + 1,
resultRange.getLastCell().getCol() + 1, resultRange.getLastCell().getRow() + 1
));
}
for (BandData child : band.getChildrenList()) {
writeBand(child);