Java Code Examples for org.apache.poi.ss.util.CellReference#convertColStringToIndex()

The following examples show how to use org.apache.poi.ss.util.CellReference#convertColStringToIndex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StAXBasedParser.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to handle start of the "cell" element. It reads required attributes and set the workspace
 * variables.
 */
private void handleCellStart() {
  final String typeValue = xmlStreamReader.getAttributeValue(/*namespaceURI=*/null, ExcelUtil.TYPE);
  lookupNextValueInSST = ExcelUtil.SST_STRING.equals(typeValue);

  determineOutputTypes(
      typeValue,
      xmlStreamReader.getAttributeValue(/*namespaceURI=*/null, ExcelUtil.STYLE));
  currentCellRef = xmlStreamReader.getAttributeValue(/*namespaceURI=*/null, ExcelUtil.CELL_REF);
  String columnName = ExcelUtil.getColumnName(currentCellRef);
  currentColumnIndex = CellReference.convertColStringToIndex(columnName);
}
 
Example 2
Source File: XlsUtils.java    From data-prep with Apache License 2.0 5 votes vote down vote up
/**
 * return the column number from a cell reference (AA242)
 *
 * @param lastCell
 * @return
 */
public static int getColumnNumberFromCellRef(String lastCell) {

    StringBuilder letters = new StringBuilder();
    // get all letters to remove row number
    StringCharacterIterator iter = new StringCharacterIterator(lastCell);
    for (char c = iter.first(); c != StringCharacterIterator.DONE; c = iter.next()) {
        if (!NumberUtils.isNumber(String.valueOf(c))) {
            letters.append(c);
        }
    }
    // use poi api to calculate column number from an excell column format
    return CellReference.convertColStringToIndex(letters.toString());

}
 
Example 3
Source File: OperationEvaluationContext.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private static int parseRowRef(String refStrPart) {
    return CellReference.convertColStringToIndex(refStrPart);
}
 
Example 4
Source File: Util.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
private static void copyPrintTitle(Sheet newSheet, Sheet sheetToCopy) {
	int nbNames = sheetToCopy.getWorkbook().getNumberOfNames();
	Name name = null;
	String formula = null;

	String part1S = null;
	String part2S = null;
	String formS = null;
	String formF = null;
	String part1F = null;
	String part2F = null;
	int rowB = -1;
	int rowE = -1;
	int colB = -1;
	int colE = -1;

	for (int i = 0; i < nbNames; i++) {
		name = sheetToCopy.getWorkbook().getNameAt(i);
		if (name.getSheetIndex() == sheetToCopy.getWorkbook().getSheetIndex(sheetToCopy)) {
			if (name.getNameName().equals("Print_Titles") || name.getNameName().equals(XSSFName.BUILTIN_PRINT_TITLE)) {
				formula = name.getRefersToFormula();
				int indexComma = formula.indexOf(",");
				if (indexComma == -1) {
					indexComma = formula.indexOf(";");
				}
				String firstPart = null;
				;
				String secondPart = null;
				if (indexComma == -1) {
					firstPart = formula;
				} else {
					firstPart = formula.substring(0, indexComma);
					secondPart = formula.substring(indexComma + 1);
				}

				formF = firstPart.substring(firstPart.indexOf("!") + 1);
				part1F = formF.substring(0, formF.indexOf(":"));
				part2F = formF.substring(formF.indexOf(":") + 1);

				if (secondPart != null) {
					formS = secondPart.substring(secondPart.indexOf("!") + 1);
					part1S = formS.substring(0, formS.indexOf(":"));
					part2S = formS.substring(formS.indexOf(":") + 1);
				}

				rowB = -1;
				rowE = -1;
				colB = -1;
				colE = -1;
				String rowBs, rowEs, colBs, colEs;
				if (part1F.lastIndexOf("$") != part1F.indexOf("$")) {
					rowBs = part1F.substring(part1F.lastIndexOf("$") + 1, part1F.length());
					rowEs = part2F.substring(part2F.lastIndexOf("$") + 1, part2F.length());
					rowB = Integer.parseInt(rowBs);
					rowE = Integer.parseInt(rowEs);
					if (secondPart != null) {
						colBs = part1S.substring(part1S.lastIndexOf("$") + 1, part1S.length());
						colEs = part2S.substring(part2S.lastIndexOf("$") + 1, part2S.length());
						colB = CellReference.convertColStringToIndex(colBs);// CExportExcelHelperPoi.convertColumnLetterToInt(colBs);
						colE = CellReference.convertColStringToIndex(colEs);// CExportExcelHelperPoi.convertColumnLetterToInt(colEs);
					}
				} else {
					colBs = part1F.substring(part1F.lastIndexOf("$") + 1, part1F.length());
					colEs = part2F.substring(part2F.lastIndexOf("$") + 1, part2F.length());
					colB = CellReference.convertColStringToIndex(colBs);// CExportExcelHelperPoi.convertColumnLetterToInt(colBs);
					colE = CellReference.convertColStringToIndex(colEs);// CExportExcelHelperPoi.convertColumnLetterToInt(colEs);

					if (secondPart != null) {
						rowBs = part1S.substring(part1S.lastIndexOf("$") + 1, part1S.length());
						rowEs = part2S.substring(part2S.lastIndexOf("$") + 1, part2S.length());
						rowB = Integer.parseInt(rowBs);
						rowE = Integer.parseInt(rowEs);
					}
				}

				newSheet.getWorkbook().setRepeatingRowsAndColumns(newSheet.getWorkbook().getSheetIndex(newSheet), colB, colE, rowB - 1, rowE - 1);
			}
		}
	}
}