Elenco Java alle colonne di Excel

Correggi where andremo male.

Ho scritto un programma in Java che otterrà l'elenco di file da due diverse directory e crea due (elenco di Java) con i nomi dei file. Voglio trasferire l'elenco (l'elenco dei file scaricati e l'elenco dei file caricati) in un excel.

Quello che ho ottenuto è che l'elenco viene trasferito in fila. Li voglio in colonna.

Di seguito è riportto il codice:

public class F { static List<String> downloadList = new ArrayList<>(); static List<String> dispatchList = new ArrayList<>(); public static class FileVisitor extends SimpleFileVisitor<Path> { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String name = file.toRealPath().getFileName().toString(); if (name.endsWith(".pdf") || name.endsWith(".zip")) { downloadList.add(name); } if (name.endsWith(".xml")) { dispatchList.add(name); } return FileVisitResult.CONTINUE; } } public static void main(String[] args) throws IOException { try { Path downloadPath = Paths.get("E:\\report\\02_Download\\10252013"); Path dispatchPath = Paths.get("E:\\report\\01_Dispatch\\10252013"); FileVisitor visitor = new FileVisitor(); Files.walkFileTree(downloadPath, visitor); Files.walkFileTree(downloadPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, visitor); Files.walkFileTree(dispatchPath, visitor); Files.walkFileTree(dispatchPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, visitor); System.out.println("Download File List" + downloadList); System.out.println("Dispatch File List" + dispatchList); F f = new F(); f.UpDown(downloadList, dispatchList); } catch (Exception ex) { Logger.getLogger(F.class.getName()).log(Level.SEVERE, null, ex); } } int rownum = 0; int colnum = 0; HSSFSheet firstSheet; Collection<File> files; HSSFWorkbook workbook; File exactFile; { workbook = new HSSFWorkbook(); firstSheet = workbook.createSheet("10252013"); Row headerRow = firstSheet.createRow(rownum); headerRow.setHeightInPoints(40); } public void UpDown(List<String> download, List<String> upload) throws Exception { List<String> headerRow = new ArrayList<>(); headerRow.add("Downloaded"); headerRow.add("Uploaded"); List<List> recordToAdd = new ArrayList<>(); recordToAdd.add(headerRow); recordToAdd.add(download); recordToAdd.add(upload); F f = new F(); f.CreateExcelFile(recordToAdd); f.createExcelFile(); } void createExcelFile() { FileOutputStream fos = null; try { fos = new FileOutputStream(new File("E:\\report\\Download&Upload.xls")); HSSFCellStyle hsfstyle = workbook.createCellStyle(); hsfstyle.setBorderBottom((short) 1); hsfstyle.setFillBackgroundColor((short) 245); workbook.write(fos); } catch (Exception e) { } } public void CreateExcelFile(List<List> l1) throws Exception { try { for (int j = 0; j < l1.size(); j++) { Row row = firstSheet.createRow(rownum); List<String> l2 = l1.get(j); for (int k = 0; k < l2.size(); k++) { Cell cell = row.createCell(k); cell.setCellValue(l2.get(k)); } rownum++; } } catch (Exception e) { } finally { } } } 

(Lo scopo è verificare i file scaricati e caricati per la data data) Grazie.

Se si desidera accedere / creare il foglio di lavoro nelle colonne invece di righe , è necessario modificare il foglio di lavoro che accede al codice.

Snipped out dal tuo codice esistente, ecco le funzioni chiave:

 Row row = firstSheet.createRow( rowNum); Cell cell = row.createCell( colNum); cell.setCellValue( value); 

È necessario riorganizzare questi loop per produrre i tuoi dati in modo colonna .

Grazie per i suggerimenti .. Ho modificato il mio programma e caricato con la soluzione.

 public class F { static List<String> downloadList = new ArrayList<>(); static List<String> dispatchList = new ArrayList<>(); public static class FileVisitor extends SimpleFileVisitor<Path> { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String name = file.toRealPath().getFileName().toString(); if (name.endsWith(".pdf") || name.endsWith(".zip")) { downloadList.add(name); } if (name.endsWith(".xml")) { dispatchList.add(name); } return FileVisitResult.CONTINUE; } } public static void main(String[] args) throws IOException { try { Path downloadPath = Paths.get("E:\\Download\\10292013"); Path dispatchPath = Paths.get("E:\\Dispatch\\10292013"); FileVisitor visitor = new FileVisitor(); Files.walkFileTree(downloadPath, visitor); Files.walkFileTree(downloadPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, visitor); Files.walkFileTree(dispatchPath, visitor); Files.walkFileTree(dispatchPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, visitor); /* List all files*/ System.out.println("Download File List" + downloadList); System.out.println("Dispatch File List" + dispatchList); F f = new F(); f.UpDown(downloadList, dispatchList); } catch (Exception ex) { Logger.getLogger(F.class.getName()).log(Level.SEVERE, null, ex); } } int rownum = 0; int colnum = 0; HSSFSheet firstSheet; Collection<File> files; HSSFWorkbook workbook; File exactFile; { workbook = new HSSFWorkbook(); firstSheet = workbook.createSheet("10292013"); Row headerRow = firstSheet.createRow(rownum); headerRow.setHeightInPoints(40); } public void UpDown(List<String> download, List<String> upload) throws Exception { List<String> headerRow = new ArrayList<String>(); headerRow.add("Downloaded"); headerRow.add("Uploaded"); List<List<String>> recordToAdd = new ArrayList<List<String>>(); recordToAdd.add(headerRow); recordToAdd.add(download); recordToAdd.add(upload); CreateExcelFile(headerRow, download, upload); createExcelFile(); } void createExcelFile() { FileOutputStream fos = null; try { fos = new FileOutputStream(new File("E:\\report\\Download&Upload.xls")); HSSFCellStyle hsfstyle = workbook.createCellStyle(); hsfstyle.setBorderBottom((short) 1); hsfstyle.setFillBackgroundColor((short) 245); workbook.write(fos); } catch (Exception e) { } } public void CreateExcelFile(List<String> headers, List<String> down, List<String> up) throws Exception { try { Row row = firstSheet.createRow((short)(rownum++)); for(int i = 0;i < headers.size();i++) { Cell cell = row.createCell(i); cell.setCellValue(headers.get(i)); } for (int j = 0; j < down.size(); j++) { row = firstSheet.createRow((short)(rownum++)); Cell cell = row.createCell(0); cell.setCellValue(down.get(j)); if(up.size() > j) { cell = row.createCell(1); cell.setCellValue(up.get(j)); } } } catch (Exception e) { } finally { } } } public void main void (String [] args) lancia IOException { public class F { static List<String> downloadList = new ArrayList<>(); static List<String> dispatchList = new ArrayList<>(); public static class FileVisitor extends SimpleFileVisitor<Path> { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String name = file.toRealPath().getFileName().toString(); if (name.endsWith(".pdf") || name.endsWith(".zip")) { downloadList.add(name); } if (name.endsWith(".xml")) { dispatchList.add(name); } return FileVisitResult.CONTINUE; } } public static void main(String[] args) throws IOException { try { Path downloadPath = Paths.get("E:\\Download\\10292013"); Path dispatchPath = Paths.get("E:\\Dispatch\\10292013"); FileVisitor visitor = new FileVisitor(); Files.walkFileTree(downloadPath, visitor); Files.walkFileTree(downloadPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, visitor); Files.walkFileTree(dispatchPath, visitor); Files.walkFileTree(dispatchPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, visitor); /* List all files*/ System.out.println("Download File List" + downloadList); System.out.println("Dispatch File List" + dispatchList); F f = new F(); f.UpDown(downloadList, dispatchList); } catch (Exception ex) { Logger.getLogger(F.class.getName()).log(Level.SEVERE, null, ex); } } int rownum = 0; int colnum = 0; HSSFSheet firstSheet; Collection<File> files; HSSFWorkbook workbook; File exactFile; { workbook = new HSSFWorkbook(); firstSheet = workbook.createSheet("10292013"); Row headerRow = firstSheet.createRow(rownum); headerRow.setHeightInPoints(40); } public void UpDown(List<String> download, List<String> upload) throws Exception { List<String> headerRow = new ArrayList<String>(); headerRow.add("Downloaded"); headerRow.add("Uploaded"); List<List<String>> recordToAdd = new ArrayList<List<String>>(); recordToAdd.add(headerRow); recordToAdd.add(download); recordToAdd.add(upload); CreateExcelFile(headerRow, download, upload); createExcelFile(); } void createExcelFile() { FileOutputStream fos = null; try { fos = new FileOutputStream(new File("E:\\report\\Download&Upload.xls")); HSSFCellStyle hsfstyle = workbook.createCellStyle(); hsfstyle.setBorderBottom((short) 1); hsfstyle.setFillBackgroundColor((short) 245); workbook.write(fos); } catch (Exception e) { } } public void CreateExcelFile(List<String> headers, List<String> down, List<String> up) throws Exception { try { Row row = firstSheet.createRow((short)(rownum++)); for(int i = 0;i < headers.size();i++) { Cell cell = row.createCell(i); cell.setCellValue(headers.get(i)); } for (int j = 0; j < down.size(); j++) { row = firstSheet.createRow((short)(rownum++)); Cell cell = row.createCell(0); cell.setCellValue(down.get(j)); if(up.size() > j) { cell = row.createCell(1); cell.setCellValue(up.get(j)); } } } catch (Exception e) { } finally { } } } int rownum = 0; public class F { static List<String> downloadList = new ArrayList<>(); static List<String> dispatchList = new ArrayList<>(); public static class FileVisitor extends SimpleFileVisitor<Path> { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String name = file.toRealPath().getFileName().toString(); if (name.endsWith(".pdf") || name.endsWith(".zip")) { downloadList.add(name); } if (name.endsWith(".xml")) { dispatchList.add(name); } return FileVisitResult.CONTINUE; } } public static void main(String[] args) throws IOException { try { Path downloadPath = Paths.get("E:\\Download\\10292013"); Path dispatchPath = Paths.get("E:\\Dispatch\\10292013"); FileVisitor visitor = new FileVisitor(); Files.walkFileTree(downloadPath, visitor); Files.walkFileTree(downloadPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, visitor); Files.walkFileTree(dispatchPath, visitor); Files.walkFileTree(dispatchPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, visitor); /* List all files*/ System.out.println("Download File List" + downloadList); System.out.println("Dispatch File List" + dispatchList); F f = new F(); f.UpDown(downloadList, dispatchList); } catch (Exception ex) { Logger.getLogger(F.class.getName()).log(Level.SEVERE, null, ex); } } int rownum = 0; int colnum = 0; HSSFSheet firstSheet; Collection<File> files; HSSFWorkbook workbook; File exactFile; { workbook = new HSSFWorkbook(); firstSheet = workbook.createSheet("10292013"); Row headerRow = firstSheet.createRow(rownum); headerRow.setHeightInPoints(40); } public void UpDown(List<String> download, List<String> upload) throws Exception { List<String> headerRow = new ArrayList<String>(); headerRow.add("Downloaded"); headerRow.add("Uploaded"); List<List<String>> recordToAdd = new ArrayList<List<String>>(); recordToAdd.add(headerRow); recordToAdd.add(download); recordToAdd.add(upload); CreateExcelFile(headerRow, download, upload); createExcelFile(); } void createExcelFile() { FileOutputStream fos = null; try { fos = new FileOutputStream(new File("E:\\report\\Download&Upload.xls")); HSSFCellStyle hsfstyle = workbook.createCellStyle(); hsfstyle.setBorderBottom((short) 1); hsfstyle.setFillBackgroundColor((short) 245); workbook.write(fos); } catch (Exception e) { } } public void CreateExcelFile(List<String> headers, List<String> down, List<String> up) throws Exception { try { Row row = firstSheet.createRow((short)(rownum++)); for(int i = 0;i < headers.size();i++) { Cell cell = row.createCell(i); cell.setCellValue(headers.get(i)); } for (int j = 0; j < down.size(); j++) { row = firstSheet.createRow((short)(rownum++)); Cell cell = row.createCell(0); cell.setCellValue(down.get(j)); if(up.size() > j) { cell = row.createCell(1); cell.setCellValue(up.get(j)); } } } catch (Exception e) { } finally { } } } } catch (Eccezione e) { public class F { static List<String> downloadList = new ArrayList<>(); static List<String> dispatchList = new ArrayList<>(); public static class FileVisitor extends SimpleFileVisitor<Path> { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String name = file.toRealPath().getFileName().toString(); if (name.endsWith(".pdf") || name.endsWith(".zip")) { downloadList.add(name); } if (name.endsWith(".xml")) { dispatchList.add(name); } return FileVisitResult.CONTINUE; } } public static void main(String[] args) throws IOException { try { Path downloadPath = Paths.get("E:\\Download\\10292013"); Path dispatchPath = Paths.get("E:\\Dispatch\\10292013"); FileVisitor visitor = new FileVisitor(); Files.walkFileTree(downloadPath, visitor); Files.walkFileTree(downloadPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, visitor); Files.walkFileTree(dispatchPath, visitor); Files.walkFileTree(dispatchPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, visitor); /* List all files*/ System.out.println("Download File List" + downloadList); System.out.println("Dispatch File List" + dispatchList); F f = new F(); f.UpDown(downloadList, dispatchList); } catch (Exception ex) { Logger.getLogger(F.class.getName()).log(Level.SEVERE, null, ex); } } int rownum = 0; int colnum = 0; HSSFSheet firstSheet; Collection<File> files; HSSFWorkbook workbook; File exactFile; { workbook = new HSSFWorkbook(); firstSheet = workbook.createSheet("10292013"); Row headerRow = firstSheet.createRow(rownum); headerRow.setHeightInPoints(40); } public void UpDown(List<String> download, List<String> upload) throws Exception { List<String> headerRow = new ArrayList<String>(); headerRow.add("Downloaded"); headerRow.add("Uploaded"); List<List<String>> recordToAdd = new ArrayList<List<String>>(); recordToAdd.add(headerRow); recordToAdd.add(download); recordToAdd.add(upload); CreateExcelFile(headerRow, download, upload); createExcelFile(); } void createExcelFile() { FileOutputStream fos = null; try { fos = new FileOutputStream(new File("E:\\report\\Download&Upload.xls")); HSSFCellStyle hsfstyle = workbook.createCellStyle(); hsfstyle.setBorderBottom((short) 1); hsfstyle.setFillBackgroundColor((short) 245); workbook.write(fos); } catch (Exception e) { } } public void CreateExcelFile(List<String> headers, List<String> down, List<String> up) throws Exception { try { Row row = firstSheet.createRow((short)(rownum++)); for(int i = 0;i < headers.size();i++) { Cell cell = row.createCell(i); cell.setCellValue(headers.get(i)); } for (int j = 0; j < down.size(); j++) { row = firstSheet.createRow((short)(rownum++)); Cell cell = row.createCell(0); cell.setCellValue(down.get(j)); if(up.size() > j) { cell = row.createCell(1); cell.setCellValue(up.get(j)); } } } catch (Exception e) { } finally { } } } Cell cellulare = row.createCell (0); public class F { static List<String> downloadList = new ArrayList<>(); static List<String> dispatchList = new ArrayList<>(); public static class FileVisitor extends SimpleFileVisitor<Path> { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String name = file.toRealPath().getFileName().toString(); if (name.endsWith(".pdf") || name.endsWith(".zip")) { downloadList.add(name); } if (name.endsWith(".xml")) { dispatchList.add(name); } return FileVisitResult.CONTINUE; } } public static void main(String[] args) throws IOException { try { Path downloadPath = Paths.get("E:\\Download\\10292013"); Path dispatchPath = Paths.get("E:\\Dispatch\\10292013"); FileVisitor visitor = new FileVisitor(); Files.walkFileTree(downloadPath, visitor); Files.walkFileTree(downloadPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, visitor); Files.walkFileTree(dispatchPath, visitor); Files.walkFileTree(dispatchPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, visitor); /* List all files*/ System.out.println("Download File List" + downloadList); System.out.println("Dispatch File List" + dispatchList); F f = new F(); f.UpDown(downloadList, dispatchList); } catch (Exception ex) { Logger.getLogger(F.class.getName()).log(Level.SEVERE, null, ex); } } int rownum = 0; int colnum = 0; HSSFSheet firstSheet; Collection<File> files; HSSFWorkbook workbook; File exactFile; { workbook = new HSSFWorkbook(); firstSheet = workbook.createSheet("10292013"); Row headerRow = firstSheet.createRow(rownum); headerRow.setHeightInPoints(40); } public void UpDown(List<String> download, List<String> upload) throws Exception { List<String> headerRow = new ArrayList<String>(); headerRow.add("Downloaded"); headerRow.add("Uploaded"); List<List<String>> recordToAdd = new ArrayList<List<String>>(); recordToAdd.add(headerRow); recordToAdd.add(download); recordToAdd.add(upload); CreateExcelFile(headerRow, download, upload); createExcelFile(); } void createExcelFile() { FileOutputStream fos = null; try { fos = new FileOutputStream(new File("E:\\report\\Download&Upload.xls")); HSSFCellStyle hsfstyle = workbook.createCellStyle(); hsfstyle.setBorderBottom((short) 1); hsfstyle.setFillBackgroundColor((short) 245); workbook.write(fos); } catch (Exception e) { } } public void CreateExcelFile(List<String> headers, List<String> down, List<String> up) throws Exception { try { Row row = firstSheet.createRow((short)(rownum++)); for(int i = 0;i < headers.size();i++) { Cell cell = row.createCell(i); cell.setCellValue(headers.get(i)); } for (int j = 0; j < down.size(); j++) { row = firstSheet.createRow((short)(rownum++)); Cell cell = row.createCell(0); cell.setCellValue(down.get(j)); if(up.size() > j) { cell = row.createCell(1); cell.setCellValue(up.get(j)); } } } catch (Exception e) { } finally { } } } cell = row.createCell (1); public class F { static List<String> downloadList = new ArrayList<>(); static List<String> dispatchList = new ArrayList<>(); public static class FileVisitor extends SimpleFileVisitor<Path> { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String name = file.toRealPath().getFileName().toString(); if (name.endsWith(".pdf") || name.endsWith(".zip")) { downloadList.add(name); } if (name.endsWith(".xml")) { dispatchList.add(name); } return FileVisitResult.CONTINUE; } } public static void main(String[] args) throws IOException { try { Path downloadPath = Paths.get("E:\\Download\\10292013"); Path dispatchPath = Paths.get("E:\\Dispatch\\10292013"); FileVisitor visitor = new FileVisitor(); Files.walkFileTree(downloadPath, visitor); Files.walkFileTree(downloadPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, visitor); Files.walkFileTree(dispatchPath, visitor); Files.walkFileTree(dispatchPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, visitor); /* List all files*/ System.out.println("Download File List" + downloadList); System.out.println("Dispatch File List" + dispatchList); F f = new F(); f.UpDown(downloadList, dispatchList); } catch (Exception ex) { Logger.getLogger(F.class.getName()).log(Level.SEVERE, null, ex); } } int rownum = 0; int colnum = 0; HSSFSheet firstSheet; Collection<File> files; HSSFWorkbook workbook; File exactFile; { workbook = new HSSFWorkbook(); firstSheet = workbook.createSheet("10292013"); Row headerRow = firstSheet.createRow(rownum); headerRow.setHeightInPoints(40); } public void UpDown(List<String> download, List<String> upload) throws Exception { List<String> headerRow = new ArrayList<String>(); headerRow.add("Downloaded"); headerRow.add("Uploaded"); List<List<String>> recordToAdd = new ArrayList<List<String>>(); recordToAdd.add(headerRow); recordToAdd.add(download); recordToAdd.add(upload); CreateExcelFile(headerRow, download, upload); createExcelFile(); } void createExcelFile() { FileOutputStream fos = null; try { fos = new FileOutputStream(new File("E:\\report\\Download&Upload.xls")); HSSFCellStyle hsfstyle = workbook.createCellStyle(); hsfstyle.setBorderBottom((short) 1); hsfstyle.setFillBackgroundColor((short) 245); workbook.write(fos); } catch (Exception e) { } } public void CreateExcelFile(List<String> headers, List<String> down, List<String> up) throws Exception { try { Row row = firstSheet.createRow((short)(rownum++)); for(int i = 0;i < headers.size();i++) { Cell cell = row.createCell(i); cell.setCellValue(headers.get(i)); } for (int j = 0; j < down.size(); j++) { row = firstSheet.createRow((short)(rownum++)); Cell cell = row.createCell(0); cell.setCellValue(down.get(j)); if(up.size() > j) { cell = row.createCell(1); cell.setCellValue(up.get(j)); } } } catch (Exception e) { } finally { } } } } catch (Eccezione e) { public class F { static List<String> downloadList = new ArrayList<>(); static List<String> dispatchList = new ArrayList<>(); public static class FileVisitor extends SimpleFileVisitor<Path> { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String name = file.toRealPath().getFileName().toString(); if (name.endsWith(".pdf") || name.endsWith(".zip")) { downloadList.add(name); } if (name.endsWith(".xml")) { dispatchList.add(name); } return FileVisitResult.CONTINUE; } } public static void main(String[] args) throws IOException { try { Path downloadPath = Paths.get("E:\\Download\\10292013"); Path dispatchPath = Paths.get("E:\\Dispatch\\10292013"); FileVisitor visitor = new FileVisitor(); Files.walkFileTree(downloadPath, visitor); Files.walkFileTree(downloadPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, visitor); Files.walkFileTree(dispatchPath, visitor); Files.walkFileTree(dispatchPath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, visitor); /* List all files*/ System.out.println("Download File List" + downloadList); System.out.println("Dispatch File List" + dispatchList); F f = new F(); f.UpDown(downloadList, dispatchList); } catch (Exception ex) { Logger.getLogger(F.class.getName()).log(Level.SEVERE, null, ex); } } int rownum = 0; int colnum = 0; HSSFSheet firstSheet; Collection<File> files; HSSFWorkbook workbook; File exactFile; { workbook = new HSSFWorkbook(); firstSheet = workbook.createSheet("10292013"); Row headerRow = firstSheet.createRow(rownum); headerRow.setHeightInPoints(40); } public void UpDown(List<String> download, List<String> upload) throws Exception { List<String> headerRow = new ArrayList<String>(); headerRow.add("Downloaded"); headerRow.add("Uploaded"); List<List<String>> recordToAdd = new ArrayList<List<String>>(); recordToAdd.add(headerRow); recordToAdd.add(download); recordToAdd.add(upload); CreateExcelFile(headerRow, download, upload); createExcelFile(); } void createExcelFile() { FileOutputStream fos = null; try { fos = new FileOutputStream(new File("E:\\report\\Download&Upload.xls")); HSSFCellStyle hsfstyle = workbook.createCellStyle(); hsfstyle.setBorderBottom((short) 1); hsfstyle.setFillBackgroundColor((short) 245); workbook.write(fos); } catch (Exception e) { } } public void CreateExcelFile(List<String> headers, List<String> down, List<String> up) throws Exception { try { Row row = firstSheet.createRow((short)(rownum++)); for(int i = 0;i < headers.size();i++) { Cell cell = row.createCell(i); cell.setCellValue(headers.get(i)); } for (int j = 0; j < down.size(); j++) { row = firstSheet.createRow((short)(rownum++)); Cell cell = row.createCell(0); cell.setCellValue(down.get(j)); if(up.size() > j) { cell = row.createCell(1); cell.setCellValue(up.get(j)); } } } catch (Exception e) { } finally { } } }