当前位置: 首页>>代码示例>>Java>>正文


Java XSSFSheet.createRow方法代码示例

本文整理汇总了Java中org.apache.poi.xssf.usermodel.XSSFSheet.createRow方法的典型用法代码示例。如果您正苦于以下问题:Java XSSFSheet.createRow方法的具体用法?Java XSSFSheet.createRow怎么用?Java XSSFSheet.createRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.xssf.usermodel.XSSFSheet的用法示例。


在下文中一共展示了XSSFSheet.createRow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeXLSXFile

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
public static void writeXLSXFile() throws IOException {

            // @SuppressWarnings("resource")
            XSSFWorkbook wbObj = new XSSFWorkbook();
            XSSFSheet sheet = wbObj.createSheet(sheetName);
            for (int row = 0; row < tableData.size(); row++) {
                XSSFRow rowObj = sheet.createRow(row);
                rowData = tableData.get(row);
                for (int col = 0; col < rowData.size(); col++) {
                    XSSFCell cell = rowObj.createCell(col);
                    cell.setCellValue(rowData.get(col));
                    logger.info("Writing " + row + " " + col + "  " + rowData.get(col));
                }
            }
            FileOutputStream fileOut = new FileOutputStream(excelFileName);
            wbObj.write(fileOut);
            wbObj.close();
            fileOut.flush();
            fileOut.close();
        }
 
开发者ID:sergueik,项目名称:SWET,代码行数:21,代码来源:TableEditorEx.java

示例2: createWageringHeaderRow

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
public static XSSFRow createWageringHeaderRow(XSSFSheet sheet, int row, int col) {
    XSSFRow headerRow = sheet.createRow(row++);

    col = seedCols(col, headerRow);

    List<String> columns = Arrays.asList("winPayoff", "placePayoff",
            "showPayoff", "totalWpsPool", "doublePayoff", "doublePool", "exactaPayoff",
            "exactaPool", "trifectaPayoff", "trifectaPool", "superfectaPayoff",
            "superfectaPool", "pick3Payoff", "pick3Pool", "pick4Payoff", "pick4Pool",
            "pick5Payoff", "pick5Pool");
    for (String column : columns) {
        CellUtil.createCell(headerRow, col++, column);
    }

    return headerRow;
}
 
开发者ID:robinhowlett,项目名称:handycapper,代码行数:17,代码来源:ThreeTypeSummary.java

示例3: copySheets

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
/**
 * @param newSheet the sheet to create from the copy.
 * @param sheet the sheet to copy.
 * @param copyStyle true copy the style.
 */
public static void copySheets(XSSFSheet newSheet, XSSFSheet sheet, boolean copyStyle) {
    int maxColumnNum = 0;
    Map<Integer, XSSFCellStyle> styleMap = (copyStyle) ? new HashMap<Integer, XSSFCellStyle>() : null;
    for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
        XSSFRow srcRow = sheet.getRow(i);
        XSSFRow destRow = newSheet.createRow(i);
        if (srcRow != null) {
            Util.copyRow(sheet, newSheet, srcRow, destRow, styleMap);
            if (srcRow.getLastCellNum() > maxColumnNum) {
                maxColumnNum = srcRow.getLastCellNum();
            }
        }
    }
    for (int i = 0; i <= maxColumnNum; i++) {
        newSheet.setColumnWidth(i, sheet.getColumnWidth(i));
    }
   //Util.copyPictures(newSheet,sheet) ;
}
 
开发者ID:likelet,项目名称:DAtools,代码行数:24,代码来源:Util.java

示例4: generate

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
public XSSFWorkbook generate(List<Person> persons, List<String> columns) {
    XSSFSheet sheet = (XSSFSheet) createSheet("Document .xlsx");

    int rowIndex = 0;

    addHeadersToSheet(sheet, rowIndex, columns);
    rowIndex++;

    for (Person person : persons) {
        XSSFRow currentRow = sheet.createRow(rowIndex);
        rowIndex++;

        int columnIndex = 0;

        for (String column : columns) {
            addCell(currentRow, columnIndex, person, column);
            columnIndex++;
        }
    }

    finalizeSheet(sheet, columns);

    return (XSSFWorkbook) workbook;
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:25,代码来源:PersonXSSFExport.java

示例5: getCell

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
/**
 * Returns the cell of a given sheet at icol;irow. Former values are overwritten.
 *
 * @param sheet the sheet to write on
 * @param icol index of column
 * @param irow index of row
 * @return the given cell at icol;irow
 * @see
 */
public Cell getCell(XSSFSheet sheet, int icol, int irow) {
  // try to get row
  Row row = sheet.getRow(irow);
  // if not exist: create row
  if (row == null)
    row = sheet.createRow(irow);
  // get cell
  return row.createCell(icol);
}
 
开发者ID:mzmine,项目名称:mzmine2,代码行数:19,代码来源:XSSFExcelWriterReader.java

示例6: writeToSheet

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
/**
 * Adds the given information as a new row to the provided sheet
 * @param data: an array of strings to write to different cells of a new row in the sheet
 * * @see SHEET_METADATA
 */
public void writeToSheet(String[] data, int SHEET){
    XSSFSheet sheet;
    Row row;

    //Get the sheet and the next row to edit on that sheet
    switch(SHEET)
    {
        case SHEET_COMMENTS:
            sheet =  commentSheet;
            row = sheet.createRow(commentRowCount++);
            //Custom row stylings for Comment Sheet entries
            row.setRowStyle(styleWordWrap);
            row.setHeight((short)850);
            break;

        case SHEET_METADATA:
            sheet =  metadataSheet;
            row = sheet.createRow(metadataRowCount++);
            //Custom row stylings for Plant Metadata Sheet entries
            break;

        case SHEET_BEDMETADATA:
            sheet =  bedmetadataSheet;
            row = sheet.createRow(bedmetadataRowCount++);
            //Custom row stylings for Bed Metadata Sheet entries
            break;

        default:
            throw new IndexOutOfBoundsException("Sheet " + SHEET + " not understood, getSHEET is being called with incorrect input.");
    }

    //Write the data
    for(int i = 0; i < data.length; i++) {
        Cell cell = row.createCell(i);
        cell.setCellValue(data[i]);
    }

}
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-revolverenguardia-1,代码行数:44,代码来源:FeedbackWriter.java

示例7: createHeader

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
private void createHeader(Map<String, CellStyle> styles,
                          XSSFSheet sheet,
                          List<String> header) {
    final XSSFRow rowhead = sheet.createRow(0);

    int i = 0;
    for (String headerColumn : header) {
        rowhead.createCell(i).setCellValue(new XSSFRichTextString(headerColumn));
        rowhead.getCell(i).setCellStyle(styles.get("header"));
        i++;
    }
}
 
开发者ID:Dactilo,项目名称:spring-spreadsheet,代码行数:13,代码来源:ExcelStreamer.java

示例8: createBreedingHeaderRow

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
public static XSSFRow createBreedingHeaderRow(XSSFSheet sheet, int row, int col) {
    XSSFRow headerRow = sheet.createRow(row++);

    col = standardCols(col, headerRow);

    List<String> columns = Arrays.asList("sex", "sire", "dam", "damSire", "foalDate", "age");
    for (String column : columns) {
        CellUtil.createCell(headerRow, col++, column);
    }

    return headerRow;
}
 
开发者ID:robinhowlett,项目名称:handycapper,代码行数:13,代码来源:ThreeTypeSummary.java

示例9: createNewWorkbook

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
/**
 * Creates a new workbook.
 *
 * @param map
 *            the map of path, key, locales and properties
 * @return the workbook
 */
private Workbook createNewWorkbook(final Map<PathAndKey, Map<Locale, String>> map) {
    int rowCounter = 0;

    final XSSFWorkbook workbook = new XSSFWorkbook();
    final XSSFSheet worksheet = workbook.createSheet("Worksheet");
    XSSFRow currentRow = worksheet.createRow(rowCounter++);

    int cellCounter = 0;
    final List<Locale> locales = findAllLocales(map);

    // create header
    currentRow.createCell(cellCounter++).setCellValue("path");
    currentRow.createCell(cellCounter++).setCellValue("key");
    currentRow.createCell(cellCounter++).setCellValue("used");

    for (final Locale locale : locales) {
        currentRow.createCell(cellCounter++).setCellValue(locale.toString());
    }

    // fill in values
    for (final Entry<PathAndKey, Map<Locale, String>> e : map.entrySet()) {
        currentRow = worksheet.createRow(rowCounter++);
        fillNewRow(currentRow, e, locales);
    }

    return workbook;
}
 
开发者ID:pingunaut,项目名称:wicketmessages-maven-plugin,代码行数:35,代码来源:GenerateXlsMojo.java

示例10: writeToSheet

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
public void writeToSheet(String sheetName, Map<Integer,String> cellValues, Map<Integer,String> headerValues){
    XSSFSheet sheet; 
    if(sheetNames.contains(sheetName)){
        sheet = wb.getSheet(sheetName); 
        }
    else{
        sheet = wb.createSheet(sheetName); 
        sheetNames.add(sheetName); 
        }
    setRowNumber(headerValues);
    
    
    XSSFRow row = sheet.createRow(lastRow); 
    
    for(int i : cellValues.keySet()){
        XSSFCell cell = row.createCell(i); 
        cell.setCellValue(cellValues.get(i));
    }
    
    
    XSSFRow headerRow = sheet.getRow(0);
    if(headerRow == null); 
        headerRow = sheet.createRow(0); 
    
    for(int j : headerValues.keySet()){
        XSSFCell headerCell = headerRow.createCell(j); 
        headerCell.setCellValue(headerValues.get(j));
    }

    incRowNumber(headerValues);
}
 
开发者ID:arago,项目名称:excel-mars-translator,代码行数:32,代码来源:ExcelWriter.java

示例11: writeExcel

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
public static void writeExcel(HttpServletResponse response,List<String> list) throws Exception {
    response.setContentType("application/vnd.ms-excel");//文件格式,此处设置为excel
    response.setHeader("Content-Disposition","attachment;filename=file.xls");//此处设置了下载文件的默认名称
    ServletOutputStream sos = response.getOutputStream();
    //创建一个新的excel
    XSSFWorkbook wb = new XSSFWorkbook();//XSSFWorkbook
    /**
     * 采用现成Excel模板
     * 用这种方式得先保证每个cell有值,不然会报空指针
     * 有时我们用row.getCell(i)会得到null,那么此时就要用Iterator<Cell> it = row.cellIterator();
     * XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(new File("D://a.xlsx")));
     * XSSFSheet sheet = wb.getSheet("Sheet1");
     * row[i] = sheet.getRow(i);
     * headerCell[j] = row[i].getCell(j);
     */
    //创建sheet页
    XSSFSheet sheet = wb.createSheet("sheet1");//sheet名
    //创建行数
    XSSFRow[] row = new XSSFRow[list.size()];
    //插入数据
    for (int i = 0; i < row.length; i++) {
        row[i] = sheet.createRow(i);
        sheet.setDefaultColumnWidth(30);//设置列的长度
        String info[] = list.get(i).split(",");
        XSSFCell[] headerCell = new XSSFCell[info.length];
        for (int j = 0; j < headerCell.length; j++) {
            headerCell[j] = row[i].createCell(j);
            headerCell[j].setCellValue(new XSSFRichTextString(info[j]));
            /**设置模板样式*/
            //headerCell[j].setCellStyle(setStyle(wb));
        }
    }
    wb.write(sos);
    wb.close();
    sos.flush();
    sos.close();
    response.flushBuffer();
}
 
开发者ID:tank2140896,项目名称:JavaWeb,代码行数:39,代码来源:FileUtil.java

示例12: buildSpreadsheet

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
/**
 * Construye la hoja de Excel
 *
 * @return Instancia de la clase XSSFWorkbook con los datos almacenados en
 * el buffer de datos
 */
private XSSFWorkbook buildSpreadsheet() {
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet();

    for (int i = 0; i <= mainBuffer.get(0).size(); i++) {
        Row row = sheet.createRow(i);
        for (int j = 0; j < variableList.size(); j++) {

            Cell cell = row.createCell(j);

            if (i == 0) {
                cell.setCellValue((String) variableList.get(j));
            } else {
                Object value = classList.get(j);
                if ((value instanceof String) || (value.equals(String.class))) {
                    cell.setCellValue((String) mainBuffer.get(j).get(i - 1));
                } else if ((value instanceof Boolean) || (value.equals(Boolean.class))) {
                    cell.setCellValue((Boolean) mainBuffer.get(j).get(i - 1));
                } else if ((value instanceof Date) || (value.equals(Date.class))) {
                    cell.setCellValue((String) mainBuffer.get(j).get(i - 1));
                } else if ((value instanceof Integer) || (value.equals(Integer.class))) {
                    cell.setCellValue((Integer) mainBuffer.get(j).get(i - 1));
                } else if ((value instanceof Long) || (value.equals(Long.class))) {
                    cell.setCellValue((Long) mainBuffer.get(j).get(i - 1));
                } else if ((value instanceof Float) || (value.equals(Float.class))) {
                    cell.setCellValue((Float) mainBuffer.get(j).get(i - 1));
                } else if ((value instanceof Double) || (value.equals(Double.class))) {
                    cell.setCellValue((Double) mainBuffer.get(j).get(i - 1));
                }
            }
        }
    }
    return workbook;
}
 
开发者ID:PanamaHitek,项目名称:PanamaHitek_Arduino,代码行数:41,代码来源:PanamaHitek_DataBuffer.java

示例13: expReportQueryData

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
/**
 * 导出数据,用scroll执行,否则大量分页数据会有重复
 * @param dataIndex 行数
 * @param row HSSFRow
 * @param sheet HSSFSheet
 * @param req PagerReq
 */
@Override
public void expReportQueryData(PagerReq req, int dataIndex, XSSFRow row, XSSFSheet sheet) {
    Query query = null;
    List<Condition> conList = JSON.parseArray(req.getCondition(), Condition.class);
    /* 在此处根据传过来的trueSql去找到正确的SQl然后拼条件condition */
    String sql = req.getBaseSql();
    query = baseDao.getSqlQuery(sql);
    for (Condition con : conList) {
        query.setParameter(con.getName(), con.getValue());
    }
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    /* 格式化百分号 */
    String[] findex = getFIndex(req);
    int i = dataIndex;
    ScrollableResults scrollableResults  = query.scroll();
    while (scrollableResults.next()) {
    	Object[] list = scrollableResults.get();
    	row = sheet.createRow(i);
        for (int j = 0; j < list.length; j++) {
            if (list[j] instanceof Timestamp) {
                list[j] = df.format((Timestamp) list[j]);
            }
            String cel = getCelValue (list[j], findex, j);
            row.createCell(j).setCellValue(cel);
        }
        i++;
        //if (i > 65535) 
        	//break;
    }
}
 
开发者ID:ls960972314,项目名称:report,代码行数:38,代码来源:ReportDaoImpl.java

示例14: printSheet

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
private void printSheet(final XSSFWorkbook wb, final XSSFSheet sheet, final APIModel api) {
    
    ////////////////////////////////////////////////////
    XSSFRow row = null;
    XSSFCell cell = null;
    
    ////////////////////////////////////////////////////

    
    row = sheet.createRow(1); //////////////////////////
    cell = row.createCell(1, Cell.CELL_TYPE_STRING);
    cell.setCellValue("機能名");
    
    cell = row.createCell(5, Cell.CELL_TYPE_STRING);
    cell.setCellValue(s(api.getName()));
    
    cell = row.createCell(22, Cell.CELL_TYPE_STRING);
    cell.setCellValue("文字コード");
    
    cell = row.createCell(25, Cell.CELL_TYPE_STRING);
    cell.setCellValue("TUF-8");
    
    row = sheet.createRow(2); //////////////////////////
    cell = row.createCell(1, Cell.CELL_TYPE_STRING);
    cell.setCellValue("URL");		
    cell = row.createCell(5, Cell.CELL_TYPE_STRING);
    cell.setCellValue(s(api.getPath()));

    cell = row.createCell(15, Cell.CELL_TYPE_STRING);
    cell.setCellValue("メソッド");
    cell = row.createCell(18, Cell.CELL_TYPE_STRING);
    cell.setCellValue("");
}
 
开发者ID:azuki-framework,项目名称:azuki-doclet-jaxrs,代码行数:34,代码来源:JAXRSXlsxDocletWriter.java

示例15: writeExcel

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
public void writeExcel(File file) {
    //Blank workbook
    XSSFWorkbook workbook = new XSSFWorkbook();

    //Create a blank sheet
    XSSFSheet sheet = workbook.createSheet("Employee Data");

    //This data needs to be written (Object[])
    Map<String, Object[]> data = new TreeMap<String, Object[]>();
    data.put("1", new Object[] {"ID", "NAME", "LASTNAME"});
    data.put("2", new Object[] {1, "Amit", "Shukla"});
    data.put("3", new Object[] {2, "Lokesh", "Gupta"});
    data.put("4", new Object[] {3, "John", "Adwards"});
    data.put("5", new Object[] {4, "Brian", "Schultz"});

    //Iterate over data and write to sheet
    Set<String> keyset = data.keySet();
    int rownum = 0;
    for (String key : keyset) {
        Row row = sheet.createRow(rownum++);
        Object[] objArr = data.get(key);
        int cellnum = 0;
        for (Object obj : objArr)
        {
            Cell cell = row.createCell(cellnum++);
            if (obj instanceof String)
                cell.setCellValue((String)obj);
            else if (obj instanceof Integer)
                cell.setCellValue((Integer)obj);
        }
    }
    try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
        //Write the workbook in file system
        workbook.write(fileOutputStream);
        logger.debug("{} written successfully on disk.", file.getPath());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:iandmyhand,项目名称:java-library-tester,代码行数:40,代码来源:ExcelHandler.java


注:本文中的org.apache.poi.xssf.usermodel.XSSFSheet.createRow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。