本文整理汇总了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;
}
示例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!");
}
}
}