@Test public void get_active_sheets_simple() throws Exception { List<String> names = XlsUtils.getActiveSheetsFromWorkbookSpec(getClass().getResourceAsStream("simple_workbook.xml")); Assertions .assertThat(names) .isNotEmpty() .containsExactly("Feuille1", "Feuille2", "Feuille3"); }
public static List<String> getActiveSheetsFromWorkbookSpec(InputStream inputStream) throws XMLStreamException { if (!inputStream.markSupported()) { inputStream = new PushbackInputStream(inputStream, 8); } XMLStreamReader streamReader = XML_INPUT_FACTORY.createXMLStreamReader(inputStream); try { List<String> names = new ArrayList<>(); while (streamReader.hasNext()) { switch (streamReader.next()) { case START_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "sheet")) { Map<String, String> attributesValues = getAttributesNameValue(streamReader); if (!attributesValues.isEmpty()) { String sheetState = attributesValues.get("state"); if (!StringUtils.equals(sheetState, "hidden")) { String sheetName = attributesValues.get("name"); names.add(sheetName); } } } break; case XMLStreamConstants.END_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "sheets")) { return names; } break; default: } } return names; } finally { if (streamReader != null) { streamReader.close(); } } }
XlsUtils { public static List<String> getActiveSheetsFromWorkbookSpec(InputStream inputStream) throws XMLStreamException { if (!inputStream.markSupported()) { inputStream = new PushbackInputStream(inputStream, 8); } XMLStreamReader streamReader = XML_INPUT_FACTORY.createXMLStreamReader(inputStream); try { List<String> names = new ArrayList<>(); while (streamReader.hasNext()) { switch (streamReader.next()) { case START_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "sheet")) { Map<String, String> attributesValues = getAttributesNameValue(streamReader); if (!attributesValues.isEmpty()) { String sheetState = attributesValues.get("state"); if (!StringUtils.equals(sheetState, "hidden")) { String sheetName = attributesValues.get("name"); names.add(sheetName); } } } break; case XMLStreamConstants.END_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "sheets")) { return names; } break; default: } } return names; } finally { if (streamReader != null) { streamReader.close(); } } } }
XlsUtils { public static List<String> getActiveSheetsFromWorkbookSpec(InputStream inputStream) throws XMLStreamException { if (!inputStream.markSupported()) { inputStream = new PushbackInputStream(inputStream, 8); } XMLStreamReader streamReader = XML_INPUT_FACTORY.createXMLStreamReader(inputStream); try { List<String> names = new ArrayList<>(); while (streamReader.hasNext()) { switch (streamReader.next()) { case START_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "sheet")) { Map<String, String> attributesValues = getAttributesNameValue(streamReader); if (!attributesValues.isEmpty()) { String sheetState = attributesValues.get("state"); if (!StringUtils.equals(sheetState, "hidden")) { String sheetName = attributesValues.get("name"); names.add(sheetName); } } } break; case XMLStreamConstants.END_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "sheets")) { return names; } break; default: } } return names; } finally { if (streamReader != null) { streamReader.close(); } } } private  XlsUtils(); }
XlsUtils { public static List<String> getActiveSheetsFromWorkbookSpec(InputStream inputStream) throws XMLStreamException { if (!inputStream.markSupported()) { inputStream = new PushbackInputStream(inputStream, 8); } XMLStreamReader streamReader = XML_INPUT_FACTORY.createXMLStreamReader(inputStream); try { List<String> names = new ArrayList<>(); while (streamReader.hasNext()) { switch (streamReader.next()) { case START_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "sheet")) { Map<String, String> attributesValues = getAttributesNameValue(streamReader); if (!attributesValues.isEmpty()) { String sheetState = attributesValues.get("state"); if (!StringUtils.equals(sheetState, "hidden")) { String sheetName = attributesValues.get("name"); names.add(sheetName); } } } break; case XMLStreamConstants.END_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "sheets")) { return names; } break; default: } } return names; } finally { if (streamReader != null) { streamReader.close(); } } } 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 List<String> getActiveSheetsFromWorkbookSpec(InputStream inputStream) throws XMLStreamException { if (!inputStream.markSupported()) { inputStream = new PushbackInputStream(inputStream, 8); } XMLStreamReader streamReader = XML_INPUT_FACTORY.createXMLStreamReader(inputStream); try { List<String> names = new ArrayList<>(); while (streamReader.hasNext()) { switch (streamReader.next()) { case START_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "sheet")) { Map<String, String> attributesValues = getAttributesNameValue(streamReader); if (!attributesValues.isEmpty()) { String sheetState = attributesValues.get("state"); if (!StringUtils.equals(sheetState, "hidden")) { String sheetName = attributesValues.get("name"); names.add(sheetName); } } } break; case XMLStreamConstants.END_ELEMENT: if (StringUtils.equals(streamReader.getLocalName(), "sheets")) { return names; } break; default: } } return names; } finally { if (streamReader != null) { streamReader.close(); } } } 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);  }