Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. private void write(String PATH) {
  2. try {
  3. InputStream inp = new FileInputStream(PATH + "\workbook.xlsx");
  4. Workbook wb = null;
  5. try {
  6. wb = WorkbookFactory.create(inp);
  7. } catch (EncryptedDocumentException | InvalidFormatException e) {
  8. e.printStackTrace();
  9. }
  10. Sheet sheet = wb.getSheetAt(1);
  11. int rowCounter = 0;
  12. Cell[] mas = new Cell[500];
  13. List<Cell> cellList = new LinkedList<Cell>();
  14. for (int i = 0; i < getFinishFile().size(); i++) {
  15. Row row = sheet.createRow(rowCounter++);
  16. for (int j = 0; i < mas.length; i++) {
  17. mas[i] = row.createCell(j);
  18. cellList.add(mas[i]);
  19. }
  20. int j = 0;
  21. for (Cell c : cellList) {
  22. c.setCellValue(getFinishFile().get(i)[j]);
  23. j++;
  24. }
  25. }
  26. FileOutputStream fileOut = new FileOutputStream(PATH + "\workbook.xlsx");
  27. wb.write(fileOut);
  28. fileOut.close();
  29. } catch (IOException e) {
  30. e.printStackTrace();
  31. }
  32. }
  33.  
  34. private static final LENGTH = 500
  35.  
  36. private void write(String PATH) {
  37. try {
  38. InputStream inp = new FileInputStream(PATH + "\workbook.xlsx");
  39. Workbook wb = WorkbookFactory.create(inp);
  40. Sheet sheet = wb.getSheetAt(1);
  41. for (int i = 0; i < getFinishFile().size(); i++) {
  42. Row row = sheet.createRow(i);
  43. for (int j = 0; j < LENGTH; j++) {
  44. row.createCell().setCellValue(getFinishFile().get(i)[j])
  45. }
  46. }
  47. FileOutputStream fileOut = new FileOutputStream(PATH + "\workbook.xlsx");
  48. wb.write(fileOut);
  49. fileOut.close();
  50. } catch (EncryptedDocumentException | IOException e | InvalidFormatException e) {
  51. e.printStackTrace();
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement