Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. try {
  2.  
  3. // creates destination file
  4. File file = new File("multisheet.xlsx");
  5.  
  6. // creates sheet 1 with a PreparedStatement and the sheet name
  7. MempoiSheet dogsSheet = MempoiSheetBuilder.aMempoiSheet()
  8. .withSheetName("Dogs sheet")
  9. .withPrepStmt(conn.prepareStatement("SELECT pet_name AS DOG_NAME, pet_race AS DOG_RACE FROM pets WHERE pet_type = 'dog'"))
  10. .build();
  11.  
  12. // creates sheet 2 with a PreparedStatement and the sheet name
  13. MempoiSheet catsSheet = MempoiSheetBuilder.aMempoiSheet()
  14. .withSheetName("Cats sheet")
  15. .withPrepStmt(conn.prepareStatement("SELECT pet_name AS CAT_NAME, pet_race AS CAT_RACE FROM pets WHERE pet_type = 'cat'"))
  16. .build();
  17.  
  18. // creates sheet 3 with a PreparedStatement and the sheet name
  19. MempoiSheet birdsSheet = MempoiSheetBuilder.aMempoiSheet()
  20. .withSheetName("Birds sheet")
  21. .withPrepStmt(conn.prepareStatement("SELECT pet_name AS BIRD_NAME, pet_race AS BIRD_RACE FROM pets WHERE pet_type = 'bird'"))
  22. .build();
  23.  
  24. // creates MemPOI using its builder
  25. MemPOI memPOI = MempoiBuilder.aMemPOI()
  26. .withDebug(true)
  27. .withFile(file)
  28. .withAdjustColumnWidth(true)
  29. .addMempoiSheet(dogsSheet)
  30. .addMempoiSheet(catsSheet)
  31. .addMempoiSheet(birdsSheet)
  32. .build();
  33.  
  34. // exports to file and gets the generated report absolute filename
  35. String absFilename = memPOI.prepareMempoiReportToFile().get();
  36.  
  37. } catch (ExecutionException e) {
  38. // using CallableFuture.get() results in an ExecutionException containing the MempoiException with the real error message
  39. System.out.println(e.getCause().getMessage());
  40. } catch (InterruptedException e) {
  41. e.printStackTrace();
  42. } catch (SQLException e) {
  43. e.printStackTrace();
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement