use of org.apache.poi.ss.util.CellRangeAddress in project poi by apache.
the class MergingCells method main.
public static void main(String[] args) throws IOException {
//or new HSSFWorkbook();
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("new sheet");
Row row = sheet.createRow((short) 1);
Cell cell = row.createCell((short) 1);
cell.setCellValue(new XSSFRichTextString("This is a test of merging"));
sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 2));
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("merging_cells.xlsx");
wb.write(fileOut);
fileOut.close();
wb.close();
}
use of org.apache.poi.ss.util.CellRangeAddress in project poi by apache.
the class HSSFSheet method setRepeatingColumns.
@Override
public void setRepeatingColumns(CellRangeAddress columnRangeRef) {
CellRangeAddress rowRangeRef = getRepeatingRows();
setRepeatingRowsAndColumns(rowRangeRef, columnRangeRef);
}
use of org.apache.poi.ss.util.CellRangeAddress in project poi by apache.
the class HSSFSheetConditionalFormatting method addConditionalFormatting.
/**
* Allows to add a new Conditional Formatting set to the sheet.
*
* @param regions - list of rectangular regions to apply conditional formatting rules
* @param cfRules - set of up to three conditional formatting rules
*
* @return index of the newly created Conditional Formatting object
*/
public int addConditionalFormatting(CellRangeAddress[] regions, HSSFConditionalFormattingRule[] cfRules) {
if (regions == null) {
throw new IllegalArgumentException("regions must not be null");
}
for (CellRangeAddress range : regions) range.validate(SpreadsheetVersion.EXCEL97);
if (cfRules == null) {
throw new IllegalArgumentException("cfRules must not be null");
}
if (cfRules.length == 0) {
throw new IllegalArgumentException("cfRules must not be empty");
}
if (cfRules.length > 3) {
throw new IllegalArgumentException("Number of rules must not exceed 3");
}
CFRuleBase[] rules = new CFRuleBase[cfRules.length];
for (int i = 0; i != cfRules.length; i++) {
rules[i] = cfRules[i].getCfRuleRecord();
}
CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules);
return _conditionalFormattingTable.add(cfra);
}
use of org.apache.poi.ss.util.CellRangeAddress in project poi by apache.
the class HSSFSheet method checkForIntersectingMergedRegions.
/**
* Verify that no merged regions intersect another merged region in this sheet.
*
* @throws IllegalStateException if at least one region intersects with another merged region in this sheet
*/
private void checkForIntersectingMergedRegions() {
final List<CellRangeAddress> regions = getMergedRegions();
final int size = regions.size();
for (int i = 0; i < size; i++) {
final CellRangeAddress region = regions.get(i);
for (final CellRangeAddress other : regions.subList(i + 1, regions.size())) {
if (region.intersects(other)) {
String msg = "The range " + region.formatAsString() + " intersects with another merged region " + other.formatAsString() + " in this sheet";
throw new IllegalStateException(msg);
}
}
}
}
use of org.apache.poi.ss.util.CellRangeAddress in project poi by apache.
the class HSSFSheet method getRepeatingRowsOrColums.
private CellRangeAddress getRepeatingRowsOrColums(boolean rows) {
NameRecord rec = getBuiltinNameRecord(NameRecord.BUILTIN_PRINT_TITLE);
if (rec == null) {
return null;
}
Ptg[] nameDefinition = rec.getNameDefinition();
if (nameDefinition == null) {
return null;
}
int maxRowIndex = SpreadsheetVersion.EXCEL97.getLastRowIndex();
int maxColIndex = SpreadsheetVersion.EXCEL97.getLastColumnIndex();
for (Ptg ptg : nameDefinition) {
if (ptg instanceof Area3DPtg) {
Area3DPtg areaPtg = (Area3DPtg) ptg;
if (areaPtg.getFirstColumn() == 0 && areaPtg.getLastColumn() == maxColIndex) {
if (rows) {
return new CellRangeAddress(areaPtg.getFirstRow(), areaPtg.getLastRow(), -1, -1);
}
} else if (areaPtg.getFirstRow() == 0 && areaPtg.getLastRow() == maxRowIndex) {
if (!rows) {
return new CellRangeAddress(-1, -1, areaPtg.getFirstColumn(), areaPtg.getLastColumn());
}
}
}
}
return null;
}
Aggregations