Package org.apache.poi.xssf.usermodel

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


                continue;
            }

            final int rowNum = cellRef.getRow();

            XSSFRow row = sheet.getRow(rowNum);

            if( row == null ) {
                row = sheet.createRow(rowNum);
            }

            assert row!=null;
            if( row==null ) {
                final String msg = String.format( "detected problem to get/create row [%d]. Will be ignored!", rowNum );
                log.warn( msg);
                continue;
            }

            final int cellNum = cellRef.getCol();

            XSSFCell cell = row.getCell( cellNum, Row.CREATE_NULL_AS_BLANK  );

            assert cell!=null;
            if( cell==null ) {
                final String msg = String.format( "detected problem to get cell [%d,%d]. Will be ignored!", rowNum, cellNum );
                log.warn( msg);
View Full Code Here


            int cellType = -1;
            XSSFCellStyle cellStyle = null;

            for( XmlObject value : bindValues ) {

                XSSFRow row = sheet.getRow(rowNum);

                if( row == null ) {
                    row = sheet.createRow(rowNum);
                }

                assert row!=null;
                if( row==null ) {
                    final String msg = String.format( "detected problem to get/create row [%d]. Will be ignored!", rowNum );
                    log.warn( msg);
                    continue;
                }

                final int cellNum = startCell.getCol() + col;

                XSSFCell cell = row.getCell( cellNum, Row.CREATE_NULL_AS_BLANK  );

                assert cell!=null;
                if( cell==null ) {
                    final String msg = String.format( "detected problem to get cell [%d,%d]. Will be ignored!", rowNum, cellNum );
                    log.warn( msg);
View Full Code Here

        System.out.printf( "sheet [%s]\n", sheet.toString());

        int i=0;
        for( Row r : sheet ) {

            XSSFRow rr = (XSSFRow) r;


            for( Cell c: r ) {

                XSSFCell cc = (XSSFCell) c;
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 = xwb.getSheet("2011");
         
          // 获取第一行的字段名,与数据库中的字段相匹配
          HashMap<String,Integer> titleMap = new HashMap<String,Integer>();
          XSSFRow title = sheet.getRow(sheet.getFirstRowNum());
          for (int j = title.getFirstCellNum(); j < title.getPhysicalNumberOfCells(); j++) {
            titleMap.put(title.getCell(j).toString(), j);
            }
         
          //数据
          XSSFRow row;
          for (int i = sheet.getFirstRowNum()+1; i < sheet.getPhysicalNumberOfRows(); i++) {
              row = sheet.getRow(i);
             
              CpqaProject cpqaProject = new CpqaProject();
            cpqaProject.setApp_show_name( getCellData(row,titleMap,"中文名") );
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

    List<Sample> samples = new ArrayList<Sample>();
    XSSFSheet sheet = wb.getSheetAt(0);
    int rows = sheet.getPhysicalNumberOfRows();

    XSSFRow glrow = sheet.getRow(1);

    //process global headers
    XSSFCell pairedCell = glrow.getCell(0);
    boolean paired;
    if (getCellValueAsString(pairedCell) != null) {
      paired = pairedCell.getBooleanCellValue();
      log.info("Got paired: " + paired);
    }
    else {
      throw new InputFormException("'Paired' cell is empty. Please specify TRUE or FALSE.");
    }

    XSSFCell platformCell = glrow.getCell(1);
    PlatformType pt = null;
    if (getCellValueAsString(platformCell) != null) {
      pt = PlatformType.get(getCellValueAsString(platformCell));
    }
    if (pt == null) {
      throw new InputFormException("Cannot resolve Platform type from: '" + getCellValueAsString(platformCell) + "'");
    }
    else {
      log.info("Got platform type: " + pt.getKey());
    }

    XSSFCell typeCell = glrow.getCell(2);
    LibraryType lt = null;
    if (getCellValueAsString(typeCell) != null) {
      String[] split = getCellValueAsString(typeCell).split("-");
      String plat = split[0];
      String type = split[1];
      if (getCellValueAsString(platformCell).equals(plat)) {
        lt = manager.getLibraryTypeByDescriptionAndPlatform(type, pt);
      }
      else {
        throw new InputFormException("Selected library type '" + getCellValueAsString(typeCell) + "' doesn't match platform type: '" + getCellValueAsString(platformCell) + "'");
      }
    }
    if (lt == null) {
      throw new InputFormException("Cannot resolve Library type from: '" + getCellValueAsString(typeCell) + "'");
    }
    else {
      log.info("Got library type: " + lt.getDescription());
    }

    XSSFCell selectionCell = glrow.getCell(3);
    LibrarySelectionType ls = null;
    if (getCellValueAsString(selectionCell) != null) {
      ls = manager.getLibrarySelectionTypeByName(getCellValueAsString(selectionCell));
    }
    if (ls == null) {
      throw new InputFormException("Cannot resolve Library Selection type from: '" + getCellValueAsString(selectionCell) + "'");
    }
    else {
      log.info("Got library selection type: " + ls.getName());
    }

    XSSFCell strategyCell = glrow.getCell(4);
    LibraryStrategyType lst = null;
    if (getCellValueAsString(strategyCell) != null) {
      lst = manager.getLibraryStrategyTypeByName(getCellValueAsString(strategyCell));
    }
    if (lst == null) {
      throw new InputFormException("Cannot resolve Library Strategy type from: '" + getCellValueAsString(strategyCell) + "'");
    }
    else {
      log.info("Got library strategy type: " + lst.getName());
    }

    //process entries
    Plate<LinkedList<Sample>, Sample> samplePlate = null;
    Map<String, Pool<Dilution>> pools = new HashMap<String, Pool<Dilution>>();

    for (int ri = 4; ri < rows; ri++) {
      XSSFRow row = sheet.getRow(ri);

      // Ax - plate position
      XSSFCell platePosCell = row.getCell(0);
      if (getCellValueAsString(platePosCell) != null && samplePlate == null) {
        //plated samples - process as plate
        samplePlate = new PlateImpl<Sample>();
      }

      //cell defs
      XSSFCell sampleAliasCell = row.getCell(2);

      Sample s = null;
      if (getCellValueAsString(sampleAliasCell) != null) {
        String salias = getCellValueAsString(sampleAliasCell);
        Collection<Sample> ss = manager.listSamplesByAlias(salias);
        if (!ss.isEmpty()) {
          if (ss.size() == 1) {
            s = ss.iterator().next();
            log.info("Got sample: " + s.getAlias());
          }
          else {
            throw new InputFormException("Multiple samples retrieved with this alias: '" + salias + "'. Cannot process.");
          }
        }
        else {
          throw new InputFormException("No such sample '" + salias + "'in database. Samples need to be created before using the form input functionality");
        }
      }
      else {
        log.info("Blank sample row found. Ending import.");
        break;
      }

      //sample OK - good to go
      if (s != null) {
        String projectAliasCell = getCellValueAsString(row.getCell(1));
        String poolNumberCell = getCellValueAsString(row.getCell(3));
        String sampleQcCell = getCellValueAsString(row.getCell(4));
        //String sampleAmountCell = getCellValueAsString(row.getCell(5));
        //String sampleWaterAmountCell = getCellValueAsString(row.getCell(6));
        String libraryDescriptionCell = getCellValueAsString(row.getCell(7));
        String barcodeKitCell = getCellValueAsString(row.getCell(8));
        String barcodeTagsCell = getCellValueAsString(row.getCell(9));
        String libraryQcCell = getCellValueAsString(row.getCell(10));
        String libraryQcInsertSizeCell = getCellValueAsString(row.getCell(11));
        String libraryQcMolarityCell = getCellValueAsString(row.getCell(12));
        String libraryQcPassFailCell = getCellValueAsString(row.getCell(13));
        //String libraryAmountCell = getCellValueAsString(row.getCell(14));
        //String libraryWaterAmountCell = getCellValueAsString(row.getCell(15));
        //String dilutionQcCell = getCellValueAsString(row.getCell(16));
        String dilutionMolarityCell = getCellValueAsString(row.getCell(17));
        //String dilutionAmountCell = getCellValueAsString(row.getCell(18));
        //String dilutionWaterAmountCell = getCellValueAsString(row.getCell(19));
        String poolQcCell = getCellValueAsString(row.getCell(20));
        //String poolAverageInsertSizeCell = getCellValueAsString(row.getCell(21));
        String poolConvertedMolarityCell = getCellValueAsString(row.getCell(22));

        //add pool, if any
        processPool(poolNumberCell, poolConvertedMolarityCell, pools);
        processSampleQC(sampleQcCell, s, u, manager);
View Full Code Here

        //"sampleid:wellid:samplealias:projectname"
        String sampleId = sampleinwell.split(":")[0];
        String wellId = sampleinwell.split(":")[1];
        String sampleAlias = sampleinwell.split(":")[2];
        String projectName = sampleinwell.split(":")[3];
        XSSFRow row = sheet.createRow(i);
        XSSFCell cellA = row.createCell(0);
        cellA.setCellValue(wellId);
        XSSFCell cellB = row.createCell(1);
        cellB.setCellValue(projectName);
        XSSFCell cellC = row.createCell(2);
        cellC.setCellValue(sampleAlias);
        i++;
      }
      oDoc.write(fileOut);
      fileOut.close();
View Full Code Here

    List<Sample> samples = new ArrayList<Sample>();
    XSSFSheet sheet = wb.getSheetAt(0);
    int rows = sheet.getPhysicalNumberOfRows();

    XSSFRow glrow = sheet.getRow(1);

    //process global headers
    XSSFCell pairedCell = glrow.getCell(0);
    boolean paired = pairedCell.getBooleanCellValue();
    log.info("Got paired: " + paired);

    XSSFCell platformCell = glrow.getCell(1);
    PlatformType pt = null;
    if (getCellValueAsString(platformCell) != null) {
      pt = PlatformType.get(getCellValueAsString(platformCell));
    }
    if (pt == null) {
      throw new InputFormException("Cannot resolve Platform type from: '" + getCellValueAsString(platformCell) + "'");
    }
    else {
      log.info("Got platform type: " + pt.getKey());
    }

    XSSFCell typeCell = glrow.getCell(2);
    LibraryType lt = null;
    if (getCellValueAsString(typeCell) != null) {
      String[] split = getCellValueAsString(typeCell).split("-");
      String plat = split[0];
      String type = split[1];
      if (getCellValueAsString(platformCell).equals(plat)) {
        lt = manager.getLibraryTypeByDescriptionAndPlatform(type, pt);
      }
      else {
        throw new InputFormException("Selected library type '" + getCellValueAsString(typeCell) + "' doesn't match platform type: '" + getCellValueAsString(platformCell) + "'");
      }
    }
    if (lt == null) {
      throw new InputFormException("Cannot resolve Library type from: '" + getCellValueAsString(typeCell) + "'");
    }
    else {
      log.info("Got library type: " + lt.getDescription());
    }

    XSSFCell selectionCell = glrow.getCell(3);
    LibrarySelectionType ls = null;
    if (getCellValueAsString(selectionCell) != null) {
      ls = manager.getLibrarySelectionTypeByName(getCellValueAsString(selectionCell));
    }
    if (ls == null) {
      throw new InputFormException("Cannot resolve Library Selection type from: '" + getCellValueAsString(selectionCell) + "'");
    }
    else {
      log.info("Got library selection type: " + ls.getName());
    }

    XSSFCell strategyCell = glrow.getCell(4);
    LibraryStrategyType lst = null;
    if (getCellValueAsString(strategyCell) != null) {
      lst = manager.getLibraryStrategyTypeByName(getCellValueAsString(strategyCell));
    }
    if (lst == null) {
      throw new InputFormException("Cannot resolve Library Strategy type from: '" + getCellValueAsString(strategyCell) + "'");
    }
    else {
      log.info("Got library strategy type: " + lst.getName());
    }

    XSSFCell plateBarcodeCell = glrow.getCell(5);
    String plateBarcode = null;
    if (getCellValueAsString(plateBarcodeCell) != null) {
      plateBarcode = getCellValueAsString(plateBarcodeCell);
    }
    if (plateBarcode == null) {
      throw new InputFormException("Cannot resolve plate barcode from: '" + getCellValueAsString(plateBarcodeCell) + "'");
    }
    else {
      log.info("Got plate barcode: " + plateBarcode);
    }

    //process entries
    Simple384WellPlate libraryPlate = null;
    //Map<String, Pool<Plate<LinkedList<Library>, Library>>> pools = new HashMap<String, Pool<Plate<LinkedList<Library>, Library>>>();
    Map<String, PlatePool> pools = new HashMap<String, PlatePool>();
    for (int ri = 4; ri < rows; ri++) {
      XSSFRow row = sheet.getRow(ri);

      // Ax - plate position
      XSSFCell platePosCell = row.getCell(0);
      String platePos = getCellValueAsString(platePosCell);
      if (platePos != null && libraryPlate == null) {
        //plated libraries - process as plate
        libraryPlate = new Simple384WellPlate();
        libraryPlate.setIdentificationBarcode(plateBarcode);
        libraryPlate.setCreationDate(new Date());
      }

      //cell defs
      XSSFCell sampleAliasCell = row.getCell(2);

      Sample s = null;
      if (getCellValueAsString(sampleAliasCell) != null) {
        String salias = getCellValueAsString(sampleAliasCell);
        Collection<Sample> ss = manager.listSamplesByAlias(salias);
        if (!ss.isEmpty()) {
          if (ss.size() == 1) {
            s = ss.iterator().next();
            log.info("Got sample: " + s.getAlias());
          }
          else {
            throw new InputFormException("Multiple samples retrieved with this alias: '" + salias + "'. Cannot process.");
          }
        }
        else {
          throw new InputFormException("No such sample '" + salias + "'in database. Samples need to be created before using the form input functionality");
        }
      }
      else {
        log.info("Blank sample row found. Ending import.");
        break;
      }

      //sample OK - good to go
      if (s != null) {
        XSSFCell entityIDCell = row.getCell(2);
        XSSFCell poolNumberCell = row.getCell(3);
        XSSFCell sampleQcCell = row.getCell(4);
        //XSSFCell sampleAmountCell = row.getCell(5);
        //XSSFCell sampleWaterAmountCell = row.getCell(6);
        XSSFCell libraryDescriptionCell = row.getCell(7);
        XSSFCell barcodeKitCell = row.getCell(8);
        XSSFCell barcodeTagsCell = row.getCell(9);
        XSSFCell libraryQcCell = row.getCell(10);
        XSSFCell libraryQcInsertSizeCell = row.getCell(11);
        XSSFCell libraryQcMolarityCell = row.getCell(12);
        XSSFCell libraryQcPassFailCell = row.getCell(13);
        //XSSFCell libraryAmountCell = row.getCell(14);
        //XSSFCell libraryWaterAmountCell = row.getCell(15);
        //XSSFCell dilutionQcCell = row.getCell(16);
        XSSFCell dilutionMolarityCell = row.getCell(17);
        //XSSFCell dilutionAmountCell = row.getCell(18);
        //XSSFCell dilutionWaterAmountCell = row.getCell(19);
        XSSFCell poolQcCell = row.getCell(20);
        //XSSFCell poolAverageInsertSizeCell = row.getCell(21);
        XSSFCell poolConvertedMolarityCell = row.getCell(22);

        //add pool, if any
        if (getCellValueAsString(poolNumberCell) != null) {
          String poolNum = getCellValueAsString(poolNumberCell);
          if (!pools.containsKey(poolNum)) {
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

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.