use of org.apache.poi.ss.util.CellReference in project poi by apache.
the class XSSFSheet method getTopRow.
/**
* The top row in the visible view when the sheet is
* first viewed after opening it in a viewer
*
* @return integer indicating the rownum (0 based) of the top row
*/
@Override
public short getTopRow() {
String cellRef = getSheetTypeSheetView().getTopLeftCell();
if (cellRef == null) {
return 0;
}
CellReference cellReference = new CellReference(cellRef);
return (short) cellReference.getRow();
}
use of org.apache.poi.ss.util.CellReference in project poi by apache.
the class XSSFSheet method getReferenceBuiltInRecord.
private static String getReferenceBuiltInRecord(String sheetName, int startC, int endC, int startR, int endR) {
// Excel example for built-in title:
// 'second sheet'!$E:$F,'second sheet'!$2:$3
CellReference colRef = new CellReference(sheetName, 0, startC, true, true);
CellReference colRef2 = new CellReference(sheetName, 0, endC, true, true);
CellReference rowRef = new CellReference(sheetName, startR, 0, true, true);
CellReference rowRef2 = new CellReference(sheetName, endR, 0, true, true);
String escapedName = SheetNameFormatter.format(sheetName);
String c = "";
String r = "";
if (startC != -1 || endC != -1) {
String col1 = colRef.getCellRefParts()[2];
String col2 = colRef2.getCellRefParts()[2];
c = escapedName + "!$" + col1 + ":$" + col2;
}
if (startR != -1 || endR != -1) {
String row1 = rowRef.getCellRefParts()[1];
String row2 = rowRef2.getCellRefParts()[1];
if (!row1.equals("0") && !row2.equals("0")) {
r = escapedName + "!$" + row1 + ":$" + row2;
}
}
StringBuilder rng = new StringBuilder();
rng.append(c);
if (rng.length() > 0 && r.length() > 0) {
rng.append(',');
}
rng.append(r);
return rng.toString();
}
use of org.apache.poi.ss.util.CellReference in project poi by apache.
the class XSSFSheet method setAutoFilter.
@SuppressWarnings("resource")
@Override
public XSSFAutoFilter setAutoFilter(CellRangeAddress range) {
CTAutoFilter af = worksheet.getAutoFilter();
if (af == null) {
af = worksheet.addNewAutoFilter();
}
CellRangeAddress norm = new CellRangeAddress(range.getFirstRow(), range.getLastRow(), range.getFirstColumn(), range.getLastColumn());
String ref = norm.formatAsString();
af.setRef(ref);
XSSFWorkbook wb = getWorkbook();
int sheetIndex = getWorkbook().getSheetIndex(this);
XSSFName name = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, sheetIndex);
if (name == null) {
name = wb.createBuiltInName(XSSFName.BUILTIN_FILTER_DB, sheetIndex);
}
name.getCTName().setHidden(true);
CellReference r1 = new CellReference(getSheetName(), range.getFirstRow(), range.getFirstColumn(), true, true);
CellReference r2 = new CellReference(null, range.getLastRow(), range.getLastColumn(), true, true);
String fmla = r1.formatAsString() + ":" + r2.formatAsString();
name.setRefersToFormula(fmla);
return new XSSFAutoFilter(this);
}
use of org.apache.poi.ss.util.CellReference in project poi by apache.
the class XSSFSheet method getLeftCol.
@Override
public short getLeftCol() {
String cellRef = worksheet.getSheetViews().getSheetViewArray(0).getTopLeftCell();
if (cellRef == null) {
return 0;
}
CellReference cellReference = new CellReference(cellRef);
return cellReference.getCol();
}
use of org.apache.poi.ss.util.CellReference in project poi by apache.
the class XSSFSheet method getPaneInformation.
/**
* Returns the information regarding the currently configured pane (split or freeze).
*
* @return null if no pane configured, or the pane information.
*/
@Override
public PaneInformation getPaneInformation() {
CTPane pane = getDefaultSheetView().getPane();
// no pane configured
if (pane == null) {
return null;
}
CellReference cellRef = pane.isSetTopLeftCell() ? new CellReference(pane.getTopLeftCell()) : null;
return new PaneInformation((short) pane.getXSplit(), (short) pane.getYSplit(), (short) (cellRef == null ? 0 : cellRef.getRow()), (cellRef == null ? 0 : cellRef.getCol()), (byte) (pane.getActivePane().intValue() - 1), pane.getState() == STPaneState.FROZEN);
}
Aggregations