Example usage for org.apache.poi.ss.usermodel Sheet createRow

List of usage examples for org.apache.poi.ss.usermodel Sheet createRow

Introduction

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

Prototype

Row createRow(int rownum);

Source Link

Document

Create a new row within the sheet and return the high level representation

Usage

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

License:Open Source License

private void getXLSLine(final Workbook wb, final Sheet s, final KbartForm kbart, final short rownumber) {

    final Row row = s.createRow(rownumber);

    if (kbart.getPublication_title() != null) {
        row.createCell((short) 0).setCellValue(removeSpecialCharacters(kbart.getPublication_title()));
    } else {// w w  w .  j a  v a  2s .  c om
        row.createCell((short) 0).setCellValue("");
    }
    if (kbart.getPrint_identifier() != null) {
        row.createCell((short) 1).setCellValue(kbart.getPrint_identifier());
    } else {
        row.createCell((short) 1).setCellValue("");
    }
    if (kbart.getOnline_identifier() != null) {
        row.createCell((short) 2).setCellValue(kbart.getOnline_identifier());
    } else {
        row.createCell((short) 2).setCellValue("");
    }
    if (kbart.getDate_first_issue_online() != null) {
        row.createCell((short) 3).setCellValue(kbart.getDate_first_issue_online());
    } else {
        row.createCell((short) 3).setCellValue("");
    }
    if (kbart.getNum_first_vol_online() != null) {
        row.createCell((short) 4).setCellValue(kbart.getNum_first_vol_online());
    } else {
        row.createCell((short) 4).setCellValue("");
    }
    if (kbart.getNum_first_issue_online() != null) {
        row.createCell((short) 5).setCellValue(kbart.getNum_first_issue_online());
    } else {
        row.createCell((short) 5).setCellValue("");
    }
    if (kbart.getDate_last_issue_online() != null) {
        row.createCell((short) 6).setCellValue(kbart.getDate_last_issue_online());
    } else {
        row.createCell((short) 6).setCellValue("");
    }
    if (kbart.getNum_last_vol_online() != null) {
        row.createCell((short) 7).setCellValue(kbart.getNum_last_vol_online());
    } else {
        row.createCell((short) 7).setCellValue("");
    }
    if (kbart.getNum_last_issue_online() != null) {
        row.createCell((short) 8).setCellValue(kbart.getNum_last_issue_online());
    } else {
        row.createCell((short) 8).setCellValue("");
    }
    if (kbart.getTitle_url() != null) {
        row.createCell((short) 9).setCellValue(kbart.getTitle_url());
    } else {
        row.createCell((short) 9).setCellValue("");
    }
    if (kbart.getFirst_author() != null) {
        row.createCell((short) 10).setCellValue(removeSpecialCharacters(kbart.getFirst_author()));
    } else {
        row.createCell((short) 10).setCellValue("");
    }
    if (kbart.getTitle_id() != null) {
        row.createCell((short) 11).setCellValue(removeSpecialCharacters(kbart.getTitle_id()));
    } else {
        row.createCell((short) 11).setCellValue("");
    }
    if (kbart.getEmbargo_info() != null) {
        row.createCell((short) 12).setCellValue(removeSpecialCharacters(kbart.getEmbargo_info()));
    } else {
        row.createCell((short) 12).setCellValue("");
    }
    if (kbart.getCoverage_depth() != null) {
        row.createCell((short) 13).setCellValue(removeSpecialCharacters(kbart.getCoverage_depth()));
    } else {
        row.createCell((short) 13).setCellValue("");
    }
    if (kbart.getCoverage_notes() != null) {
        row.createCell((short) 14).setCellValue(removeSpecialCharacters(kbart.getCoverage_notes()));
    } else {
        row.createCell((short) 14).setCellValue("");
    }
    if (kbart.getPublisher_name() != null) {
        row.createCell((short) 15).setCellValue(removeSpecialCharacters(kbart.getPublisher_name()));
    } else {
        row.createCell((short) 15).setCellValue("");
    }

}

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.oakmountain.tpa.parser.TpaParser.java

License:Apache License

public void generateRequests(MacroscopicTopology macroscopicTopology, int requestsPerHour, int durationMinutes,
        int offset, String from, String to, Periodicity p) {
    String colLayoutString = getPropertyValue(tpaProps.REQUESTS_COL_LAYOUT);

    List<ColumnIdentifier> cols = new ArrayList<ColumnIdentifier>(requestsLayout.values().length);
    for (requestsLayout l : requestsLayout.values()) {
        cols.add(l);//w  w  w  . j a v  a 2  s  . c  om
    }
    Map<ColumnIdentifier, Integer> colLayoutMapping = getColLayoutMapping(colLayoutString, cols);

    int arrtimeColIndex = colLayoutMapping.get(requestsLayout.ARRTIME);
    int fromColIndex = colLayoutMapping.get(requestsLayout.FROM);
    int toColIndex = colLayoutMapping.get(requestsLayout.TO);
    int deptimeColIndex = colLayoutMapping.get(requestsLayout.DEPTIME);
    int idColIndex = colLayoutMapping.get(requestsLayout.ID);
    String requestedMarker = getPropertyValue(tpaProps.REQUESTS_REQUESTED_DAY_MARKER);

    List<String> linkNames = macroscopicTopology.getLinkNames();
    Sheet sheet = wb.getSheet(getPropertyValue(tpaProps.REQUESTS_WS_NAME));

    // header
    Row headerRow = sheet.createRow(0);
    for (ColumnIdentifier col : colLayoutMapping.keySet()) {
        int i = colLayoutMapping.get(col);
        Cell cell = headerRow.getCell(i, Row.CREATE_NULL_AS_BLANK);
        cell.setCellValue(col.name());
    }
    // train path slots hourly
    int k = 1;
    for (int i = 0; i < 24; i++) {
        for (int j = 0; j < requestsPerHour; j++) {
            Row row = sheet.createRow(sheet.getLastRowNum() + 1);
            int hour = i;
            int minutes = (offset + j * (60 / requestsPerHour)) % 60;
            double deptime = DateUtil
                    .convertTime(String.format("%02d", hour) + ":" + String.format("%02d", minutes));
            double arrtime = (deptime * 24 * 60 + durationMinutes) / (24 * 60);

            Cell cell = row.getCell(deptimeColIndex, Row.CREATE_NULL_AS_BLANK);
            cell.setCellStyle(timestyle);
            cell.setCellValue(deptime);
            cell = row.getCell(arrtimeColIndex, Row.CREATE_NULL_AS_BLANK);
            cell.setCellStyle(timestyle);
            cell.setCellValue(arrtime);

            row.getCell(fromColIndex, Row.CREATE_NULL_AS_BLANK).setCellValue(from);
            row.getCell(toColIndex, Row.CREATE_NULL_AS_BLANK).setCellValue(to);

            row.getCell(idColIndex, Row.CREATE_NULL_AS_BLANK)
                    .setCellValue(from + "_" + to + "_" + String.format("%03d", k));
            k++;

            // peridiocity
            for (Integer integer : p.getWeekDays()) {
                int weekdayColIndex = colLayoutMapping.get(requestsLayout.getWeekDayTrainPathLayout(integer));
                row.getCell(weekdayColIndex, Row.CREATE_NULL_AS_BLANK).setCellValue(requestedMarker);
            }
        }
    }
}

From source file:ch.oakmountain.tpa.parser.TpaParser.java

License:Apache License

public void addCatalogue(MacroscopicTopology macroscopicTopology, TrainPathSlotCatalogue catalogue) {
    String colLayoutString = getPropertyValue(tpaProps.TRAINPATHS_COL_LAYOUT);
    List<ColumnIdentifier> cols = new ArrayList<ColumnIdentifier>(trainPathLayout.values().length);
    for (trainPathLayout l : trainPathLayout.values()) {
        cols.add(l);// ww  w  .  j  a  va 2s .  c  o m
    }
    Map<ColumnIdentifier, Integer> colLayoutMapping = getColLayoutMapping(colLayoutString, cols);
    int deptimeColIndex = colLayoutMapping.get(trainPathLayout.DEPTIME);
    int arrtimeColIndex = colLayoutMapping.get(trainPathLayout.ARRTIME);
    int idColIndex = colLayoutMapping.get(trainPathLayout.ID);

    for (PeriodicalTrainPathSlot periodicalTrainPathSlot : catalogue.getTrainPathSlots()) {
        String linkName = periodicalTrainPathSlot.getTrainPathSectionName();

        // Create sheet if it does not exist yet
        if (wb.getSheet(linkName) == null) {
            Sheet sheet = wb.createSheet(linkName);
            // header
            Row headerRow = sheet.createRow(0);
            for (ColumnIdentifier col : colLayoutMapping.keySet()) {
                int i = colLayoutMapping.get(col);
                Cell cell = headerRow.getCell(i, Row.CREATE_NULL_AS_BLANK);
                cell.setCellValue(col.name());
            }
        }

        Sheet sheet = wb.getSheet(linkName);
        int rowNb;
        for (rowNb = 1; rowNb < sheet.getPhysicalNumberOfRows(); rowNb++) {
            if (sheet.getRow(rowNb) == null || StringUtils.isBlank(
                    getCellValueString(sheet.getRow(rowNb).getCell(idColIndex, Row.CREATE_NULL_AS_BLANK)))) {
                break;
            }
        }
        Row row = sheet.createRow(rowNb);

        TrainPathSlot slot = periodicalTrainPathSlot.getSlots().get(0);
        int depHour = slot.getStartTime().getHourOfDay();
        int depMinutes = slot.getStartTime().getMinuteOfHour();
        int arrHour = slot.getEndTime().getHourOfDay();
        int arrMinutes = slot.getEndTime().getMinuteOfHour();
        double deptime = DateUtil
                .convertTime(String.format("%02d", depHour) + ":" + String.format("%02d", depMinutes));
        double arrtime = DateUtil
                .convertTime(String.format("%02d", arrHour) + ":" + String.format("%02d", arrMinutes));

        Cell cell = row.getCell(deptimeColIndex, Row.CREATE_NULL_AS_BLANK);
        cell.setCellStyle(timestyle);
        cell.setCellValue(deptime);
        cell = row.getCell(arrtimeColIndex, Row.CREATE_NULL_AS_BLANK);
        cell.setCellStyle(timestyle);
        cell.setCellValue(arrtime);

        cell = row.getCell(idColIndex, Row.CREATE_NULL_AS_BLANK);
        cell.setCellValue(periodicalTrainPathSlot.getName());
    }
}

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);//from w  w w .  j  ava  2 s  .  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 testSetCurrentSheet() throws IOException {
    try (Workbook workbook = new XSSFWorkbook()) {
        // /* w  w w  . j a  va 2  s  . c  o m*/
        Sheet sheet0 = workbook.createSheet("CREATED 0");
        sheet0.createRow(0).createCell(0).setCellValue("CELL IN 0");
        Sheet sheet1 = workbook.createSheet("CREATED 1");
        sheet1.createRow(0).createCell(0).setCellValue("CELL IN 1");

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

            reader.setCurrentSheet(0);
            String[] r0 = reader.read();
            assertNotNull(r0);
            assertEquals(1, r0.length);
            assertEquals("CELL IN 0", r0[0]);
            assertNull(reader.read());

            reader.setCurrentSheet(1);
            String[] r1 = reader.read();
            assertNotNull(r1);
            assertEquals(1, r1.length);
            assertEquals("CELL IN 1", r1[0]);
            assertNull(reader.read());
        }
    }
}

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

License:Apache License

@Test
public void testRead_2_ROWS() throws IOException {
    try (Workbook workbook = new XSSFWorkbook()) {
        // //from  w w w .  j a va 2s  .  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()) {
        // /*  w  w  w.  ja v  a 2 s  .c om*/
        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()) {
        // //from w ww  .jav a  2s.com
        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 w ww  .  ja  v  a2s.c  o  m
        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());
        }
    }
}