package poi;

import java.io.FileOutputStream;

import org.apache.poi.ss.usermodel.Cell;
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;

public class CreateExcelFile {
	//Q: Create a new excel sheet & write to it?
	public static void main(String[] args) {
		crateAndWriteToExcel();
	}

	
	//Create a new excel file and write to it
	static void crateAndWriteToExcel() {
		Workbook wb = null;
		Sheet sh = null;
		Row row = null;
		Cell cell = null;
		FileOutputStream fout = null;
		try {
			wb = new XSSFWorkbook(); //Creating new excel
			sh = wb.createSheet("TestData");
			
			row = sh.createRow(0);
			cell = row.createCell(0);
			cell.setCellValue("SG Testing Institute");
			cell = row.createCell(1);
			cell.setCellValue("Core Java");
			cell = row.createCell(2);
			cell.setCellValue("Good Morning");
			
			fout = new FileOutputStream("C:\\MorningBatch_Combined\\Sample.xlsx");
			wb.write(fout);
		}catch(Exception e) {
			e.printStackTrace();
		}
		finally
		{
			try {
				fout.flush();
				fout.close();
				fout = null;
				cell = null;
				row = null;
				sh = null;
				wb.close();
				wb = null;
			}catch(Exception e) {
				e.printStackTrace();
			}
		}
	}
}
