Example usage for org.apache.poi.ss.usermodel Row createCell

List of usage examples for org.apache.poi.ss.usermodel Row createCell

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Row createCell.

Prototype

Cell createCell(int column);

Source Link

Document

Use this to create new cells within the row and return it.

Usage

From source file:ch.dbs.actions.reports.KbartReport.java

License:Open Source License

private void initXLS(final Workbook wb, final Sheet s) {

    final Row rowhead = s.createRow((short) 0);
    rowhead.createCell((short) 0).setCellValue("publication_title");
    rowhead.createCell((short) 1).setCellValue("print _identifier");
    rowhead.createCell((short) 2).setCellValue("online_identifier");
    rowhead.createCell((short) 3).setCellValue("date_first_issue_online");
    rowhead.createCell((short) 4).setCellValue("num_first_vol_online");
    rowhead.createCell((short) 5).setCellValue("num_first_issue_online");
    rowhead.createCell((short) 6).setCellValue("date_last_issue_online");
    rowhead.createCell((short) 7).setCellValue("num_last_vol_online");
    rowhead.createCell((short) 8).setCellValue("num_last_issue_online");
    rowhead.createCell((short) 9).setCellValue("title_url");
    rowhead.createCell((short) 10).setCellValue("first_author");
    rowhead.createCell((short) 11).setCellValue("title_id");
    rowhead.createCell((short) 12).setCellValue("embargo_info");
    rowhead.createCell((short) 13).setCellValue("coverage_depth");
    rowhead.createCell((short) 14).setCellValue("coverage_notes");
    rowhead.createCell((short) 15).setCellValue("publisher_name");

}

From source file:ch.scheduled.java

public void output() throws FileNotFoundException, IOException {
    Workbook wb = new HSSFWorkbook();
    Sheet sheet = wb.createSheet("Schedule");

    int count = 0;
    for (int i = 0; i < Courses.size(); ++i) {

        Course temp = Courses.get(i);// w  ww  . j  av  a2s.co  m
        if (temp.isScheduled() == true) {

            Row row = sheet.createRow((short) count);
            row.createCell(0).setCellValue(temp.getNumber());

            row.createCell(2).setCellValue(temp.getSession().getDay());
            row.createCell(3).setCellValue(temp.getSession().getSlot());
            ++count;
        }
    }
    FileOutputStream fileOut = new FileOutputStream("Final$Exam.xls");
    wb.write(fileOut);
    fileOut.close();
}

From source file:cherry.goods.excel.ExcelReaderTest.java

License:Apache License

@Test
public void testRead_2_ROWS() throws IOException {
    try (Workbook workbook = new XSSFWorkbook()) {
        // //w w  w . ja  v  a  2  s.  c o  m
        Sheet sheet = workbook.createSheet();
        Row row0 = sheet.createRow(0);
        row0.createCell(0).setCellValue("00");
        row0.createCell(1).setCellValue("01");
        Row row1 = sheet.createRow(1);
        row1.createCell(0).setCellValue("10");
        row1.createCell(1).setCellValue("11");
        row1.createCell(2).setCellValue("12");

        // 
        try (ExcelReader reader = new ExcelReader(workbook)) {

            String[] r0 = reader.read();
            assertNotNull(r0);
            assertEquals(2, r0.length);
            assertEquals("00", r0[0]);
            assertEquals("01", r0[1]);

            String[] r1 = reader.read();
            assertNotNull(r1);
            assertEquals(3, r1.length);
            assertEquals("10", r1[0]);
            assertEquals("11", r1[1]);
            assertEquals("12", r1[2]);

            assertNull(reader.read());
        }
    }
}

From source file:cherry.goods.excel.ExcelReaderTest.java

License:Apache License

@Test
public void testRead_3_ROWS_WITH_EMPTY_ROW() throws IOException {
    try (Workbook workbook = new XSSFWorkbook()) {
        // //ww  w  .ja  v  a2s. c  o  m
        Sheet sheet = workbook.createSheet();
        Row row0 = sheet.createRow(0);
        row0.createCell(0).setCellValue("00");
        row0.createCell(1).setCellValue("01");
        sheet.createRow(1);
        Row row2 = sheet.createRow(2);
        row2.createCell(0).setCellValue("20");
        row2.createCell(1).setCellValue("21");
        row2.createCell(2).setCellValue("22");

        // 
        try (ExcelReader reader = new ExcelReader(workbook)) {

            String[] r0 = reader.read();
            assertNotNull(r0);
            assertEquals(2, r0.length);
            assertEquals("00", r0[0]);
            assertEquals("01", r0[1]);

            String[] r1 = reader.read();
            assertNotNull(r1);
            assertEquals(0, r1.length);

            String[] r2 = reader.read();
            assertNotNull(r2);
            assertEquals(3, r2.length);
            assertEquals("20", r2[0]);
            assertEquals("21", r2[1]);
            assertEquals("22", r2[2]);

            assertNull(reader.read());
        }
    }
}

From source file:cherry.goods.excel.ExcelReaderTest.java

License:Apache License

@Test
public void testRead_NUMERIC() throws IOException {
    try (Workbook workbook = new XSSFWorkbook()) {
        // /*ww w  .ja v  a 2 s . c  om*/
        Sheet sheet = workbook.createSheet();
        Row row0 = sheet.createRow(0);
        row0.createCell(0).setCellValue(1234);
        row0.createCell(1).setCellValue(1234.56);

        // 
        try (ExcelReader reader = new ExcelReader(workbook)) {

            String[] r0 = reader.read();
            assertNotNull(r0);
            assertEquals(2, r0.length);
            assertEquals("1234", r0[0]);
            assertEquals("1234.56", r0[1]);

            assertNull(reader.read());
        }
    }
}

From source file:cherry.goods.excel.ExcelReaderTest.java

License:Apache License

@Test
public void testRead_STRING() throws IOException {
    try (Workbook workbook = new XSSFWorkbook()) {
        // /*from ww w .j a v  a2  s .  c  om*/
        Sheet sheet = workbook.createSheet();
        Row row0 = sheet.createRow(0);
        row0.createCell(0).setCellValue("CELL 00");
        row0.createCell(1).setCellValue("CELL 01");

        // 
        try (ExcelReader reader = new ExcelReader(workbook)) {

            String[] r0 = reader.read();
            assertNotNull(r0);
            assertEquals(2, r0.length);
            assertEquals("CELL 00", r0[0]);
            assertEquals("CELL 01", r0[1]);

            assertNull(reader.read());
        }
    }
}

From source file:cherry.goods.excel.ExcelReaderTest.java

License:Apache License

@Test
public void testRead_BLANK() throws IOException {
    try (Workbook workbook = new XSSFWorkbook()) {
        // /* ww w.  ja  v a 2s .  com*/
        Sheet sheet = workbook.createSheet();
        Row row0 = sheet.createRow(0);
        row0.createCell(0);
        row0.createCell(1);

        // 
        try (ExcelReader reader = new ExcelReader(workbook)) {

            String[] r0 = reader.read();
            assertNotNull(r0);
            assertEquals(2, r0.length);
            assertEquals("", r0[0]);
            assertEquals("", r0[1]);

            assertNull(reader.read());
        }
    }
}

From source file:cherry.goods.excel.ExcelReaderTest.java

License:Apache License

@Test
public void testRead_BOOLEAN() throws IOException {
    try (Workbook workbook = new XSSFWorkbook()) {
        // /*from   w  w  w  .  ja v a2s  . c om*/
        Sheet sheet = workbook.createSheet();
        Row row0 = sheet.createRow(0);
        row0.createCell(0).setCellValue(true);
        row0.createCell(1).setCellValue(false);

        // 
        try (ExcelReader reader = new ExcelReader(workbook)) {

            String[] r0 = reader.read();
            assertNotNull(r0);
            assertEquals(2, r0.length);
            assertEquals("true", r0[0]);
            assertEquals("false", r0[1]);

            assertNull(reader.read());
        }
    }
}

From source file:cherry.goods.excel.ExcelReaderTest.java

License:Apache License

@Test
public void testRead_ERROR() throws IOException {
    try (Workbook workbook = new XSSFWorkbook()) {
        // /*from  w ww.  j a v a 2  s .  c  o m*/
        Sheet sheet = workbook.createSheet();
        Row row0 = sheet.createRow(0);
        row0.createCell(0).setCellErrorValue((byte) 0);
        row0.createCell(1).setCellErrorValue((byte) 0);

        // 
        try (ExcelReader reader = new ExcelReader(workbook)) {

            String[] r0 = reader.read();
            assertNotNull(r0);
            assertEquals(2, r0.length);
            assertNull(r0[0]);
            assertNull(r0[1]);

            assertNull(reader.read());
        }
    }
}

From source file:cherry.goods.excel.ExcelReaderTest.java

License:Apache License

@Test
public void testRead_FORMULA_NUMERIC() throws IOException {
    try (Workbook workbook = new XSSFWorkbook()) {
        // /*  www  .j a  v a  2 s . c  o m*/
        Sheet sheet = workbook.createSheet();
        Row row0 = sheet.createRow(0);
        row0.createCell(0).setCellFormula("1200+34");
        row0.createCell(1).setCellFormula("1200+34.56");
        FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
        evaluator.evaluateAll();

        // 
        try (ExcelReader reader = new ExcelReader(workbook)) {

            String[] r0 = reader.read();
            assertNotNull(r0);
            assertEquals(2, r0.length);
            assertEquals("1234", r0[0]);
            assertEquals("1234.56", r0[1]);

            assertNull(reader.read());
        }
    }
}