@Test public void get_ColumnsNumber() throws Exception { Assertions .assertThat(XlsUtils.getColumnsNumber(getClass().getResourceAsStream("data_xls.xml"))) .isEqualTo(33); Assertions .assertThat(XlsUtils.getColumnsNumber(getClass().getResourceAsStream("simple_data.xml"))) .isEqualTo(4); Assertions .assertThat(XlsUtils.getColumnsNumber(getClass().getResourceAsStream("TDP-1781.xml"))) .isEqualTo(6); }
public static int getColumnsNumber(InputStream inputStream) throws XMLStreamException, IOException { if (!inputStream.markSupported()) { inputStream = new PushbackInputStream(inputStream, 8); } int colNumber = 0; XMLStreamReader streamReader = XML_INPUT_FACTORY.createXMLStreamReader(inputStream); try { while (streamReader.hasNext()) { switch (streamReader.next()) { case START_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "dimension")) { Map<String, String> attributesValues = getAttributesNameValue(streamReader); if (!attributesValues.isEmpty()) { return getColumnsNumberFromDimension(attributesValues.get("ref")); } } if (StringUtils.equals(streamReader.getLocalName(), "col")) { colNumber++; } break; case END_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "cols")) { return colNumber; } default: } } } finally { if (streamReader != null) { streamReader.close(); } } return -1; }
XlsUtils { public static int getColumnsNumber(InputStream inputStream) throws XMLStreamException, IOException { if (!inputStream.markSupported()) { inputStream = new PushbackInputStream(inputStream, 8); } int colNumber = 0; XMLStreamReader streamReader = XML_INPUT_FACTORY.createXMLStreamReader(inputStream); try { while (streamReader.hasNext()) { switch (streamReader.next()) { case START_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "dimension")) { Map<String, String> attributesValues = getAttributesNameValue(streamReader); if (!attributesValues.isEmpty()) { return getColumnsNumberFromDimension(attributesValues.get("ref")); } } if (StringUtils.equals(streamReader.getLocalName(), "col")) { colNumber++; } break; case END_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "cols")) { return colNumber; } default: } } } finally { if (streamReader != null) { streamReader.close(); } } return -1; } }
XlsUtils { public static int getColumnsNumber(InputStream inputStream) throws XMLStreamException, IOException { if (!inputStream.markSupported()) { inputStream = new PushbackInputStream(inputStream, 8); } int colNumber = 0; XMLStreamReader streamReader = XML_INPUT_FACTORY.createXMLStreamReader(inputStream); try { while (streamReader.hasNext()) { switch (streamReader.next()) { case START_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "dimension")) { Map<String, String> attributesValues = getAttributesNameValue(streamReader); if (!attributesValues.isEmpty()) { return getColumnsNumberFromDimension(attributesValues.get("ref")); } } if (StringUtils.equals(streamReader.getLocalName(), "col")) { colNumber++; } break; case END_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "cols")) { return colNumber; } default: } } } finally { if (streamReader != null) { streamReader.close(); } } return -1; } private  XlsUtils(); }
XlsUtils { public static int getColumnsNumber(InputStream inputStream) throws XMLStreamException, IOException { if (!inputStream.markSupported()) { inputStream = new PushbackInputStream(inputStream, 8); } int colNumber = 0; XMLStreamReader streamReader = XML_INPUT_FACTORY.createXMLStreamReader(inputStream); try { while (streamReader.hasNext()) { switch (streamReader.next()) { case START_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "dimension")) { Map<String, String> attributesValues = getAttributesNameValue(streamReader); if (!attributesValues.isEmpty()) { return getColumnsNumberFromDimension(attributesValues.get("ref")); } } if (StringUtils.equals(streamReader.getLocalName(), "col")) { colNumber++; } break; case END_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "cols")) { return colNumber; } default: } } } finally { if (streamReader != null) { streamReader.close(); } } return -1; } private  XlsUtils(); static String getCellValueAsString(Cell cell, FormulaEvaluator formulaEvaluator); static boolean isNewExcelFormat(InputStream inputStream); static List<String> getActiveSheetsFromWorkbookSpec(InputStream inputStream); static int getColumnsNumber(InputStream inputStream); static int getColumnsNumberFromDimension(String dimension); static int getColumnNumberFromCellRef(String lastCell); }
XlsUtils { public static int getColumnsNumber(InputStream inputStream) throws XMLStreamException, IOException { if (!inputStream.markSupported()) { inputStream = new PushbackInputStream(inputStream, 8); } int colNumber = 0; XMLStreamReader streamReader = XML_INPUT_FACTORY.createXMLStreamReader(inputStream); try { while (streamReader.hasNext()) { switch (streamReader.next()) { case START_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "dimension")) { Map<String, String> attributesValues = getAttributesNameValue(streamReader); if (!attributesValues.isEmpty()) { return getColumnsNumberFromDimension(attributesValues.get("ref")); } } if (StringUtils.equals(streamReader.getLocalName(), "col")) { colNumber++; } break; case END_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "cols")) { return colNumber; } default: } } } finally { if (streamReader != null) { streamReader.close(); } } return -1; } private  XlsUtils(); static String getCellValueAsString(Cell cell, FormulaEvaluator formulaEvaluator); static boolean isNewExcelFormat(InputStream inputStream); static List<String> getActiveSheetsFromWorkbookSpec(InputStream inputStream); static int getColumnsNumber(InputStream inputStream); static int getColumnsNumberFromDimension(String dimension); static int getColumnNumberFromCellRef(String lastCell);  }