cl.a2r.wsmicampov2.common.utils.Excel.java Source code

Java tutorial

Introduction

Here is the source code for cl.a2r.wsmicampov2.common.utils.Excel.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cl.a2r.wsmicampov2.common.utils;

import cl.a2r.wsmicampov2.common.AppLog;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 *
 * @author Elaine
 */
public class Excel {

    public static void GenerateExcel(String fileUrl, String sheetName, List<Integer> dataList) {

        File archivo = new File(fileUrl);
        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet(sheetName);

        int rowNum = 1;
        for (Integer data : dataList) {

            Row row = sheet.createRow(rowNum++);

            row.createCell(0).setCellValue(data);
        }
        try {
            FileOutputStream salida = new FileOutputStream(archivo);
            workbook.write(salida);
            workbook.close();

        } catch (FileNotFoundException ex) {
            AppLog.logInfo(ex.getMessage(), ex);

        } catch (IOException ex) {
            AppLog.logInfo(ex.getMessage(), ex);
        } catch (Exception ex) {
            AppLog.logInfo(ex.getMessage(), ex);

        }

    }

}