Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- // creates destination file
- File file = new File("multisheet.xlsx");
- // creates sheet 1 with a PreparedStatement and the sheet name
- MempoiSheet dogsSheet = MempoiSheetBuilder.aMempoiSheet()
- .withSheetName("Dogs sheet")
- .withPrepStmt(conn.prepareStatement("SELECT pet_name AS DOG_NAME, pet_race AS DOG_RACE FROM pets WHERE pet_type = 'dog'"))
- .build();
- // creates sheet 2 with a PreparedStatement and the sheet name
- MempoiSheet catsSheet = MempoiSheetBuilder.aMempoiSheet()
- .withSheetName("Cats sheet")
- .withPrepStmt(conn.prepareStatement("SELECT pet_name AS CAT_NAME, pet_race AS CAT_RACE FROM pets WHERE pet_type = 'cat'"))
- .build();
- // creates sheet 3 with a PreparedStatement and the sheet name
- MempoiSheet birdsSheet = MempoiSheetBuilder.aMempoiSheet()
- .withSheetName("Birds sheet")
- .withPrepStmt(conn.prepareStatement("SELECT pet_name AS BIRD_NAME, pet_race AS BIRD_RACE FROM pets WHERE pet_type = 'bird'"))
- .build();
- // creates MemPOI using its builder
- MemPOI memPOI = MempoiBuilder.aMemPOI()
- .withDebug(true)
- .withFile(file)
- .withAdjustColumnWidth(true)
- .addMempoiSheet(dogsSheet)
- .addMempoiSheet(catsSheet)
- .addMempoiSheet(birdsSheet)
- .build();
- // exports to file and gets the generated report absolute filename
- String absFilename = memPOI.prepareMempoiReportToFile().get();
- } catch (ExecutionException e) {
- // using CallableFuture.get() results in an ExecutionException containing the MempoiException with the real error message
- System.out.println(e.getCause().getMessage());
- } catch (InterruptedException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement