本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFCell.CELL_TYPE_STRING屬性的典型用法代碼示例。如果您正苦於以下問題:Java HSSFCell.CELL_TYPE_STRING屬性的具體用法?Java HSSFCell.CELL_TYPE_STRING怎麽用?Java HSSFCell.CELL_TYPE_STRING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.apache.poi.hssf.usermodel.HSSFCell
的用法示例。
在下文中一共展示了HSSFCell.CELL_TYPE_STRING屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCellValue
private String getCellValue(HSSFCell cell){
if(cell == null) return "";
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING: return cell.getStringCellValue();
case HSSFCell.CELL_TYPE_BOOLEAN : return Boolean.toString(cell.getBooleanCellValue());
case HSSFCell.CELL_TYPE_NUMERIC :
if(HSSFDateUtil.isCellDateFormatted(cell))
return DateUtils.formatDateTime("yyyyMMdd", HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
else
return new BigDecimal(cell.getNumericCellValue()).toPlainString();
case HSSFCell.CELL_TYPE_FORMULA : return "";
case HSSFCell.CELL_TYPE_BLANK : return "";
default:return "";
}
}
示例2: findColumn
public static Integer findColumn(HSSFRow row, String str) {
for (int colNum = row.getFirstCellNum(); colNum <= row.getLastCellNum(); colNum++) {
HSSFCell cell = row.getCell(colNum);
if (cell == null) {
continue;
}
if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
HSSFRichTextString cellValue = cell.getRichStringCellValue();
if (str.equals(cellValue.getString())) {
return Integer.valueOf(colNum);
}
}
}
return null;
}
示例3: findMatchColumn
public static Integer findMatchColumn(HSSFRow row, String str) {
for (int colNum = row.getFirstCellNum(); colNum <= row.getLastCellNum(); colNum++) {
HSSFCell cell = row.getCell(colNum);
if (cell == null) {
continue;
}
if (cell.getCellType() != HSSFCell.CELL_TYPE_STRING) {
continue;
}
HSSFRichTextString cellValue = cell.getRichStringCellValue();
if (cellValue.getString().matches(str)) {
return Integer.valueOf(colNum);
}
}
return null;
}
示例4: fromHSSFRowtoCSV
private String fromHSSFRowtoCSV(HSSFRow row){
StringBuffer csvRow = new StringBuffer();
int l = row.getLastCellNum();
for (int i=0;i<l;i++){
HSSFCell cell = row.getCell((short)i);
String cellValue = "";
if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
cellValue = "";
} else if (cell.getCellType()== HSSFCell.CELL_TYPE_STRING){
cellValue = "\"" + cell.getStringCellValue() + "\"";
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
double value = cell.getNumericCellValue();
cellValue = getNumberFormat().format(value);
cellValue = "\"" + cellValue + "\"";
}
csvRow.append(cellValue);
if (i<l){
csvRow.append(getCsvDelimiter().toCharArray()[0]);
}
}
return csvRow.toString();
}
示例5: fromXSSFRowtoCSV
private String fromXSSFRowtoCSV(XSSFRow row){
StringBuffer csvRow = new StringBuffer();
int l = row.getLastCellNum();
for (int i=0;i<l;i++){
XSSFCell cell = row.getCell((short)i);
String cellValue = "";
if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
cellValue = "";
} else if (cell.getCellType()== HSSFCell.CELL_TYPE_STRING){
cellValue = "\"" + cell.getStringCellValue() + "\"";
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
double value = cell.getNumericCellValue();
cellValue = getNumberFormat().format(value);
cellValue = "\"" + cellValue + "\"";
}
csvRow.append(cellValue);
if (i<l){
csvRow.append(getCsvDelimiter().toCharArray()[0]);
}
}
return csvRow.toString();
}
示例6: getCellValue
private Object getCellValue(Cell cellObject) {
Object cellValue = null;
if (cellObject != null) {
switch (cellObject.getCellType()) {
case HSSFCell.CELL_TYPE_BOOLEAN:
cellValue = cellObject.getBooleanCellValue();
break;
case HSSFCell.CELL_TYPE_STRING:
cellValue = cellObject.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
if (DateUtil.isCellDateFormatted(cellObject)) {
cellValue = cellObject.getDateCellValue();
} else {
cellValue = cellObject.getNumericCellValue();
}
break;
default:
break;
}
}
return cellValue;
}
示例7: manageInteger
private Integer manageInteger(PreparedStatement ps, PreparedStatement psUpdate, int lfdCol, HSSFCell cell) throws SQLException {
Integer result = null;
if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
if (cell.getStringCellValue().trim().length() > 0) {
result = new Integer(cell.getStringCellValue());
if (ps != null) ps.setInt(lfdCol, result);
if (psUpdate != null) psUpdate.setInt(lfdCol, result);
return result;
}
} else {
result = new Integer((int) cell.getNumericCellValue());
if (ps != null) ps.setInt(lfdCol, result);
if (psUpdate != null) psUpdate.setInt(lfdCol, result);
return result;
}
if (ps != null) ps.setNull(lfdCol, java.sql.Types.INTEGER);
if (psUpdate != null) psUpdate.setNull(lfdCol, java.sql.Types.INTEGER);
return result;
}
示例8: manageBigInteger
private Long manageBigInteger(PreparedStatement ps, PreparedStatement psUpdate, int lfdCol, HSSFCell cell) throws SQLException {
Long result = null;
if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
if (cell.getStringCellValue().trim().length() > 0) {
result = new Long(cell.getStringCellValue());
if (ps != null) ps.setLong(lfdCol, result);
if (psUpdate != null) psUpdate.setLong(lfdCol, result);
return result;
}
} else {
result = new Long((long) cell.getNumericCellValue());
if (ps != null) ps.setLong(lfdCol, result);
if (psUpdate != null) psUpdate.setLong(lfdCol, result);
return result;
}
if (ps != null) ps.setNull(lfdCol, java.sql.Types.BIGINT);
if (psUpdate != null) psUpdate.setNull(lfdCol, java.sql.Types.BIGINT);
return result;
}
示例9: getValueFromCell
/**
* <b>描述:</b> 從單元格中獲取到的數據
* @param cell 單元格對應的HSSFCell對象
* @return Object 從單元格中獲取到的數據
*/
private Object getValueFromCell(HSSFCell cell){
if(cell==null)return "";
switch(cell.getCellType()){
case HSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue();
case HSSFCell.CELL_TYPE_NUMERIC:
return cell.getNumericCellValue();
case HSSFCell.CELL_TYPE_FORMULA:
return cell.getCellFormula();
case HSSFCell.CELL_TYPE_STRING:
return cell.getRichStringCellValue().toString();
default:
return cell.getRichStringCellValue().toString();
}
}
示例10: getCellData
/**
* Get cell value based on the excel column data type
*
* @param myCell
* @return
*/
private static String getCellData(HSSFCell myCell) throws Exception {
String cellData = "";
if (myCell == null) {
cellData += CVS_SEPERATOR_CHAR;;
} else {
switch (myCell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
case HSSFCell.CELL_TYPE_BOOLEAN:
cellData += myCell.getRichStringCellValue() + CVS_SEPERATOR_CHAR;
break;
case HSSFCell.CELL_TYPE_NUMERIC:
cellData += getNumericValue(myCell);
break;
case HSSFCell.CELL_TYPE_FORMULA:
cellData += getFormulaValue(myCell);
default:
cellData += CVS_SEPERATOR_CHAR;
;
}
}
return cellData;
}
示例11: autoWeight
/**
* 自動設置寬度
*
* @param columnNum
*/
public void autoWeight(int columnNum) {
//讓列寬隨著導出的列長自動適應
for (int colNum = 0; colNum < columnNum; colNum++) {
int columnWidth = sheet.getColumnWidth(colNum) / 256;
for (int rowNum = 0; rowNum < sheet.getLastRowNum(); rowNum++) {
Row currentRow;
//當前行未被使用過
if (sheet.getRow(rowNum) == null) {
currentRow = sheet.createRow(rowNum);
} else {
currentRow = sheet.getRow(rowNum);
}
if (currentRow.getCell(colNum) != null) {
Cell currentCell = currentRow.getCell(colNum);
if (currentCell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
int length = currentCell.getStringCellValue().getBytes().length;
if (columnWidth < length) {
columnWidth = length;
}
}
}
}
sheet.setColumnWidth(colNum, (columnWidth + 4) * 256);
}
/**
* 合並標題
*/
if (this.excelTitle != null && this.excelTitle.title != null) {
this.sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, columnNum - 1));
ExcelRow excelRow = this.row(0).cell(0).cellValue(this.excelTitle.title);
excelRow.getRow().setHeightInPoints(30.0F);
if (this.excelTitle.cellStyle != null) {
excelRow.cellStyle(this.excelTitle.cellStyle);
}
}
}
示例12: getCellStringValue
public static String getCellStringValue(HSSFCell cell) {
String cellValue = "";
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
cellValue = cell.getStringCellValue();
if (cellValue.trim().equals("") || cellValue.trim().length() <= 0) {
cellValue = " ";
}
break;
case HSSFCell.CELL_TYPE_NUMERIC:
// cellValue = String.valueOf(cell.getNumericCellValue());
DecimalFormat formatter = new DecimalFormat("######");
cellValue = formatter.format(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cellValue = String.valueOf(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
cellValue = " ";
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
break;
case HSSFCell.CELL_TYPE_ERROR:
break;
default:
break;
}
return cellValue;
}
示例13: copyCell
/**
* @param oldCell
* @param newCell
* @param styleMap
*/
public static void copyCell(HSSFCell oldCell, HSSFCell newCell, Map<Integer, HSSFCellStyle> styleMap) {
if (styleMap != null) {
if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) {
newCell.setCellStyle(oldCell.getCellStyle());
} else {
int stHashCode = oldCell.getCellStyle().hashCode();
HSSFCellStyle newCellStyle = styleMap.get(stHashCode);
if (newCellStyle == null) {
newCellStyle = newCell.getSheet().getWorkbook().createCellStyle();
newCellStyle.cloneStyleFrom(oldCell.getCellStyle());
styleMap.put(stHashCode, newCellStyle);
}
newCell.setCellStyle(newCellStyle);
}
}
switch (oldCell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
newCell.setCellValue(oldCell.getStringCellValue());
break;
case HSSFCell.CELL_TYPE_NUMERIC:
newCell.setCellValue(oldCell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
newCell.setCellType(HSSFCell.CELL_TYPE_BLANK);
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
newCell.setCellValue(oldCell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_ERROR:
newCell.setCellErrorValue(oldCell.getErrorCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
newCell.setCellFormula(oldCell.getCellFormula());
break;
default:
break;
}
}
示例14: getCellFormatValue
/**
* 根據HSSFCell類型設置數據
*
* @param cell
* @return
*/
private String getCellFormatValue(Cell cell) {
String cellvalue = "";
if (cell != null) {
// 判斷當前Cell的Type
switch (cell.getCellType()) {
// 如果當前Cell的Type為NUMERIC
case HSSFCell.CELL_TYPE_NUMERIC:
case HSSFCell.CELL_TYPE_FORMULA: {
// 判斷當前的cell是否為Date
if (HSSFDateUtil.isCellDateFormatted(cell)) {
// 如果是Date類型則,轉化為Data格式
// 方法1:這樣子的data格式是帶時分秒的:2011-10-12 0:00:00
// cellvalue = cell.getDateCellValue().toLocaleString();
// 方法2:這樣子的data格式是不帶帶時分秒的:2011-10-12
Date date = cell.getDateCellValue();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
cellvalue = sdf.format(date);
}
// 如果是純數字
else {
// 取得當前Cell的數值
cellvalue = String.valueOf(cell.getNumericCellValue());
}
break;
}
// 如果當前Cell的Type為STRIN
case HSSFCell.CELL_TYPE_STRING:
// 取得當前的Cell字符串
cellvalue = cell.getRichStringCellValue().getString();
break;
// 默認的Cell值
default:
cellvalue = " ";
}
} else {
cellvalue = "";
}
return cellvalue;
}
示例15: checkCellEntries
private boolean checkCellEntries(Iterator<Cell> cells)
{
boolean type = false;
while (cells.hasNext())
{
HSSFCell cell = (HSSFCell) cells.next();
switch (cell.getCellType())
{
case HSSFCell.CELL_TYPE_NUMERIC:
type = false;
break;
case HSSFCell.CELL_TYPE_STRING:
if (cell.getStringCellValue().length() < 100)
{
type = true;
}
else
{
type = false;
}
break;
default:
type = false;
break;
}
if (!type)
{
return false;
}
}
return true;
}