Example usage for org.apache.poi.hssf.usermodel HSSFWorkbook HSSFWorkbook

List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook HSSFWorkbook

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFWorkbook HSSFWorkbook.

Prototype

public HSSFWorkbook() 

Source Link

Document

Creates new HSSFWorkbook from scratch (start here!)

Usage

From source file:com.github.wnameless.workbookaccessor.WorkbookReaderTest.java

License:Apache License

@Test
public void testConstructor() {
    assertTrue(reader instanceof WorkbookReader);
    assertTrue(readerNH instanceof WorkbookReader);
    assertTrue(new WorkbookReader(new File(BASE_DIR + "PII_20130328154417.xls")) instanceof WorkbookReader);
    Workbook wb = new HSSFWorkbook();
    wb.createSheet();//from   w  w  w.jav a  2  s .com
    assertTrue(new WorkbookReader(wb) instanceof WorkbookReader);
    assertTrue(WorkbookReader.open(wb) instanceof WorkbookReader);
    assertTrue(WorkbookReader.open(new File(BASE_DIR + "PII_20130328154417.xls")) instanceof WorkbookReader);
    assertTrue(WorkbookReader.open(BASE_DIR + "PII_20130328154417.xls") instanceof WorkbookReader);
}

From source file:com.github.wnameless.workbookaccessor.WorkbookWriter.java

License:Apache License

/**
 * Creates a {@link WorkbookWriter}. Default sheet name is Sheet0 and XLS
 * format is used./* w  w  w  .java  2  s  .  c  o m*/
 */
public WorkbookWriter() {
    workbook = new HSSFWorkbook();
    sheet = workbook.createSheet();
}

From source file:com.github.wnameless.workbookaccessor.WorkbookWriter.java

License:Apache License

private WorkbookWriter(boolean xlsx) {
    workbook = xlsx ? new XSSFWorkbook() : new HSSFWorkbook();
    sheet = workbook.createSheet();
}

From source file:com.github.wnameless.workbookaccessor.WorkbookWriterTest.java

License:Apache License

@Test
public void testConstructor() {
    assertTrue(writer instanceof WorkbookWriter);
    assertTrue(new WorkbookWriter(new HSSFWorkbook()) instanceof WorkbookWriter);
    Workbook wb = new HSSFWorkbook();
    wb.createSheet();/*from  ww  w.ja  v a2  s  .  co  m*/
    assertTrue(new WorkbookWriter(wb) instanceof WorkbookWriter);
    assertTrue(WorkbookWriter.open(wb) instanceof WorkbookWriter);
    assertTrue(WorkbookWriter.openXLSX() instanceof WorkbookWriter);
    assertTrue(WorkbookWriter.openXLS() instanceof WorkbookWriter);
}

From source file:com.github.wnameless.workbookaccessor.WorkbookWriterTest.java

License:Apache License

@Test
public void testAddRow() {
    Calendar cal = Calendar.getInstance();
    Date date = new Date();
    writer.addRow("def");
    writer.addRow(null, true, cal, date, 1.1, new HSSFRichTextString("Hello!"),
            new XSSFRichTextString("World."),
            new HSSFWorkbook().getCreationHelper().createHyperlink(Hyperlink.LINK_URL), 123, "abc");
    assertEquals("def",
            writer.getWorkbook().getSheetAt(0).rowIterator().next().cellIterator().next().getStringCellValue());
    WorkbookWriter.openXLSX().addRow(new HSSFRichTextString("Hello!"), new XSSFRichTextString("World."));
    WorkbookWriter.openXLS().addRow(new HSSFRichTextString("Hello!"), new XSSFRichTextString("World."));

}

From source file:com.grant.data.ItemDAO.java

public List getAllItemOutReport() throws FileNotFoundException, IOException {

    ResultSet rs = null;//w w  w .j a  v  a 2s  .  c o m
    Connection dbConn = null;
    List ss = null;

    try {
        dbConn = dbConnManager.connect();

        Statement stmt = dbConn.createStatement();

        String query = "SELECT * FROM grant_item_out";
        //String query = "INSERT INTO grant_item_out(v_item_name,v_item_no,v_ref_code,v_descrip,v_invo_no,i_outwards,i_balance,d_in_date)  " + "VALUES( '" + itemName + "','" + itemNo + "','" + refCode +  "','"+ description + "','" + invoiceNo + "','" + outwards + "','" + balance +  "','"+ itemInDate + "'" + ")";

        System.out.println(query);

        rs = stmt.executeQuery(query);

        /////////////
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("lawix10");
        HSSFRow rowhead = sheet.createRow((short) 0);
        rowhead.createCell((short) 0).setCellValue("CellHeadName1");
        rowhead.createCell((short) 1).setCellValue("CellHeadName2");
        rowhead.createCell((short) 2).setCellValue("CellHeadName3");
        int i = 1;
        while (rs.next()) {
            HSSFRow row = sheet.createRow((short) i);
            // row.createCell((short) 0).setCellValue(Integer.toString(rs.getInt("column1")));
            row.createCell((short) 1).setCellValue(rs.getString(1));
            row.createCell((short) 2).setCellValue(rs.getString(2));
            i++;
        }
        String yemi = "C:/Users/Isura Amarasinghe/Desktop/test.xls";
        //C:/Users/Isura Amarasinghe/Desktop
        FileOutputStream fileOut = new FileOutputStream(yemi);
        workbook.write(fileOut);
        fileOut.close();
        ///////////

    } catch (SQLException sQLException) {

        System.out.println(sQLException + "-----------Insert query failed-------");

        rs = null;
    } finally {
        dbConnManager.con_close(dbConn);
    }
    return ss;
}

From source file:com.grant.data.ItemDAO.java

public boolean getStockINReport(ReportICatogory rrc) throws FileNotFoundException, IOException {

    ResultSet rs = null;/*from  w  ww  . ja va  2 s  .com*/
    Connection dbConn = null;
    boolean ss = false;

    try {
        dbConn = dbConnManager.connect();

        Statement stmt = dbConn.createStatement();
        String query = "SELECT * FROM grant_item_in WHERE d_in_date BETWEEN '" + rrc.getItemIDateStart()
                + "' AND '" + rrc.getItemInDateEnd() + "'";
        System.out.println(query);

        rs = stmt.executeQuery(query);
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("lawix10");
        HSSFRow rowhead = sheet.createRow((short) 0);

        rowhead.createCell((short) 1).setCellValue("Item ID");
        rowhead.createCell((short) 2).setCellValue("v_item_name");
        rowhead.createCell((short) 3).setCellValue("v_item_no");
        rowhead.createCell((short) 4).setCellValue("v_descrip");
        rowhead.createCell((short) 5).setCellValue("i_inwards");
        rowhead.createCell((short) 6).setCellValue("i_balance");
        rowhead.createCell((short) 7).setCellValue("v_type");
        rowhead.createCell((short) 8).setCellValue("d_in_date");
        rowhead.createCell((short) 9).setCellValue("i_unit_price");

        int i = 1;
        while (rs.next()) {
            HSSFRow row = sheet.createRow((short) i);
            //row.createCell((short) 0).setCellValue(Integer.toString(rs.getInt(0)));
            row.createCell((short) 1).setCellValue(rs.getString(1));
            row.createCell((short) 2).setCellValue(rs.getString(2));
            row.createCell((short) 3).setCellValue(rs.getString(3));
            row.createCell((short) 4).setCellValue(rs.getString(4));
            row.createCell((short) 5).setCellValue(rs.getString(5));
            row.createCell((short) 6).setCellValue(rs.getString(6));
            row.createCell((short) 7).setCellValue(rs.getString(7));
            row.createCell((short) 8).setCellValue(rs.getString(8));
            row.createCell((short) 9).setCellValue(rs.getString(9));

            i++;
        }

        FileDateTime fileDateTime = new FileDateTime();
        FileOutputStream fileOut = new FileOutputStream(fileDateTime.getFileName("Stock_In"));
        workbook.write(fileOut);
        ss = true;
    } catch (SQLException sQLException) {
        ss = false;
        System.out.println(sQLException + "-----------Insert query failed-------");
        rs = null;
    } finally {
        dbConnManager.con_close(dbConn);
    }
    return ss;
}

From source file:com.grant.data.ItemDAO.java

public boolean getStockOutReport(ReportICatogory ric) throws FileNotFoundException, IOException {

    ResultSet rs = null;/*from  w ww  . j av  a 2  s.  c  o m*/
    Connection dbConn = null;
    boolean ss = false;

    try {
        dbConn = dbConnManager.connect();

        Statement stmt = dbConn.createStatement();

        String query = "SELECT * FROM grant_item_print WHERE d_in_date BETWEEN '" + ric.getItemIDateStart()
                + "' AND '" + ric.getItemInDateEnd() + "'";

        System.out.println(query);

        rs = stmt.executeQuery(query);

        /////////////
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("lawix10");
        HSSFRow rowhead = sheet.createRow((short) 0);
        //rowhead.createCell((short) 0).setCellValue("Item ID");

        rowhead.createCell((short) 1).setCellValue("i_itin_id");
        rowhead.createCell((short) 2).setCellValue("v_item_name");
        rowhead.createCell((short) 3).setCellValue("v_item_no");
        rowhead.createCell((short) 4).setCellValue("v_ref_code");
        rowhead.createCell((short) 5).setCellValue("v_descrip");
        rowhead.createCell((short) 6).setCellValue("v_invo_no");
        rowhead.createCell((short) 7).setCellValue("i_outwards");
        rowhead.createCell((short) 8).setCellValue("v_outtype");
        rowhead.createCell((short) 9).setCellValue("i_balance");
        rowhead.createCell((short) 10).setCellValue("i_unit_price");
        rowhead.createCell((short) 11).setCellValue("i_amount");
        rowhead.createCell((short) 12).setCellValue("i_sub_total");
        rowhead.createCell((short) 13).setCellValue("i_discount");
        rowhead.createCell((short) 14).setCellValue("i_total");
        rowhead.createCell((short) 15).setCellValue("d_in_date");
        rowhead.createCell((short) 16).setCellValue("v_cus_name");
        rowhead.createCell((short) 17).setCellValue("v_address");
        rowhead.createCell((short) 18).setCellValue("v_payType");
        rowhead.createCell((short) 19).setCellValue("v_no");
        rowhead.createCell((short) 20).setCellValue("v_order_no");

        int i = 1;
        while (rs.next()) {
            HSSFRow row = sheet.createRow((short) i);
            //row.createCell((short) 0).setCellValue(Integer.toString(rs.getInt(0)));
            row.createCell((short) 1).setCellValue(rs.getString(1));
            row.createCell((short) 2).setCellValue(rs.getString(2));
            row.createCell((short) 3).setCellValue(rs.getString(3));
            row.createCell((short) 4).setCellValue(rs.getString(4));
            row.createCell((short) 5).setCellValue(rs.getString(5));
            row.createCell((short) 6).setCellValue(rs.getString(6));
            row.createCell((short) 7).setCellValue(rs.getString(7));
            row.createCell((short) 8).setCellValue(rs.getString(8));
            row.createCell((short) 9).setCellValue(rs.getString(9));
            row.createCell((short) 10).setCellValue(rs.getString(10));
            row.createCell((short) 11).setCellValue(rs.getString(11));
            row.createCell((short) 12).setCellValue(rs.getString(12));
            row.createCell((short) 13).setCellValue(rs.getString(13));
            row.createCell((short) 14).setCellValue(rs.getString(14));
            row.createCell((short) 15).setCellValue(rs.getString(15));
            row.createCell((short) 16).setCellValue(rs.getString(16));
            row.createCell((short) 17).setCellValue(rs.getString(17));
            row.createCell((short) 18).setCellValue(rs.getString(18));
            row.createCell((short) 19).setCellValue(rs.getString(19));
            row.createCell((short) 20).setCellValue(rs.getString(20));
            i++;
        }

        FileDateTime fileDateTime = new FileDateTime();
        FileOutputStream fileOut = new FileOutputStream(fileDateTime.getFileName("Stock_Out"));
        workbook.write(fileOut);
        fileOut.close();
        ss = true;

    } catch (SQLException sQLException) {
        ss = false;
        System.out.println(sQLException + "-----------Insert query failed-------");

        rs = null;
    } finally {
        dbConnManager.con_close(dbConn);
    }
    return ss;
}

From source file:com.grant.data.ItemDAO.java

public List getItemCatogaryReport(ReportICatogory ric) throws FileNotFoundException, IOException {

    ResultSet rs = null;/*from w  w  w.  j  a  v  a  2  s .  c o  m*/
    Connection dbConn = null;
    List ss = null;

    try {
        dbConn = dbConnManager.connect();

        Statement stmt = dbConn.createStatement();

        String query = "SELECT * FROM grant_item_out WHERE d_in_date BETWEEN '" + ric.getItemIDateStart()
                + "' AND '" + ric.getItemInDateEnd() + "' AND v_item_name = '" + ric.getItemName() + "'";
        //SELECT * FROM grant_item_out WHERE d_in_date BETWEEN '2016-01-07' AND '2016-01-08' AND v_item_name = 'Item 1 chm'
        //String query = "INSERT INTO grant_item_out(v_item_name,v_item_no,v_ref_code,v_descrip,v_invo_no,i_outwards,i_balance,d_in_date)  " + "VALUES( '" + itemName + "','" + itemNo + "','" + refCode +  "','"+ description + "','" + invoiceNo + "','" + outwards + "','" + balance +  "','"+ itemInDate + "'" + ")";

        System.out.println(query);

        rs = stmt.executeQuery(query);

        /////////////
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("lawix10");
        HSSFRow rowhead = sheet.createRow((short) 0);
        //rowhead.createCell((short) 0).setCellValue("Item ID");
        rowhead.createCell((short) 1).setCellValue("i_itin_id");
        rowhead.createCell((short) 2).setCellValue("v_item_name");
        rowhead.createCell((short) 3).setCellValue("v_item_no");
        rowhead.createCell((short) 4).setCellValue("v_ref_code");
        rowhead.createCell((short) 5).setCellValue("v_descrip");
        rowhead.createCell((short) 6).setCellValue("v_invo_no");
        rowhead.createCell((short) 7).setCellValue("i_outwards");
        rowhead.createCell((short) 8).setCellValue("v_outtype");
        rowhead.createCell((short) 9).setCellValue("i_balance");
        rowhead.createCell((short) 10).setCellValue("i_unit_price");
        rowhead.createCell((short) 11).setCellValue("i_amount");
        rowhead.createCell((short) 12).setCellValue("i_sub_total");
        rowhead.createCell((short) 13).setCellValue("i_discount");
        rowhead.createCell((short) 14).setCellValue("i_total");
        rowhead.createCell((short) 15).setCellValue("d_in_date");
        rowhead.createCell((short) 16).setCellValue("v_cus_name");
        rowhead.createCell((short) 17).setCellValue("v_address");
        rowhead.createCell((short) 18).setCellValue("v_payType");
        rowhead.createCell((short) 19).setCellValue("v_no");
        rowhead.createCell((short) 20).setCellValue("v_order_no");
        int i = 1;
        while (rs.next()) {
            HSSFRow row = sheet.createRow((short) i);
            //row.createCell((short) 0).setCellValue(Integer.toString(rs.getInt(0)));
            row.createCell((short) 1).setCellValue(rs.getString(1));
            row.createCell((short) 2).setCellValue(rs.getString(2));
            row.createCell((short) 3).setCellValue(rs.getString(3));
            row.createCell((short) 4).setCellValue(rs.getString(4));
            row.createCell((short) 5).setCellValue(rs.getString(5));
            row.createCell((short) 6).setCellValue(rs.getString(6));
            row.createCell((short) 7).setCellValue(rs.getString(7));
            row.createCell((short) 8).setCellValue(rs.getString(8));
            row.createCell((short) 9).setCellValue(rs.getString(9));
            row.createCell((short) 10).setCellValue(rs.getString(10));
            row.createCell((short) 11).setCellValue(rs.getString(11));
            row.createCell((short) 12).setCellValue(rs.getString(12));
            row.createCell((short) 13).setCellValue(rs.getString(13));
            row.createCell((short) 14).setCellValue(rs.getString(14));
            row.createCell((short) 15).setCellValue(rs.getString(15));
            row.createCell((short) 16).setCellValue(rs.getString(16));
            row.createCell((short) 17).setCellValue(rs.getString(17));
            row.createCell((short) 18).setCellValue(rs.getString(18));
            row.createCell((short) 19).setCellValue(rs.getString(19));
            row.createCell((short) 20).setCellValue(rs.getString(20));
            i++;
        }
        String yemi = "C:/Users/Isura Amarasinghe/Desktop/test.xls";
        //C:/Users/Isura Amarasinghe/Desktop
        FileOutputStream fileOut = new FileOutputStream(yemi);
        workbook.write(fileOut);
        fileOut.close();
        ///////////

    } catch (SQLException sQLException) {

        System.out.println(sQLException + "-----------Insert query failed-------");

        rs = null;
    } finally {
        dbConnManager.con_close(dbConn);
    }
    return ss;
}

From source file:com.grant.data.ItemDAO.java

public List getRefPerfReport(ReportRefCode rrc) throws FileNotFoundException, IOException {

    ResultSet rs = null;/*from  www. jav  a  2s  .c o m*/
    Connection dbConn = null;
    List ss = null;

    try {
        dbConn = dbConnManager.connect();

        Statement stmt = dbConn.createStatement();

        String query = "SELECT * FROM grant_item_out WHERE d_in_date BETWEEN '" + rrc.getItemIDateStart()
                + "' AND '" + rrc.getItemInDateEnd() + "' AND v_ref_code = '" + rrc.getRefCode() + "'";
        //SELECT * FROM grant_item_out WHERE d_in_date BETWEEN '2016-01-07' AND '2016-01-08' AND v_item_name = 'Item 1 chm'
        //String query = "INSERT INTO grant_item_out(v_item_name,v_item_no,v_ref_code,v_descrip,v_invo_no,i_outwards,i_balance,d_in_date)  " + "VALUES( '" + itemName + "','" + itemNo + "','" + refCode +  "','"+ description + "','" + invoiceNo + "','" + outwards + "','" + balance +  "','"+ itemInDate + "'" + ")";

        System.out.println(query);

        rs = stmt.executeQuery(query);

        /////////////
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("lawix10");
        HSSFRow rowhead = sheet.createRow((short) 0);
        //rowhead.createCell((short) 0).setCellValue("Item ID");
        rowhead.createCell((short) 1).setCellValue("i_itin_id");
        rowhead.createCell((short) 2).setCellValue("v_item_name");
        rowhead.createCell((short) 3).setCellValue("v_item_no");
        rowhead.createCell((short) 4).setCellValue("v_ref_code");
        rowhead.createCell((short) 5).setCellValue("v_descrip");
        rowhead.createCell((short) 6).setCellValue("v_invo_no");
        rowhead.createCell((short) 7).setCellValue("i_outwards");
        rowhead.createCell((short) 8).setCellValue("v_outtype");
        rowhead.createCell((short) 9).setCellValue("i_balance");
        rowhead.createCell((short) 10).setCellValue("i_unit_price");
        rowhead.createCell((short) 11).setCellValue("i_amount");
        rowhead.createCell((short) 12).setCellValue("i_sub_total");
        rowhead.createCell((short) 13).setCellValue("i_discount");
        rowhead.createCell((short) 14).setCellValue("i_total");
        rowhead.createCell((short) 15).setCellValue("d_in_date");
        rowhead.createCell((short) 16).setCellValue("v_cus_name");
        rowhead.createCell((short) 17).setCellValue("v_address");
        rowhead.createCell((short) 18).setCellValue("v_payType");
        rowhead.createCell((short) 19).setCellValue("v_no");
        rowhead.createCell((short) 20).setCellValue("v_order_no");
        int i = 1;
        while (rs.next()) {
            HSSFRow row = sheet.createRow((short) i);
            //row.createCell((short) 0).setCellValue(Integer.toString(rs.getInt(0)));
            row.createCell((short) 1).setCellValue(rs.getString(1));
            row.createCell((short) 2).setCellValue(rs.getString(2));
            row.createCell((short) 3).setCellValue(rs.getString(3));
            row.createCell((short) 4).setCellValue(rs.getString(4));
            row.createCell((short) 5).setCellValue(rs.getString(5));
            row.createCell((short) 6).setCellValue(rs.getString(6));
            row.createCell((short) 7).setCellValue(rs.getString(7));
            row.createCell((short) 8).setCellValue(rs.getString(8));
            row.createCell((short) 9).setCellValue(rs.getString(9));
            row.createCell((short) 10).setCellValue(rs.getString(10));
            row.createCell((short) 11).setCellValue(rs.getString(11));
            row.createCell((short) 12).setCellValue(rs.getString(12));
            row.createCell((short) 13).setCellValue(rs.getString(13));
            row.createCell((short) 14).setCellValue(rs.getString(14));
            row.createCell((short) 15).setCellValue(rs.getString(15));
            row.createCell((short) 16).setCellValue(rs.getString(16));
            row.createCell((short) 17).setCellValue(rs.getString(17));
            row.createCell((short) 18).setCellValue(rs.getString(18));
            row.createCell((short) 19).setCellValue(rs.getString(19));
            row.createCell((short) 20).setCellValue(rs.getString(20));
            i++;
        }
        String yemi = "C:/Users/Isura Amarasinghe/Desktop/ref.xls";
        //C:/Users/Isura Amarasinghe/Desktop
        FileOutputStream fileOut = new FileOutputStream(yemi);
        workbook.write(fileOut);
        fileOut.close();
        ///////////

    } catch (SQLException sQLException) {

        System.out.println(sQLException + "-----------Insert query failed-------");

        rs = null;
    } finally {
        dbConnManager.con_close(dbConn);
    }
    return ss;
}