org.riflemansd.businessprofit.excel.ExcelExamplePOI.java Source code

Java tutorial

Introduction

Here is the source code for org.riflemansd.businessprofit.excel.ExcelExamplePOI.java

Source

/* ~~ The ExcelExamplePOI is part of BusinessProfit. ~~
 * 
 * The BusinessProfit's classes and any part of the code 
 * cannot be copied/distributed without 
 * the permission of Sotiris Doudis
 * 
 * Github - RiflemanSD - https://github.com/RiflemanSD
 * 
 * Copyright  2016 Sotiris Doudis | All rights reserved
 * 
 * License for BusinessProfit project - in GREEK language
 * 
 *  ?  ?  ??  ?  ?. 
 *  o??      ??  ?.
 * 
 * A??  ?    ?   ? 
 *    ??. 
 *  ?    ?    ?  .
 * ?  ?  header    ?  link 
 *   ( github).
 * 
 * ~~ Information about BusinessProfit project - in GREEK language ~~
 *  
 *  BusinessProfit   project     ?
 *  /  ?    ?  ?  ? 
 *  ? ?  ?.    ?  
 *       ? ..
 *  
 *  project ?   ? ?.  ??  ..
 *  ? ?.        ?.
 * 
 *  project ??  Java (https://www.java.com/en/download/).
 *  ?  NetBeans IDE (https://netbeans.org/)
 *    ? ?     java.
 *  
 *   ? ?  ?  project .   ?
 *  ?/  , ?    ?? (  License).
 * 
 * Github - https://github.com/RiflemanSD/BusinessProfit
 * 
 * 
 * Copyright  2016 Sotiris Doudis | All rights reserved
 */
package org.riflemansd.businessprofit.excel;

import java.awt.Desktop;
import java.io.File;
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.xssf.streaming.SXSSFWorkbook;

/** <h1>ExcelExamplePOI</h1>
 * 
 * <p></p>
 * 
 * <p>Last Update: 29/01/2016</p>
 * <p>Author: <a href=https://github.com/RiflemanSD>RiflemanSD</a></p>
 * 
 * <p>Copyright  2016 Sotiris Doudis | All rights reserved</p>
 * 
 * @version 1.0.7
 * @author RiflemanSD
 */
public class ExcelExamplePOI {

    public static void main(String[] args) throws Throwable {
        SXSSFWorkbook wb = new SXSSFWorkbook(1000); // keep 100 rows in memory, exceeding rows will be flushed to disk

        if (wb.getNumberOfSheets() == 0) {
            wb.createSheet("MySheet");
        }
        Sheet sh = wb.getSheetAt(0);
        Row row = sh.createRow(3);

        for (int i = 0; i < 10; i++) {
            Cell cell = row.createCell(i);
            //String address = new CellReference(cell).formatAsString();
            cell.setCellValue("? " + i);
            //row.setHeightInPoints(50);
            //sh.setColumnWidth(5, 1200); //4, 33 pixels
            wb.getSheetAt(0).autoSizeColumn(i);
        }

        FileOutputStream out = new FileOutputStream("test.xlsx");
        wb.write(out);
        out.close();

        // dispose of temporary files backing this workbook on disk
        wb.dispose();

        Desktop.getDesktop().open(new File("test.xlsx"));
    }
}