コード例 #1
0
 private static void populateDataToWorkSheet(
     CreateCSVFile csvFile, HSSFSheet workSheet, Map<String, Object[]> data) {
   Set<String> keySet = data.keySet();
   HSSFRow row1 = csvFile.createRow(workSheet, 0);
   Object[] objects1 = new String[] {"ID", "NAME", "LAST NAME", "", ""};
   int cellNum1 = 0;
   for (Object object : objects1) {
     csvFile.createHeader(row1, object, cellNum1++);
   }
   int rowNum = 1;
   for (String header : keySet) {
     HSSFRow row = csvFile.createRow(workSheet, rowNum++);
     Object[] objects = data.get(header);
     int cellNum = 0;
     for (Object object : objects) {
       csvFile.createCell(row, object, cellNum++);
     }
   }
 }
コード例 #2
0
 public static void main(String[] args) {
   CreateCSVFile csvFile = new CreateCSVFile();
   HSSFWorkbook workBook = csvFile.createWorkBook();
   HSSFSheet workSheet = csvFile.createWorkSheet(workBook);
   Map<String, Object[]> data = csvFile.getData();
   csvFile.createStyles(workBook, workSheet);
   populateDataToWorkSheet(csvFile, workSheet, data);
   csvFile.writeToFile(workBook);
 }