code: private void renderCellToHeaderFooter(StringBuilder result, String bandName, BandElement bandElement, Object value, int gridRow, int row,
                                int column, int cols, int rowSpan, int colSpan, boolean isImage) {
      	    	
      	if (newRow) {
      		result.append("\r\n ");
      	} else {
      		result.append(" ");
      	}
      	boolean specialCell = false;
      	if (bandElement instanceof VariableBandElement)  {
          	VariableBandElement vbe = (VariableBandElement)bandElement;
          	Variable var = VariableFactory.getVariable(vbe.getVariable());        	
          	if (var instanceof PageNoVariable) {           		
          		specialCell = true;
          		result.append("&P");
          	} 
      	} else if (bandElement instanceof ExpressionBandElement)  {
           	// special case pageNo inside an expression
           	// bandName is not important here (it is used for groupRow computation)
      		PrefixSuffix pf = interpretPageNo(bandElement);
  			if (pf != null) {
  				result.append(pf.getPrefix()).append(" &P ").append(pf.getSuffix());     
  				specialCell = true;
  			}	
      	}
  		if (!specialCell) {
  			result.append(value);
  		}				
      }
docs: http://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/extensions/XSSFHeaderFooter.html