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


Java HSSFCell.setCellType方法代碼示例

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


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

示例1: parseBooleanCell

import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
private boolean parseBooleanCell(HSSFCell cell) {
if (cell != null) {
    String value;
    try {
	cell.setCellType(Cell.CELL_TYPE_STRING);
	if (cell.getStringCellValue() != null) {
	    if (cell.getStringCellValue().trim().length() != 0) {
		emptyRow = false;
	    }
	} else {
	    return false;
	}
	value = cell.getStringCellValue().trim();
    } catch (Exception e) {
	cell.setCellType(Cell.CELL_TYPE_NUMERIC);
	double d = cell.getNumericCellValue();
	emptyRow = false;
	value = new Long(new Double(d).longValue()).toString();
    }
    if (StringUtils.equals(value, "1") || StringUtils.equalsIgnoreCase(value, "true")) {
	return true;
    }
}
return false;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:ImportService.java

示例2: parseStringCell

import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
private String parseStringCell(HSSFCell cell) {
if (cell != null) {
    try {
	cell.setCellType(Cell.CELL_TYPE_STRING);
	if (cell.getStringCellValue() != null) {
	    if (cell.getStringCellValue().trim().length() != 0) {
		emptyRow = false;
	    }
	} else {
	    return null;
	}
	// log.debug("string cell value: '"+cell.getStringCellValue().trim()+"'");
	return cell.getStringCellValue().trim();
    } catch (Exception e) {
	cell.setCellType(Cell.CELL_TYPE_NUMERIC);
	double d = cell.getNumericCellValue();
	emptyRow = false;
	// log.debug("numeric cell value: '"+d+"'");
	return (new Long(new Double(d).longValue()).toString());
    }
}
return null;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:ImportService.java

示例3: writeCell

import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
/**
    * Write the value to the cell. Override this method if you have complex data types that may need to be exported.
    * @param value the value of the cell
    * @param cell the cell to write it to
    */
protected void writeCell(Object value, HSSFCell cell, HSSFWorkbook wb)
   {
       if (value instanceof Number)
       {
           Number num = (Number) value;
           cell.setCellValue(num.doubleValue());
       }
       else if (value instanceof Date)
       {
       	HSSFCellStyle cellStyle = wb.createCellStyle();
	    cellStyle.setDataFormat(
	    		wb.getCreationHelper().createDataFormat().getFormat("dd/MM/yyyy HH:mm"));
	    cell.setCellStyle(cellStyle);
		cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
           cell.setCellValue((Date) value);
       }
       else if (value instanceof Calendar)
       {
           cell.setCellValue((Calendar) value);
       }
       else
       {
           cell.setCellValue(new HSSFRichTextString(escapeColumnValue(value)));
       }
   }
 
開發者ID:GovernIB,項目名稱:helium,代碼行數:31,代碼來源:HeliumHssfExportView.java

示例4: getBook

import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
private HSSFWorkbook getBook() {
    HSSFWorkbook book = new HSSFWorkbook();
    int i = 0;
    for (Entry<String, TextSheet> x : this.sheets.entrySet()) {
        HSSFSheet sheet = book.createSheet();
        book.setSheetName(i, x.getKey());
        List<HashMap<String, String>> rows = x.getValue().getRows();
        for (int k = 0; k < rows.size(); k++) {
            HSSFRow row = sheet.createRow(k);
            HashMap<String, String> c = rows.get(k);
            int n = 0;
            for (Entry<String, String> d : c.entrySet()) {
                HSSFCell cell = row.createCell((short) n);
                cell.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell.setCellValue(d.getValue().toString());
                n++;
            }
        }
        i++;
    }
    return book;
}
 
開發者ID:hou80houzhu,項目名稱:rocserver,代碼行數:23,代碼來源:JTextExcel.java

示例5: parseStringCell

import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
private String parseStringCell(HSSFCell cell) {
if (cell != null) {
    cell.setCellType(Cell.CELL_TYPE_STRING);
    if (cell.getStringCellValue() != null) {
	return cell.getStringCellValue().trim();
    }
}
return null;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:GroupingUploadAJAXAction.java

示例6: setCell

import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
/**
 * 設置單元格
 * 
 * @param index
 *            列號
 * @param value
 *            單元格填充值
 */
public void setCell(int index, double value) {
	HSSFCell cell = this.row.createCell((short) index);
	cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
	cell.setCellValue(value);
	HSSFCellStyle cellStyle = workbook.createCellStyle(); // 建立新的cell樣式
	HSSFDataFormat format = workbook.createDataFormat();
	cellStyle.setDataFormat(format.getFormat(NUMBER_FORMAT)); // 設置cell樣式為定製的浮點數格式
	cell.setCellStyle(cellStyle); // 設置該cell浮點數的顯示格式
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:18,代碼來源:XLSExportUtil.java

示例7: getCellStringValue

import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
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;
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:31,代碼來源:ReadExcelUtil.java

示例8: get

import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
public String get(int sheetIndex, int x_index, int y_index) {
    String str = "";
    try {
        if (wb == null) throw new Exception("未打開文件");
        HSSFCell cell = wb.getSheetAt(sheetIndex).getRow(x_index).getCell(y_index);
        cell.setCellType(Cell.CELL_TYPE_STRING);//處理讀取xls時 單元格使用各類函數的數據讀取問題
        str = cell.getStringCellValue();
    } catch (Exception e) {
        logger.error(e.getMessage());
    }
    return str;
}
 
開發者ID:BetaSummer,項目名稱:sztw,代碼行數:13,代碼來源:HSSF.java

示例9: copyCell

import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
/**
 * @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;
    }

}
 
開發者ID:likelet,項目名稱:DAtools,代碼行數:45,代碼來源:Util.java

示例10: createcsv

import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
/**
 * 創建cell,並且寫cell數據
 * @param row : 行下標
 * @param index :列下標
 * @param value : 列值
 * @param cellStyle : 列樣式
 */
@SuppressWarnings("deprecation")
public static void createcsv(HSSFRow row, short index, String value,
		HSSFCellStyle cellStyle) {
	// 創建單元格(左上端)
	HSSFCell cell = row.createCell(index);
	// 定義單元格為字符串類型
	cell.setCellType(HSSFCell.CELL_TYPE_STRING);
	// 設置cell編碼解決中文高位字節截斷
	// cell.setEncoding(HSSFCell.ENCODING_UTF_16);
	// 格式
	cell.setCellStyle(cellStyle);
	// 在單元格中輸入一些內容
	cell.setCellValue(value);
}
 
開發者ID:wufeisoft,項目名稱:data,代碼行數:22,代碼來源:CreateExcelUtil.java

示例11: writeToCell

import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
protected static void writeToCell(HSSFSheet sheet, int row, int col, String value, HSSFCellStyle style) {
		final HSSFCell xlsCell = getCell(sheet, row, col, true);
		xlsCell.setCellType(HSSFCell.CELL_TYPE_STRING);
//		xlsCell.setEncoding(HSSFCell.ENCODING_UTF_16);
//		xlsCell.setCellValue(new String(value.getBytes(CHARSET_UTF_16), CHARSET_UTF_16));
		xlsCell.setCellValue(new HSSFRichTextString(value));
		if (style != null) {
			xlsCell.setCellStyle(style);
		}
	}
 
開發者ID:mpgerstl,項目名稱:tEFMA,代碼行數:11,代碼來源:ExcelGenerator.java

示例12: manageString

import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
private String manageString(PreparedStatement ps, PreparedStatement psUpdate, int lfdCol, HSSFCell cell, LinkedHashMap<Object, String> hashBL) throws SQLException {
	String result = null;
	if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
		if (ps != null) ps.setNull(lfdCol, java.sql.Types.VARCHAR);
		if (psUpdate != null) psUpdate.setNull(lfdCol, java.sql.Types.VARCHAR);
	} else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
		result = cell.getStringCellValue().trim();
		if (ps != null) ps.setString(lfdCol, result);
		if (psUpdate != null) psUpdate.setString(lfdCol, result);
	} else {
		result = cell.getStringCellValue().trim();
		if (hashBL != null) {
			int val, min = 1000;
			String newResult = result;
			for (Object o : hashBL.keySet()) {
				val = Levenshtein.LD(result, o.toString());
				if (val < min) {
					min = val;
					newResult = o.toString();
				}
			}
			if (!newResult.equals(result)) {
				if (DBKernel.debug) MyLogger.handleMessage("Levenshtein - not equal ... " + newResult + "\t" + result);
				result = newResult;
			}
		}
		if (ps != null) ps.setString(lfdCol, result);
		if (psUpdate != null) psUpdate.setString(lfdCol, result);
	}
	//ps.setNull(lfdCol, java.sql.Types.VARCHAR);		
	if (result != null && result.equals("[email protected]")) {
		MyLogger.handleMessage(result);
	}
	return result;
}
 
開發者ID:SiLeBAT,項目名稱:BfROpenLab,代碼行數:37,代碼來源:GeneralXLSImporter.java

示例13: createTableHeader

import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
public void createTableHeader(String[] tableHeader) {
	HSSFHeader header = sheet.getHeader();
	header.setCenter("人員權限信息"); // 
	HSSFRow headerRow = sheet.createRow((short) 0);
	for (int i = 0; i < tableHeader.length; i++) {
		HSSFCell headerCell = headerRow.createCell((short) i);
		headerCell.setCellType(HSSFCell.CELL_TYPE_STRING);
		/*headerCell.setEncoding(HSSFCell.ENCODING_UTF_16);*/       //removed by zhuqingxiang
		headerCell.setCellValue(tableHeader[i]);
	}
}
 
開發者ID:wangzijian777,項目名稱:contentManager,代碼行數:13,代碼來源:WriteExcel.java

示例14: copyCell

import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
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;  
    }  
      
}
 
開發者ID:rmage,項目名稱:gnvc-ims,代碼行數:40,代碼來源:MultiPageReportModel.java

示例15: copyRow

import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
public static void copyRow(final HSSFSheet oldSheet, final HSSFSheet newSheet, final int oldRowNum, final int newRowNum) {
    final HSSFRow oldRow = oldSheet.getRow(oldRowNum);

    final HSSFRow newRow = newSheet.createRow(newRowNum);

    if (oldRow == null) {
        return;
    }

    newRow.setHeight(oldRow.getHeight());

    if (oldRow.getFirstCellNum() == -1) {
        return;
    }

    for (int colNum = oldRow.getFirstCellNum(); colNum <= oldRow.getLastCellNum(); colNum++) {
        final HSSFCell oldCell = oldRow.getCell(colNum);
        final HSSFCell newCell = newRow.createCell(colNum);

        if (oldCell != null) {
            final HSSFCellStyle style = oldCell.getCellStyle();
            newCell.setCellStyle(style);

            final int cellType = oldCell.getCellType();
            newCell.setCellType(cellType);

            if (cellType == Cell.CELL_TYPE_BOOLEAN) {
                newCell.setCellValue(oldCell.getBooleanCellValue());

            } else if (cellType == Cell.CELL_TYPE_FORMULA) {
                newCell.setCellFormula(oldCell.getCellFormula());

            } else if (cellType == Cell.CELL_TYPE_NUMERIC) {
                newCell.setCellValue(oldCell.getNumericCellValue());

            } else if (cellType == Cell.CELL_TYPE_STRING) {
                newCell.setCellValue(oldCell.getRichStringCellValue());
            }
        }
    }

    POIUtils.copyMergedRegion(newSheet, getMergedRegionList(oldSheet, oldRowNum), newRowNum);
}
 
開發者ID:roundrop,項目名稱:ermasterr,代碼行數:44,代碼來源:POIUtils.java


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