本文整理匯總了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;
}
示例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;
}
示例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)));
}
}
示例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;
}
示例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;
}
示例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浮點數的顯示格式
}
示例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;
}
示例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;
}
示例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;
}
}
示例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);
}
示例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);
}
}
示例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;
}
示例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]);
}
}
示例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;
}
}
示例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);
}