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


Java Row.getPhysicalNumberOfCells方法代碼示例

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


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

示例1: createHeadNameList

import org.apache.poi.ss.usermodel.Row; //導入方法依賴的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

示例2: createTable

import org.apache.poi.ss.usermodel.Row; //導入方法依賴的package包/類
private void createTable(Sheet sheet) {
    StringBuilder createTableSql = new StringBuilder("CREATE TABLE IF NOT EXISTS ");
    createTableSql.append(sheet.getSheetName());
    createTableSql.append("(");
    Iterator<Row> rit = sheet.rowIterator();
    Row rowHeader = rit.next();
    List<String> columns = new ArrayList<>();
    for (int i = 0; i < rowHeader.getPhysicalNumberOfCells(); i++) {
        createTableSql.append(rowHeader.getCell(i).getStringCellValue());
        if (i == rowHeader.getPhysicalNumberOfCells() - 1) {
            createTableSql.append(" TEXT");
        } else {
            createTableSql.append(" TEXT,");
        }
        columns.add(rowHeader.getCell(i).getStringCellValue());
    }
    createTableSql.append(")");

    if (dropTable)
        database.execSQL("DROP TABLE IF EXISTS " + sheet.getSheetName());

    database.execSQL(createTableSql.toString());

    for (String column : columns) {
        Cursor cursor = database.rawQuery("SELECT * FROM " + sheet.getSheetName(), null); // grab cursor for all data
        int deleteStateColumnIndex = cursor.getColumnIndex(column);  // see if the column is there
        if (deleteStateColumnIndex < 0) {
            String type = "TEXT";
            // missing_column not there - add it
            database.execSQL("ALTER TABLE " + sheet.getSheetName() + " ADD COLUMN " + column + " " + type + " NULL;");
        }
    }

    while (rit.hasNext()) {
        Row row = rit.next();
        ContentValues values = new ContentValues();
        for (int n = 0; n < row.getPhysicalNumberOfCells(); n++) {
            if (row.getCell(n).getCellType() == Cell.CELL_TYPE_NUMERIC) {
                values.put(columns.get(n), row.getCell(n).getNumericCellValue());
            } else {
                values.put(columns.get(n), row.getCell(n).getStringCellValue());
            }
        }
        long result = database.insertWithOnConflict(sheet.getSheetName(), null, values, SQLiteDatabase.CONFLICT_IGNORE);
        if (result < 0) {
            throw new RuntimeException("Insert value failed!");
        }
    }
}
 
開發者ID:androidmads,項目名稱:SQLite2XL,代碼行數:50,代碼來源:ExcelToSQLite.java


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