當前位置: 首頁>>代碼示例>>Java>>正文


Java Sheet.getRow方法代碼示例

本文整理匯總了Java中org.apache.poi.ss.usermodel.Sheet.getRow方法的典型用法代碼示例。如果您正苦於以下問題:Java Sheet.getRow方法的具體用法?Java Sheet.getRow怎麽用?Java Sheet.getRow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.poi.ss.usermodel.Sheet的用法示例。


在下文中一共展示了Sheet.getRow方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readExcel

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
public static List<String[]> readExcel(InputStream is, int sheetIndex) throws Exception {
	Workbook workbook = WorkbookFactory.create(is);
	Sheet sheet = workbook.getSheetAt(sheetIndex);
	List<String[]> data = new ArrayList<>();
	for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
		Row row = sheet.getRow(i);
		if (row == null) continue;
		int last = row.getLastCellNum();
		String[] rowData = new String[last];
		for (int j = 0; j < last; j++) {
			Cell cell = row.getCell(j);
			rowData[j] = cell == null ? null : getCellString(cell);
		}
		data.add(rowData);
	}
	return data;
}
 
開發者ID:21ca,項目名稱:selenium-testng-template,代碼行數:18,代碼來源:FileUtils.java

示例2: createHeadNameList

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/** 獲取表頭名
 * @param sheet
 * @param headRow
 * @return
 */
private static List<String> createHeadNameList(Sheet sheet ,int headRow){
	List<String> headNameList;
	Row row;
	int cellCount;
	Cell cell;
	try {
		row = sheet.getRow(headRow);
		cellCount = row.getPhysicalNumberOfCells();
		headNameList = new ArrayList<String>();
		cell = null;
		for(int i = 0 ; i < cellCount ; i++){
			cell = row.getCell(i);
			headNameList.add(cell.getStringCellValue());			
		}
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
	return headNameList;
}
 
開發者ID:long47964,項目名稱:excel-utils,代碼行數:26,代碼來源:ExcelImportUtil.java

示例3: readLine

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public String[] readLine(int line, boolean readResult) throws TechnicalException {
    final Sheet sheet = workbook.getSheetAt(0);
    final Row row = sheet.getRow(line);
    if (row == null || "".equals(readCell(row.getCell(0)))) {
        return null;
    } else {
        final String[] ret = readResult ? new String[columns.size()] : new String[columns.size() - 1];
        Cell cell;
        for (int i = 0; i < ret.length; i++) {
            if ((cell = row.getCell(i)) == null) {
                ret[i] = "";
            } else {
                ret[i] = readCell(cell);
            }
        }
        return ret;
    }
}
 
開發者ID:NoraUi,項目名稱:NoraUi,代碼行數:23,代碼來源:ExcelDataProvider.java

示例4: writeTitlePageHeader

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/**
 * 按報表模板格式寫分頁頁眉標題
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-06-25
 * @version     v1.0
 *
 * @param i_DataWorkbook   數據工作薄
 * @param i_DataSheet      數據工作表
 * @param io_RTotal        將數據寫入Excel時的輔助統計信息
 * @param io_RSystemValue  係統變量信息
 * @param i_Datas          數據
 * @param i_RTemplate      報表模板對象
 */
public final static void writeTitlePageHeader(RWorkbook i_DataWorkbook ,Sheet i_DataSheet ,RTotal io_RTotal ,RSystemValue io_RSystemValue ,Object i_Datas ,RTemplate i_RTemplate) 
{
    Sheet v_TemplateSheet    = i_RTemplate.getTemplateSheet();
    int   v_TemplateRowCount = io_RTotal.getTitlePageHeaderCount();
    int   v_ExcelRowIndex    = io_RTotal.getExcelRowIndex();

    copyMergedRegionsTitlePageHeader(i_RTemplate ,i_DataSheet ,io_RTotal);  // 按模板合並單元格
    copyImagesTitlePageHeader(       i_RTemplate ,i_DataSheet ,io_RTotal);  // 按模板複製圖片
    
    io_RSystemValue.setPageNo(io_RSystemValue.getPageNo() + 1);
    
    for (int v_RowNo=0; v_RowNo<v_TemplateRowCount; v_RowNo++)
    {
        int v_TemplateRowNo = i_RTemplate.getTitlePageHeaderBeginRow() + v_RowNo;
        Row v_TemplateRow   = v_TemplateSheet.getRow(v_TemplateRowNo);
        
        int v_DataRowNo = v_RowNo + v_ExcelRowIndex;
        Row v_DataRow   = i_DataSheet.createRow(v_DataRowNo);
        io_RTotal.addExcelRowIndex(1);
        
        copyRow(i_RTemplate ,v_TemplateRow ,i_DataWorkbook ,io_RTotal ,io_RSystemValue ,v_DataRow ,i_Datas);
    }
}
 
開發者ID:HY-ZhengWei,項目名稱:hy.common.report,代碼行數:38,代碼來源:JavaToExcel.java

示例5: writeTitle

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/**
 * 按報表模板格式寫標題
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-03-17
 * @version     v1.0
 *
 * @param i_DataWorkbook  數據工作薄
 * @param i_DataSheet     數據工作表
 * @param io_RTotal       將數據寫入Excel時的輔助統計信息
 * @param io_RSystemValue 係統變量信息
 * @param i_Datas         數據
 * @param i_RTemplate     報表模板對象
 */
public final static void writeTitle(RWorkbook i_DataWorkbook ,Sheet i_DataSheet ,RTotal io_RTotal ,RSystemValue io_RSystemValue ,Object i_Datas ,RTemplate i_RTemplate) 
{
    Sheet v_TemplateSheet    = i_RTemplate.getTemplateSheet();
    int   v_TemplateRowCount = i_RTemplate.getRowCountTitle();
    int   v_ExcelRowIndex    = io_RTotal.getExcelRowIndex();

    copyMergedRegionsTitle(i_RTemplate ,i_DataSheet ,io_RTotal);  // 按模板合並單元格
    copyImagesTitle(       i_RTemplate ,i_DataSheet ,io_RTotal);  // 按模板複製圖片
    
    for (int v_RowNo=0; v_RowNo<v_TemplateRowCount; v_RowNo++)
    {
        int v_TemplateRowNo = i_RTemplate.getTitleBeginRow() + v_RowNo;
        Row v_TemplateRow   = v_TemplateSheet.getRow(v_TemplateRowNo);
        
        int v_DataRowNo = v_RowNo + v_ExcelRowIndex;
        Row v_DataRow   = i_DataSheet.createRow(v_DataRowNo);
        io_RTotal.addExcelRowIndex(1);
        
        copyRow(i_RTemplate ,v_TemplateRow ,i_DataWorkbook ,io_RTotal ,io_RSystemValue ,v_DataRow ,i_Datas);
    }
}
 
開發者ID:HY-ZhengWei,項目名稱:hy.common.report,代碼行數:36,代碼來源:JavaToExcel.java

示例6: writeDataByBlankSpace

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/**
 * 按報表模板格式寫入“空白”數據
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-07-03
 * @version     v1.0
 *
 * @param i_DataWorkbook   數據工作薄
 * @param i_DataSheet      數據工作表
 * @param io_RTotal        將數據寫入Excel時的輔助統計信息
 * @param io_RSystemValue  係統變量信息
 * @param i_Datas          數據
 * @param i_RTemplate      報表模板對象
 */
public final static void writeDataByBlankSpace(RWorkbook i_DataWorkbook ,Sheet i_DataSheet ,RTotal io_RTotal ,RSystemValue io_RSystemValue, RTemplate i_RTemplate) 
{
    Sheet v_TemplateSheet    = i_RTemplate.getTemplateSheet();
    int   v_TemplateRowCount = i_RTemplate.getRowCountData();
    int   v_ExcelRowIndex    = io_RTotal.getExcelRowIndex();
    
    copyMergedRegionsData(i_RTemplate ,i_DataSheet ,io_RTotal);  // 按模板合並單元格
    copyImagesData(       i_RTemplate ,i_DataSheet ,io_RTotal);  // 按模板複製圖片
    
    for (int v_RowNo=0; v_RowNo<v_TemplateRowCount; v_RowNo++) 
    {
        int v_TemplateRowNo = i_RTemplate.getDataBeginRow() + v_RowNo;
        Row v_TemplateRow   = v_TemplateSheet.getRow(v_TemplateRowNo);
        
        int v_DataRowNo = v_RowNo + v_ExcelRowIndex;
        Row v_DataRow   = i_DataSheet.createRow(v_DataRowNo);
        io_RTotal.addExcelRowIndex(1);
        
        copyRowByBlankSpace(i_RTemplate ,v_TemplateRow ,i_DataWorkbook ,io_RTotal ,io_RSystemValue ,v_DataRow);
    }
}
 
開發者ID:HY-ZhengWei,項目名稱:hy.common.report,代碼行數:36,代碼來源:JavaToExcel.java

示例7: readFirstRow

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
private static List<String> readFirstRow(Sheet sheet)
        throws TranslationImportException, ValidationException {
    List<String> localeStringList = new ArrayList<String>();
    Row row = sheet.getRow(0);
    if (row != null) {
        int colIdx = 1; // skip the first col it contains the keys
        String localeString = "";
        while (true) {
            localeString = getCellValue(row, colIdx++, true);
            if (localeString == null) {
                break;
            }
            if (StandardLanguage.isStandardLanguage(localeString,
                    StandardLanguage.COLUMN_HEADING_SUFFIX)) {
                localeStringList.add(localeString);
                continue;
            }
            validateLocale(localeString);
            localeString = localeString.toLowerCase();
            localeStringList.add(localeString);
        }
    }
    return localeStringList;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:25,代碼來源:ExcelHandler.java

示例8: getCellValue

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/**
 * 獲取指定單元格的值
 *
 * @param rowNumber  行數,從1開始
 * @param cellNumber 列數,從1開始
 * @return 該單元格的值
 */
public String getCellValue(int rowNumber, int cellNumber) {
    String result;
    checkRowAndCell(rowNumber, cellNumber);
    Sheet sheet = this.workbook.getSheet(this.sheetName);
    Row row = sheet.getRow(--rowNumber);
    Cell cell = row.getCell(--cellNumber);
    switch (cell.getCellTypeEnum()) {
        case BLANK:
            result = cell.getStringCellValue();
            break;
        case BOOLEAN:
            result = String.valueOf(cell.getBooleanCellValue());
            break;
        case ERROR:
            result = String.valueOf(cell.getErrorCellValue());
            break;
        case FORMULA:
            result = cell.getCellFormula();
            break;
        case NUMERIC:
            if (DateUtil.isCellDateFormatted(cell)) {
                result = format.format(cell.getDateCellValue());
            } else {
                result = String.valueOf(cell.getNumericCellValue());
            }
            break;
        case STRING:
            result = cell.getRichStringCellValue().getString();
            break;
        default:
            result = cell.getStringCellValue();
            break;
    }
    return result;
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:43,代碼來源:ExcelReader.java

示例9: writeValue

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/**
 * @param column
 * @param line
 * @param value
 * @param style
 */
private void writeValue(String column, int line, String value, CellStyle style) {
    logger.debug("Writing: [{}] at line [{}] in column [{}]", value, line, column);
    final int colIndex = columns.indexOf(column);
    final Sheet sheet = workbook.getSheetAt(0);
    final Row row = sheet.getRow(line);
    Cell cell = row.getCell(colIndex);
    if (cell != null) {
        row.removeCell(cell);
    }
    cell = row.createCell(colIndex);
    cell.setCellStyle(style);
    cell.setCellValue(value);
    saveOpenExcelFile();
}
 
開發者ID:NoraUi,項目名稱:NoraUi,代碼行數:21,代碼來源:ExcelDataProvider.java

示例10: readStudentValue

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/**
 * 讀取Excel裏麵客戶的信息
 * @param wb
 * @return
 */
private Map<String, Object> readStudentValue(Workbook wb) {
    //得到第一個shell
    Sheet sheet = wb.getSheetAt(0);
    Map<String, Object> modelMap = new HashMap<>();
    //得到Excel的行數
    this.totalRows = sheet.getPhysicalNumberOfRows();
    //得到Excel的列數(前提是有行數)
    if (totalRows >= 1 && sheet.getRow(0) != null) {
        this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
    }
    List<ClassroomEntity> classList = new ArrayList<ClassroomEntity>();
    ClassroomEntity classroom;
    List<ErrorCJson> errorList = new ArrayList<ErrorCJson>();
    ErrorCJson error;
    //循環Excel行數,從第二行開始。標題不入庫
    for (int r = 1; r < totalRows; r++) {
        Row row = sheet.getRow(r);
        if (row == null) continue;
        classroom = new ClassroomEntity();
        //循環Excel的列
        for (int c = 0; c < this.totalCells; c++) {
            Cell cell = row.getCell(c);
            if (null != cell) {
                if (c == 0) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    classroom.setClassroom(cell.getStringCellValue());//教室名
                } else if (c == 1) {
                    classroom.setPeopleNum((int) cell.getNumericCellValue());//教室容量
                }

            }
        }
        System.out.println(classroom);
        if (classroom.getClassroom() != null && classroom.getPeopleNum() >=0 && classroom.getPeopleNum() <1000 ) {
            classList.add(classroom);
        }else if(classroom.getPeopleNum() <0 && classroom.getPeopleNum() >1000){
            error = new ErrorCJson();
            error.setCourseId(classroom.getClassroom());
            error.setErrors("教室容量過小或過大");
        }
    }
    modelMap.put("result", classList);
    modelMap.put("error", errorList);
    return modelMap;
}
 
開發者ID:junrui-zhao,項目名稱:Educational-Management-System,代碼行數:51,代碼來源:ReadRExcel.java

示例11: readInfoValue

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/**
 * 讀取Excel裏麵客戶的信息
 * @param wb
 * @return
 */
private Map<String, Object> readInfoValue(Workbook wb) {
    //得到第一個shell
    Sheet sheet = wb.getSheetAt(0);
    Map<String, Object> modelMap = new HashMap<>();
    //得到Excel的行數
    this.totalRows = sheet.getPhysicalNumberOfRows();
    //得到Excel的列數(前提是有行數)
    if (totalRows >= 1 && sheet.getRow(0) != null) {
        this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
    }
    List<InfoEntity> infoList = new ArrayList<InfoEntity>();
    InfoEntity info;
    List<ErrorJson> errorList = new ArrayList<ErrorJson>();
    ErrorJson error;
    //循環Excel行數,從第二行開始。標題不入庫
    for (int r = 1; r < totalRows; r++) {
        Row row = sheet.getRow(r);
        if (row == null) continue;
        info = new InfoEntity();
        //循環Excel的列
        for (int c = 0; c < this.totalCells; c++) {
            Cell cell = row.getCell(c);
            if (null != cell) {
                if (c == 0) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    info.setTitle(cell.getStringCellValue());//title

                } else if (c == 1) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    info.setContext(cell.getStringCellValue());//context
                } else if (c == 2) {
                    Date ti =new Date();
                    Timestamp time = new Timestamp(ti.getTime());
                    info.setTime(time);//time
                } else if (c == 3) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    info.setSender(cell.getStringCellValue());//sender
                }
                else if (c == 4) {
                    info.setStudentId((int) cell.getNumericCellValue());//學號

                }

            }
        }
        //添加學生
        System.out.println(info);
        if (info.getStudentId()!=0&&info.getTitle()!=""&&info.getContext()!=""&&info.getTime()!=null&&info.getSender()!="") {
            infoList.add(info);
        } else if (info.getStudentId()==0) {
            error = new ErrorJson();
            error.setId(info.getId());
            error.setErrors("學號不能為空");
            errorList.add(error);
        } else if ( info.getTitle()=="") {
            error = new ErrorJson();
            error.setId(info.getId());
            error.setErrors("title不能為空");
            errorList.add(error);
        } else if (info.getId() != 0 && info.getContext() == "") {
            error = new ErrorJson();
            error.setId(info.getId());
            error.setErrors("內容不能為空");
            errorList.add(error);
        } else if (info.getId() != 0 && info.getSender() == "") {
            error = new ErrorJson();
            error.setId(info.getId());
            error.setErrors("發送者不能為空");
            errorList.add(error);
        }
    }
    modelMap.put("result", infoList);
    modelMap.put("error", errorList);
    return modelMap;
}
 
開發者ID:junrui-zhao,項目名稱:Educational-Management-System,代碼行數:81,代碼來源:ReadInfoExcel.java

示例12: writeCell

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/**
 * @param row 0-based index
 * @param column 0-based index
 */
public static void writeCell(Sheet sheet, int row, int column, String value) {
    Row r = sheet.getRow(row);
    if (r == null) {
        r = sheet.createRow(row);
    }
    Cell cell = r.getCell(column);
    if (cell == null) {
        cell = r.createCell(column, Cell.CELL_TYPE_STRING);
    }
    cell.setCellValue(value);
}
 
開發者ID:pascalgn,項目名稱:jiracli,代碼行數:16,代碼來源:ExcelUtils.java

示例13: writeDataPageHeader

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/**
 * 按報表模板格式寫入數據(支持分頁頁眉)
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-06-25
 * @version     v1.0
 *
 * @param i_DataWorkbook   數據工作薄
 * @param i_DataSheet      數據工作表
 * @param io_RTotal        將數據寫入Excel時的輔助統計信息
 * @param io_RSystemValue  係統變量信息
 * @param i_Datas          數據
 * @param i_RTemplate      報表模板對象
 */
public final static void writeDataPageHeader(RWorkbook i_DataWorkbook ,Sheet i_DataSheet ,RTotal io_RTotal ,RSystemValue io_RSystemValue, Object i_Datas ,RTemplate i_RTemplate) 
{
    Sheet v_TemplateSheet    = i_RTemplate.getTemplateSheet();
    int   v_TemplateRowCount = i_RTemplate.getRowCountData();
    int   v_ExcelRowIndex    = io_RTotal.getExcelRowIndex();
    int   v_PageIndex        = (io_RTotal.getRealDataCount() + io_RTotal.getTitleCount() * i_RTemplate.getTitleRatio() - i_RTemplate.getTitlePageHeaderRate()) % i_RTemplate.getPerPageRowSize();
    
    // 創建分頁頁眉。模板的"行(可對應Excel中的多行)"按一個不可再被分割的整體對待,固沒有寫在下麵的For語句中。
    if ( v_PageIndex == 0 || io_RTotal.getRealDataCount() == i_RTemplate.getTitlePageHeaderFirstWriteByRealDataCount() )
    {
        writeTitlePageHeader(i_DataWorkbook ,i_DataSheet ,io_RTotal ,io_RSystemValue ,i_Datas ,i_RTemplate);
        v_ExcelRowIndex += io_RTotal.getTitlePageHeaderCount();
    }
    
    copyMergedRegionsData(i_RTemplate ,i_DataSheet ,io_RTotal);  // 按模板合並單元格
    copyImagesData(       i_RTemplate ,i_DataSheet ,io_RTotal);  // 按模板複製圖片
    
    for (int v_RowNo=0; v_RowNo<v_TemplateRowCount; v_RowNo++) 
    {
        int v_TemplateRowNo = i_RTemplate.getDataBeginRow() + v_RowNo;
        Row v_TemplateRow   = v_TemplateSheet.getRow(v_TemplateRowNo);
        
        int v_DataRowNo = v_RowNo + v_ExcelRowIndex;
        Row v_DataRow   = i_DataSheet.createRow(v_DataRowNo);
        io_RTotal.addExcelRowIndex(1);
        io_RTotal.addRealDataCount(1);
        
        copyRowPageHeader(i_RTemplate ,v_TemplateRow ,i_DataWorkbook ,io_RTotal ,io_RSystemValue ,v_DataRow ,i_Datas);
    }
}
 
開發者ID:HY-ZhengWei,項目名稱:hy.common.report,代碼行數:45,代碼來源:JavaToExcel.java

示例14: writeDataPage

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/**
 * 按報表模板格式寫入數據(支持分頁頁眉、分頁頁腳)
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-06-25
 * @version     v1.0
 *
 * @param i_DataWorkbook   數據工作薄
 * @param i_DataSheet      數據工作表
 * @param io_RTotal        將數據寫入Excel時的輔助統計信息
 * @param io_RSystemValue  係統變量信息
 * @param i_Datas          數據
 * @param i_RTemplate      報表模板對象
 */
public final static void writeDataPage(RWorkbook i_DataWorkbook ,Sheet i_DataSheet ,RTotal io_RTotal ,RSystemValue io_RSystemValue, Object i_Datas ,RTemplate i_RTemplate) 
{
    Sheet v_TemplateSheet    = i_RTemplate.getTemplateSheet();
    int   v_TemplateRowCount = i_RTemplate.getRowCountData();
    int   v_ExcelRowIndex    = io_RTotal.getExcelRowIndex();
    int   v_PageIndex        = (io_RTotal.getRealDataCount() + io_RTotal.getTitleCount() * i_RTemplate.getTitleRatio() - i_RTemplate.getTitlePageHeaderRate()) % i_RTemplate.getPerPageRowSize();
    
    // 創建分頁頁眉。模板的"行(可對應Excel中的多行)"按一個不可再被分割的整體對待,固沒有寫在下麵的For語句中。
    if ( v_PageIndex == 0 || io_RTotal.getRealDataCount() == i_RTemplate.getTitlePageHeaderFirstWriteByRealDataCount() )
    {
        writeTitlePageHeader(i_DataWorkbook ,i_DataSheet ,io_RTotal ,io_RSystemValue ,i_Datas ,i_RTemplate);
        v_ExcelRowIndex += io_RTotal.getTitlePageHeaderCount();
    }
    
    copyMergedRegionsData(i_RTemplate ,i_DataSheet ,io_RTotal);  // 按模板合並單元格
    copyImagesData(       i_RTemplate ,i_DataSheet ,io_RTotal);  // 按模板複製圖片
    
    for (int v_RowNo=0; v_RowNo<v_TemplateRowCount; v_RowNo++) 
    {
        int v_TemplateRowNo = i_RTemplate.getDataBeginRow() + v_RowNo;
        Row v_TemplateRow   = v_TemplateSheet.getRow(v_TemplateRowNo);
        
        int v_DataRowNo = v_RowNo + v_ExcelRowIndex;
        Row v_DataRow   = i_DataSheet.createRow(v_DataRowNo);
        io_RTotal.addExcelRowIndex(1);
        io_RTotal.addRealDataCount(1);
        
        copyRowPageFooter(i_RTemplate ,v_TemplateRow ,i_DataWorkbook ,io_RTotal ,io_RSystemValue ,v_DataRow ,i_Datas);
    }
    
    // 創建分頁頁腳。模板的"行(可對應Excel中的多行)"按一個不可再被分割的整體對待,固沒有寫在下麵的For語句中。
    v_PageIndex = (io_RTotal.getRealDataCount() + io_RTotal.getTitleCount() * i_RTemplate.getTitleRatio() - i_RTemplate.getTitlePageHeaderRate()) % i_RTemplate.getPerPageRowSize();
    if ( (v_PageIndex == 0 && io_RTotal.getRealDataCount() >= 1) || io_RTotal.getRealDataCount() == i_RTemplate.getTitlePageHeaderFirstWriteByRealDataCount() )
    {
        writeTitlePageFooter(i_DataWorkbook ,i_DataSheet ,io_RTotal ,io_RSystemValue ,i_Datas ,i_RTemplate);
        v_ExcelRowIndex += io_RTotal.getTitlePageFooterCount();
    }
}
 
開發者ID:HY-ZhengWei,項目名稱:hy.common.report,代碼行數:53,代碼來源:JavaToExcel.java

示例15: loadDataBlock

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/**
 * Parses the test case data (the data between TEST_CASE_START and TEST_CASE_END commented cells) from the
 * excel spreadsheet and loads it into a two-dimensional Object[][] array - workingObjectArray
 */
private void loadDataBlock(
                            Method method ) throws DataProviderException {

    Sheet sheet = excelFileWorkbook.getSheet(this.sheetName);
    if (sheet == null) {
        throw new DataProviderException(UNABLE_TO_LOAD_SHEETS + this.sheetName);
    }

    //Get the starting cell coordinates
    Cell startingCell = getStartingCell(sheet);
    int startCol = startingCell.getColumnIndex();
    int startRow = startingCell.getRowIndex();

    //Get the ending cell coordinates
    Cell endingCell = getEndingCell(sheet);
    int endCol = endingCell.getColumnIndex();
    int endRow = endingCell.getRowIndex();

    if (method.getParameterTypes().length != (endCol - startCol) + 1) {
        throw new DataProviderException(" Expected " + method.getParameterTypes().length
                                        + " parameters in the test method while the table has "
                                        + ( (endCol - startCol) + 1));
    }
    // If the data table is to be returned as a Cartesian product of the rows (the not empty cells)
    if (isMultipliable) {
        makeCartesianProductTable(startCol, startRow, endCol, endRow, sheet, method);
    } else {
        // Initialize the object array
        int columns = endCol - startCol + 1;
        int rows = endRow - startRow + 1;
        this.log.debug(CREATING_DATA_BLOCK + columns + "/" + rows);
        this.workingObjectArray = new Object[rows][columns];

        //Fill the object array iterating the sheet column by column
        for (int col = startCol, parameterIndex = 0; col <= endCol; col++, parameterIndex++) {

            //Get the type of the method parameter at the current position
            Class<?> parameterType = getParameterTypeAt(method, parameterIndex);

            //Iterate over the current column to load the cells according to the parameter type
            for (int row = startRow; row <= endRow; row++) {
                Row rowValue = sheet.getRow(row);
                if (rowValue != null) {
                    Cell currentCell = rowValue.getCell(col, Row.CREATE_NULL_AS_BLANK);
                    this.workingObjectArray[row - startRow][parameterIndex] = parseCellContents(currentCell,
                                                                                                parameterType);
                }
            }
        }
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:56,代碼來源:ExcelParser.java


注:本文中的org.apache.poi.ss.usermodel.Sheet.getRow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。