Package org.apache.poi.xssf.usermodel

Examples of org.apache.poi.xssf.usermodel.XSSFRow


        
        importer.importFromXML(testXML);
        
        XSSFSheet sheet=wb.getSheetAt(0);
        
         XSSFRow rowHeadings = sheet.getRow(0);
         XSSFRow rowData = sheet.getRow(1);
        
         assertEquals("FirstName", rowHeadings.getCell(0).getStringCellValue());
         assertEquals("Albert", rowData.getCell(0).getStringCellValue());
        
         assertEquals("LastName", rowHeadings.getCell(1).getStringCellValue());
         assertEquals("Einstein", rowData.getCell(1).getStringCellValue());
        
         assertEquals("BirthDate", rowHeadings.getCell(2).getStringCellValue());
         assertEquals("1879-03-14", rowData.getCell(2).getStringCellValue());
        
         // Value for OptionalRating is declared optional (minOccurs=0) in 55864.xlsx
         assertEquals("OptionalRating", rowHeadings.getCell(3).getStringCellValue());
         assertNull("", rowData.getCell(3));
        } finally {
            wb.close();
        }
  }
View Full Code Here


                    String nodeXPath = commonXPath + "[" + (i + 1) + "]" + localXPath;

                    // TODO: convert the data to the cell format
                    String value = (String) xpath.evaluate(nodeXPath, result.item(i), XPathConstants.STRING);
                    logger.log(POILogger.DEBUG, "Extracting with xpath " + nodeXPath + " : value is '" + value + "'");
                    XSSFRow row = table.getXSSFSheet().getRow(rowId);
                    if (row == null) {
                        row = table.getXSSFSheet().createRow(rowId);
                    }

                    XSSFCell cell = row.getCell(columnId);
                    if (cell == null) {
                        cell = row.createCell(columnId);
                    }
                    logger.log(POILogger.DEBUG, "Setting '" + value + "' to cell " + cell.getColumnIndex() + "-" + cell.getRowIndex() + " in sheet "
                                                    + table.getXSSFSheet().getSheetName());
                    cell.setCellValue(value.trim());
                }
View Full Code Here

                    startRow +=1;

                    int endRow = table.getEndCellReference().getRow();

                    for(int i = startRow; i<= endRow; i++) {
                        XSSFRow row = sheet.getRow(i);

                        Node tableRootNode = getNodeByXPath(table.getCommonXpath(),doc.getFirstChild(),doc,true);

                        short startColumnIndex = table.getStartCellReference().getCol();
                        for(int j = startColumnIndex; j<= table.getEndCellReference().getCol();j++) {
                            XSSFCell cell = row.getCell(j);
                            if (cell!=null) {
                                XSSFXmlColumnPr pointer = tableColumns.get(j-startColumnIndex);
                                String localXPath = pointer.getLocalXPath();
                                Node currentNode = getNodeByXPath(localXPath,tableRootNode,doc,false);
                                STXmlDataType.Enum dataType = pointer.getXmlDataType();
View Full Code Here

        }
    }

    private void updateSheetFormulas(XSSFSheet sh, FormulaShifter shifter) {
        for (Row r : sh) {
            XSSFRow row = (XSSFRow) r;
            updateRowFormulas(row, shifter);
        }
    }
View Full Code Here

            XSSFSheet sheet = wb.getSheetAt(sheetNum);
            if (sheet != null)
            {
               for (int rowNum = sheet.getFirstRowNum(); rowNum <= sheet.getLastRowNum(); rowNum++)
               {
                  XSSFRow row = sheet.getRow(rowNum);

                  if (row != null)
                  {
                     int lastcell = row.getLastCellNum();
                     for (int k = 0; k < lastcell; k++)
                     {
                        XSSFCell cell = row.getCell(k);
                        if (cell != null)
                        {
                           switch (cell.getCellType())
                           {
                              case XSSFCell.CELL_TYPE_NUMERIC : {
View Full Code Here

    sheet.setColumnWidth(5, 50*255);   
    sheet.setColumnWidth(6, 15*255);   
    sheet.setColumnWidth(7, 20*255)
    sheet.setColumnWidth(8, 10*255);   
    //创建第一行
    XSSFRow row=sheet.createRow(0);
    //表头样式
        XSSFFont fonttitle=wb.createFont();
        fonttitle.setItalic(true);
        fonttitle.setFontName("微软雅黑");
        fonttitle.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);//粗体
       
            CellStyle styletitle = wb.createCellStyle();
            styletitle.setFillForegroundColor(IndexedColors.BRIGHT_GREEN.getIndex());
            styletitle.setFillPattern(CellStyle.SOLID_FOREGROUND);
            styletitle.setFont(fonttitle);
            styletitle.setBorderLeft(CellStyle.BORDER_THIN);
            styletitle.setBorderRight(CellStyle.BORDER_THIN);
            styletitle.setBorderTop(CellStyle.BORDER_THIN);
            styletitle.setBorderBottom(CellStyle.BORDER_THIN);
           
      //正文样式
            //
            XSSFFont fontRed=wb.createFont();
            fontRed.setColor(HSSFColor.GREEN.index);
            fontRed.setColor(IndexedColors.RED.getIndex());
            fontRed.setFontName("微软雅黑");
            fontRed.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);//粗体
            fontRed.setFontHeightInPoints((short) 11);
        CellStyle styleRed = wb.createCellStyle();
        styleRed.setFont(fontRed);
        styleRed.setBorderLeft(CellStyle.BORDER_THIN);
        styleRed.setBorderRight(CellStyle.BORDER_THIN);
        styleRed.setBorderTop(CellStyle.BORDER_THIN);
        styleRed.setBorderBottom(CellStyle.BORDER_THIN);
           
            XSSFFont fontGreen=wb.createFont();
            fontGreen.setColor(IndexedColors.GREEN.getIndex());
            fontGreen.setFontName("微软雅黑");
            fontGreen.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);//粗体
            fontGreen.setFontHeightInPoints((short) 11);
        CellStyle styleGreen = wb.createCellStyle();
        styleGreen.setFont(fontGreen);
        styleGreen.setBorderLeft(CellStyle.BORDER_THIN);
        styleGreen.setBorderRight(CellStyle.BORDER_THIN);
        styleGreen.setBorderTop(CellStyle.BORDER_THIN);
        styleGreen.setBorderBottom(CellStyle.BORDER_THIN);
       
            XSSFFont fontBlack=wb.createFont();
            fontBlack.setColor(IndexedColors.BLACK.getIndex());
            fontBlack.setFontName("Arial");
            fontBlack.setFontHeightInPoints((short) 9);
        CellStyle styleBlack = wb.createCellStyle();
        styleBlack.setFont(fontBlack);
        styleBlack.setBorderLeft(CellStyle.BORDER_THIN);
        styleBlack.setBorderRight(CellStyle.BORDER_THIN);
        styleBlack.setBorderTop(CellStyle.BORDER_THIN);
        styleBlack.setBorderBottom(CellStyle.BORDER_THIN);
    //写入标题
    for (int i = 0; i < title.size(); i++) {
      XSSFCell cell=row.createCell(i, XSSFCell.CELL_TYPE_STRING);
      cell.setCellValue(title.get(i));
      cell.setCellStyle(styletitle);
    }
   
    // 写入内容行
    for (int i = 0; i < datas.size(); i++) {
      String[] rowvalue = datas.get(i);
      XSSFRow nextrow = sheet.createRow(sheet.getLastRowNum() + 1);// 创建一行
      for (int j = 0; j < rowvalue.length; j++) {
        XSSFCell cell = nextrow
            .createCell(j, XSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(new XSSFRichTextString(rowvalue[j]));
        if (rowvalue[j].equals("Fail")) {
          cell.setCellStyle(styleRed);
        } else if (rowvalue[j].equals("Pass")) {
View Full Code Here

      // }
    }
  }

  private void handleRow(final XSSFWorkbook workbook, final XSSFSheet sheet, final Row row, final int rowNum) {
    XSSFRow r = sheet.createRow(rowNum);
    r.setHeightInPoints(row.getHeight());

    int cellNum = 0;

    for (Cell cell : row.getCells()) {
      this.handleCell(workbook, r, cell, cellNum++);
View Full Code Here

            XSSFSheet sheet = wb.getSheetAt(sheetNum);
            if (sheet != null)
            {
               for (int rowNum = sheet.getFirstRowNum(); rowNum <= sheet.getLastRowNum(); rowNum++)
               {
                  XSSFRow row = sheet.getRow(rowNum);

                  if (row != null)
                  {
                     int lastcell = row.getLastCellNum();
                     for (int k = 0; k < lastcell; k++)
                     {
                        XSSFCell cell = row.getCell(k);
                        if (cell != null)
                        {
                           switch (cell.getCellType())
                           {
                              case XSSFCell.CELL_TYPE_NUMERIC : {
View Full Code Here

    sheet.setColumnWidth(5, 50*255);   
    sheet.setColumnWidth(6, 15*255);   
    sheet.setColumnWidth(7, 20*255)
    sheet.setColumnWidth(8, 10*255);   
    //创建第一行
    XSSFRow row=sheet.createRow(0);
    //表头样式
        XSSFFont fonttitle=wb.createFont();
        fonttitle.setItalic(true);
        fonttitle.setFontName("微软雅黑");
        fonttitle.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);//粗体
       
            CellStyle styletitle = wb.createCellStyle();
            styletitle.setFillForegroundColor(IndexedColors.BRIGHT_GREEN.getIndex());
            styletitle.setFillPattern(CellStyle.SOLID_FOREGROUND);
            styletitle.setFont(fonttitle);
            styletitle.setBorderLeft(CellStyle.BORDER_THIN);
            styletitle.setBorderRight(CellStyle.BORDER_THIN);
            styletitle.setBorderTop(CellStyle.BORDER_THIN);
            styletitle.setBorderBottom(CellStyle.BORDER_THIN);
           
      //正文样式
            //
            XSSFFont fontRed=wb.createFont();
            fontRed.setColor(HSSFColor.GREEN.index);
            fontRed.setColor(IndexedColors.RED.getIndex());
            fontRed.setFontName("微软雅黑");
            fontRed.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);//粗体
            fontRed.setFontHeightInPoints((short) 11);
        CellStyle styleRed = wb.createCellStyle();
        styleRed.setFont(fontRed);
        styleRed.setBorderLeft(CellStyle.BORDER_THIN);
        styleRed.setBorderRight(CellStyle.BORDER_THIN);
        styleRed.setBorderTop(CellStyle.BORDER_THIN);
        styleRed.setBorderBottom(CellStyle.BORDER_THIN);
           
            XSSFFont fontGreen=wb.createFont();
            fontGreen.setColor(IndexedColors.GREEN.getIndex());
            fontGreen.setFontName("微软雅黑");
            fontGreen.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);//粗体
            fontGreen.setFontHeightInPoints((short) 11);
        CellStyle styleGreen = wb.createCellStyle();
        styleGreen.setFont(fontGreen);
        styleGreen.setBorderLeft(CellStyle.BORDER_THIN);
        styleGreen.setBorderRight(CellStyle.BORDER_THIN);
        styleGreen.setBorderTop(CellStyle.BORDER_THIN);
        styleGreen.setBorderBottom(CellStyle.BORDER_THIN);
       
            XSSFFont fontBlack=wb.createFont();
            fontBlack.setColor(IndexedColors.BLACK.getIndex());
            fontBlack.setFontName("Arial");
            fontBlack.setFontHeightInPoints((short) 9);
        CellStyle styleBlack = wb.createCellStyle();
        styleBlack.setFont(fontBlack);
        styleBlack.setBorderLeft(CellStyle.BORDER_THIN);
        styleBlack.setBorderRight(CellStyle.BORDER_THIN);
        styleBlack.setBorderTop(CellStyle.BORDER_THIN);
        styleBlack.setBorderBottom(CellStyle.BORDER_THIN);
    //写入标题
    for (int i = 0; i < title.size(); i++) {
      XSSFCell cell=row.createCell(i, XSSFCell.CELL_TYPE_STRING);
      cell.setCellValue(title.get(i));
      cell.setCellStyle(styletitle);
    }
   
    // 写入内容行
    for (int i = 0; i < datas.size(); i++) {
      String[] rowvalue = datas.get(i);
      XSSFRow nextrow = sheet.createRow(sheet.getLastRowNum() + 1);// 创建一行
      for (int j = 0; j < rowvalue.length; j++) {
        XSSFCell cell = nextrow
            .createCell(j, XSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(new XSSFRichTextString(rowvalue[j]));
        if (rowvalue[j].equals("Fail")) {
          cell.setCellStyle(styleRed);
        } else if (rowvalue[j].equals("Pass")) {
View Full Code Here

      // }
    }
  }

  private void handleRow(final XSSFWorkbook workbook, final XSSFSheet sheet, final Row row, final int rowNum) {
    XSSFRow r = sheet.createRow(rowNum);
    r.setHeightInPoints(row.getHeight());

    int cellNum = 0;

    for (Cell cell : row.getCells()) {
      this.handleCell(workbook, r, cell, cellNum++);
View Full Code Here

TOP

Related Classes of org.apache.poi.xssf.usermodel.XSSFRow

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.