插入新的行（向下移动表格中的行），方便写入数据。

@param sheet          表单页。
@param list           写入JavaBean列表。
@param templateRowNum 模板行号。
@return JavaBean列表大小。
492991
public static int shiftRows(Sheet sheet, List<?> list, int templateRowNum) {
        val itemSize = list == null ? 0 : list.size();
        return shiftRows(sheet, itemSize, templateRowNum);
    }
467832
public synchronized TableModel<V> setCell(int columnIndex, int rowIndex, V value) {
        getCell(columnIndex, rowIndex);
        List<V> row = rows.get(rowIndex);

        //Pad row with null if necessary
        for(int j = row.size(); j < columnIndex; j++) {
            row.add(null);
        }

        V existingValue = row.get(columnIndex);
        if(existingValue == value) {
            return this;
        }
        row.set(columnIndex, value);
        for(Listener<V> listener: listeners) {
            listener.onCellChanged(this, rowIndex, columnIndex, existingValue, value);
        }
        return this;
    }
494253
public static List<List<String>> readTable(String sheetName) {
        setXssfSheet(xssfWorkbook.getSheet(sheetName));
        return readTable();
    }
1278546
public void generate( String templateName,
                          Row row ) {
        try {
            CompiledTemplate template = getTemplate( templateName );
            VariableResolverFactory factory = new MapVariableResolverFactory();
            Map<String, Object> vars = new HashMap<String, Object>();

            initializePriorCommaConstraints( vars );
            initializeHasPriorJunctionConstraint( vars );

            vars.put( "row",
                      row );

            for ( Cell cell : row.getCells() ) {
                cell.addValue( vars );
            }

            String drl = String.valueOf( TemplateRuntime.execute( template,
                                                                  vars,
                                                                  factory,
                                                                  registry ) );

            rules.add( drl );
        } catch ( Exception e ) {
            throw new RuntimeException( e );
        }
    }
406476
public List<String> getHeaderRowContents(String sheetName, int size) {
        return excelReader.getHeaderRowContents(sheetName, size);
    }
452477
protected String[] readLine(HSSFSheet sheet, int rowIndex) {
    HSSFRow row = sheet.getRow(rowIndex);
    logger.debug("values count:{}", row.getLastCellNum());
    List<String> attrList = CollectUtils.newArrayList();
    for (int i = 0; i < row.getLastCellNum(); i++) {
      HSSFCell cell = row.getCell(i);
      if (null != cell) {
        String attr = cell.getRichStringCellValue().getString();
        if (Strings.isEmpty(attr)) {
          break;
        } else {
          attrList.add(attr.trim());
        }
      } else {
        break;
      }
    }
    String[] attrs = new String[attrList.size()];
    attrList.toArray(attrs);
    logger.debug("has attrs {}", attrs);
    return attrs;
  }
206351
public static Row insertRow(final Sheet sheet, final int rowIndex) {

        ArgUtils.notNull(sheet, "cell");
        ArgUtils.notMin(rowIndex, 0, "rowIndex");

        // 最終行を取得する
        int lastRow = sheet.getLastRowNum();
        if(lastRow < rowIndex) {
            // データが定義されている範囲害の場合は、行を新たに作成して返す。
            return sheet.createRow(rowIndex);
        }

        sheet.shiftRows(rowIndex, lastRow+1, 1);
        return sheet.createRow(rowIndex);
    }
847337
public void generateXls(OutputStream out, List<Map<String, Object>> rows, List<ColumnDef> columns) {
        try {
            Workbook wb = new HSSFWorkbook();  // or new XSSFWorkbook();
            String safeName = WorkbookUtil.createSafeSheetName("Report"); // returns " O'Brien's sales   "
            Sheet reportSheet = wb.createSheet(safeName);

            short rowc = 0;
            Row nrow = reportSheet.createRow(rowc++);
            short cellc = 0;
            if (rows == null) return;
            if (columns == null && rows.size() > 0)
            {
                columns = new ArrayList<ColumnDef>(CollectionUtils.collect(rows.get(0).keySet(), new Transformer() {
                    @Override
                    public Object transform(final Object input) {
                        return new ColumnDef()
                        {{
                                setName((String)input);
                            }};
                    }
                }));
            }
            if (columns != null)
            {
                for (ColumnDef column : columns)
                {
                    Cell cell = nrow.createCell(cellc++);
                    cell.setCellValue(column.getName());
                }
            }
            for (Map<String, Object> row : rows)
            {
                nrow = reportSheet.createRow(rowc++);
                cellc = 0;
                for (ColumnDef column : columns)
                {
                    Cell cell = nrow.createCell(cellc++);
                    cell.setCellValue(String.valueOf(row.get(column.getName())));
                }
            }
            wb.write(out);
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }

    }
221908
public static int getColumns(final Sheet sheet) {
        ArgUtils.notNull(sheet, "sheet");

        int minRowIndex = sheet.getFirstRowNum();
        int maxRowIndex = sheet.getLastRowNum();
        int maxColumnsIndex = 0;
        for(int i = minRowIndex; i <= maxRowIndex; i++) {
            final Row row = sheet.getRow(i);
            if(row == null) {
                continue;
            }

            final int column = row.getLastCellNum();
            if(column > maxColumnsIndex) {
                maxColumnsIndex = column;
            }
        }

        return maxColumnsIndex;
    }
58161
public static <T> List<T> handleWorkBookToBeans(Class<T> clazz, File file) throws ReadExcelException {
        List<T> beans = null;
        try {
            Workbook workbook = WorkbookFactory.create(file);
            beans = ReadExcelUtils.handleWorkBookToBeans(clazz, workbook);
            if (workbook != null) {
                workbook.close();
            }
        } catch (Exception e) {
            throw new ReadExcelException(e.getMessage());
        }
        return beans;
    }
1084940
public SpreadSheetCellDAO[] getSpreadSheetCellDAOfromSimpleDataType(Object[] row, String sheetName, int rowNum) {
		// for each value in the row

		SpreadSheetCellDAO[] result = new SpreadSheetCellDAO[row.length];
		for (int currentColumnNum = 0; currentColumnNum < row.length; currentColumnNum++) { // for each element of the
																							// row
			Object x = row[currentColumnNum];
			String formattedValue = "";
			String comment = "";
			String formula = "";
			String address = "";
			StringBuffer sb = new StringBuffer();
			if (x != null) {
				if (x instanceof SpreadSheetCellDAO) {
					result[currentColumnNum] = (SpreadSheetCellDAO) x;
				} else {
					if (x instanceof Boolean) {
						formattedValue = "";
						comment = "";
						formula = String.valueOf(x);
						address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
					} else if (x instanceof Byte) {
						formattedValue = "";
						comment = "";
						formula = String.valueOf(x);
						address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
					} else if (x instanceof Short) {
						formattedValue ="";
						comment = "";
						formula = "";
						formula = String.valueOf(x);
						address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
					} else if (x instanceof Integer) {
						formattedValue = "";
						comment = "";
						formula = String.valueOf(x);
						address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
					} else if (x instanceof Long) {
						formattedValue = "";
						comment = "";
						formula = String.valueOf(x);
						address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
					} else if (x instanceof Double) {
						formattedValue = "";
						comment = "";
						formula = String.valueOf(x);
						address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
					} else if (x instanceof Float) {
						formattedValue = "";
						comment = "";
						formula = String.valueOf(x);
						address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
					} else if (x instanceof BigDecimal) {
						formattedValue = "";
						comment = "";
						formula = ((BigDecimal) x).toString();
						address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
					} else if (x instanceof Timestamp) {
						if (this.dateTimeFormat==null) {
							formattedValue = String.valueOf(x);
						} else {
							formattedValue=this.dateTimeFormat.format(x,sb,new FieldPosition(0)).toString();
							sb.setLength(0);
						}
						comment = "";
						formula = "";
						address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
					} else if (x instanceof Date) {
						formattedValue = this.dateFormat.format((Date) x);
						comment = "";
						formula = "";
						address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
					} else if (x instanceof String) {
						formattedValue = x.toString();
						comment = "";
						formula = "";
						address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
					} else if ((x instanceof String[]) && ((String[]) x).length == 5) {
						String[] spreadSheetCellDAOAsArray = (String[]) x;
						formattedValue = spreadSheetCellDAOAsArray[0];
						comment = spreadSheetCellDAOAsArray[1];
						formula = spreadSheetCellDAOAsArray[2];
						address = spreadSheetCellDAOAsArray[3];
						sheetName = spreadSheetCellDAOAsArray[4];
					} else {
						LOG.warn("Unknown datatype in column number: " + currentColumnNum + ". Reported data type"
								+ x.getClass().getName() + ". Trying to use .toString");
						formattedValue = x.toString();
						comment = "";
						formula = "";
						address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
					}
					result[currentColumnNum] = new SpreadSheetCellDAO(formattedValue, comment, formula, address,
							sheetName);
				}
			}
		}
		return result;
	}
1200710
File appendSheet(final List<WorksheetContent> worksheetContents) throws IOException {
        final ImmutableSet<String> worksheetNames = FluentIterable.from(worksheetContents)
                .transform(new Function<WorksheetContent, String>() {
                    @Nullable @Override public String apply(@Nullable final WorksheetContent worksheetContent) {
                        return worksheetContent.getSpec().getSheetName();
                    }
                }).toSet();
        if(worksheetNames.size() < worksheetContents.size()) {
            throw new IllegalArgumentException("Sheet names must have distinct names");
        }
        for (final String worksheetName : worksheetNames) {
            if(worksheetName.length() > 30) {
                throw new IllegalArgumentException(
                        String.format("Sheet name cannot exceed 30 characters (invalid name: '%s')",
                                worksheetName));
            }
        }

        final XSSFWorkbook workbook = new XSSFWorkbook();
        final File tempFile =
                File.createTempFile(ExcelConverter.class.getName(), UUID.randomUUID().toString() + XLSX_SUFFIX);
        final FileOutputStream fos = new FileOutputStream(tempFile);

        for (WorksheetContent worksheetContent : worksheetContents) {
            final WorksheetSpec spec = worksheetContent.getSpec();
            appendSheet(workbook, worksheetContent.getDomainObjects(), spec.getFactory(), spec.getSheetName());
        }
        workbook.write(fos);
        fos.close();
        return tempFile;
    }
557867
protected JavascriptVarBuilder encodeRow(final FacesContext context, final String rowKey,
                final JavascriptVarBuilder jsData, final JavascriptVarBuilder jsRowStyle,
                final JavascriptVarBuilder jsStyle, final JavascriptVarBuilder jsReadOnly, final Sheet sheet,
                final int rowIndex) throws IOException {
        // encode rowStyle (if any)
        final String rowStyleClass = sheet.getRowStyleClass();
        if (rowStyleClass == null) {
            jsRowStyle.appendArrayValue("null", false);
        }
        else {
            jsRowStyle.appendArrayValue(rowStyleClass, true);
        }

        // data is array of array of data
        final JavascriptVarBuilder jsRow = new JavascriptVarBuilder(null, false);
        int renderCol = 0;
        for (int col = 0; col < sheet.getColumns().size(); col++) {
            final SheetColumn column = sheet.getColumns().get(col);
            if (!column.isRendered()) {
                continue;
            }

            // render data value
            final String value = sheet.getRenderValueForCell(context, rowKey, col);
            jsRow.appendArrayValue(value, true);

            // custom style
            final String styleClass = column.getStyleClass();
            if (styleClass != null) {
                jsStyle.appendRowColProperty(rowIndex, renderCol, styleClass, true);
            }

            // read only per cell
            final boolean readOnly = column.isReadonlyCell();
            if (readOnly) {
                jsReadOnly.appendRowColProperty(rowIndex, renderCol, "true", true);
            }
            renderCol++;
        }
        // close row and append to jsData
        jsData.appendArrayValue(jsRow.closeVar().toString(), false);
        return jsData;
    }
216368
public static List<Map<String, Object>> handleSheetToMapList(Sheet sheet) throws ReadExcelException {
        List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
        // 得到Sheet里的列名
        List<String> columnList = ReadExcelUtils.getColumnOfSheet(sheet);
        for (int i = 2; i < sheet.getLastRowNum() + 1; i++) {
            Map<String, Object> beanMap = new HashMap<String, Object>();
            // 得到行
            Row row = sheet.getRow(i);
            // 遍历列
            for (int j = 0; j < row.getLastCellNum(); j++) {
                // 获取单元格
                Cell cell = row.getCell(j);
                if (cell != null) {
                    // 单元格对应列名
                    String key = columnList.get(j);
                    // 单元格对应值
                    Object value = ReadExcelUtils.getCellValue(cell.getCellType(), cell);
                    // key-value pairs 放入map
                    if (value != null) {
                        beanMap.put(key, value);
                    }
                }
            }
            // 将每个beanMap放入List中
            if (!beanMap.isEmpty()) {
                listMap.add(beanMap);
            }
        }
        return listMap;
    }
302905
public AbstractSheet<TRow, TColumn, TCell> setRows(List<TRow> rows) {
        this.rows = rows;
        return this;
    }
1273527
public static void loadTemplate(SheetTemplate template, int sheetIndex) {

        if (sheetIndex < 0) sheetIndex = 0;
        template.sheetIndex = sheetIndex;
        template.sheet = template.workbook.getSheetAt(sheetIndex);
        initModuleConfig(template);
        template.currentRowIndex = template.initRowIndex;
        template.currentColumnIndex = template.initColumnIndex;
        template.lastRowIndex = template.sheet.getLastRowNum();
    }
219033
public PdfPCell createTableCell(Object val, Collection<BaseStyler> stylers, boolean noWrap) throws VectorPrintException {
      if (noWrap) {
         stylers.add(new NoWrap());
      }

      return createCell(val, stylers);
   }