Cloud Stack Ninja

Here is an example of what i could like to do: Excel Image

Is there a way to output all the cells between startprint and end_print, i've got like 3 sheet in excel with same place holder, and i want to view only the data between startprint and endprint, for now all i can do is print out all the 3 sheet with all the content, here is my code:

public class ReadInvoices {
    
    private static final String NAME = "C:\\Users\\.......\excelfilename.xlsx";

    public static void main(String[] args) {
        try {
            FileInputStream file = new FileInputStream(new File(NAME));
            Workbook workbook = new XSSFWorkbook(file);
            DataFormatter dataFormatter = new DataFormatter();
            Iterator<Sheet> sheets = workbook.sheetIterator();
            while(sheets.hasNext()) {
                Sheet sh = sheets.next();
                System.out.println("Sheet name is "+sh.getSheetName());
                System.out.println("---------");
                Iterator<Row> iterator = sh.iterator();
                while(iterator.hasNext()) {
                    Row row = iterator.next();
                    Iterator<Cell> cellIterator = row.iterator();
                    while (cellIterator.hasNext()) {
                        Cell cell = cellIterator.next();
                        String cellValue = dataFormatter.formatCellValue(cell);

                        System.out.print(cellValue+"\t");
                    }
                    System.out.println();
                }
            }
            workbook.close();
        }
        catch(Exception e) {
            e.printStackTrace();
        }

    }

}


Read more here: https://stackoverflow.com/questions/64385292/use-java-to-iterate-between-given-placeholders-in-excel

Content Attribution

This content was originally published by user3922899 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: