本文整理匯總了Java中org.apache.poi.ss.usermodel.Cell.setCellType方法的典型用法代碼示例。如果您正苦於以下問題:Java Cell.setCellType方法的具體用法?Java Cell.setCellType怎麽用?Java Cell.setCellType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.ss.usermodel.Cell
的用法示例。
在下文中一共展示了Cell.setCellType方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setValue
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
* 設置Cell值
* @param cell
* @param value
*/
public static void setValue(Cell cell,String value){
if(value==null){
cell.setCellType(Cell.CELL_TYPE_BLANK);
}else{
cell.setCellValue(value);
}
}
示例2: fillCellValue
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
public void fillCellValue(Sheet sheet, Row row, Cell cell, Object value) {
if (value != null) {
if (value instanceof Date) {
String result = sdf.format(value);
if (result.endsWith("00:00:00")) {
result = result.substring(0, 11);
}
cell.setCellValue(result);
} else if (value instanceof Double) {
cell.setCellValue((Double) value);
} else if (value instanceof Integer) {
cell.setCellValue((Integer) value);
} else if (value instanceof Byte) {
cell.setCellValue((Byte) value);
} else if (value instanceof Short) {
cell.setCellValue((Short) value);
} else if (value instanceof Boolean) {
cell.setCellValue((Boolean) value);
} else if (value instanceof Long) {
cell.setCellValue((Long) value);
} else if (value instanceof Float) {
cell.setCellValue((Float) value);
} else if (value instanceof BigDecimal) {
double doubleVal = ((BigDecimal) value).doubleValue();
cell.setCellValue(doubleVal);
} else {
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(value.toString());
}
} else {
cell.setCellValue("");
}
}
示例3: addTitleToSheet
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
public int addTitleToSheet(ReportTitle reportTitle, Sheet sheet, int row, int firstCol, int lastCol) {
if (!reportTitle.isShowTitle()) {
return row;
}
Row titleRow = sheet.createRow(row);
Cell titleCell = titleRow.createCell(firstCol);
titleCell.setCellType(Cell.CELL_TYPE_STRING);
titleCell.setCellValue(reportTitle.getTitle());
CellStyle titleStyle = new TitleStyleBuilder().builder(reportTitle, sheet.getWorkbook());
titleCell.setCellStyle(titleStyle);
CellRangeAddress rangle = new CellRangeAddress(row, row, firstCol, lastCol);
sheet.addMergedRegion(rangle);
this.setCellRangeAddressBorder(rangle, sheet);
return row + 1;
}
示例4: readStudentValue
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
* 讀取Excel裏麵客戶的信息
* @param wb
* @return
*/
private Map<String, Object> readStudentValue(Workbook wb) {
//得到第一個shell
Sheet sheet = wb.getSheetAt(0);
Map<String, Object> modelMap = new HashMap<>();
//得到Excel的行數
this.totalRows = sheet.getPhysicalNumberOfRows();
//得到Excel的列數(前提是有行數)
if (totalRows >= 1 && sheet.getRow(0) != null) {
this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
}
List<StudentEntity> studentList = new ArrayList<StudentEntity>();
StudentEntity student;
List<ErrorJson> errorList = new ArrayList<ErrorJson>();
ErrorJson error;
//循環Excel行數,從第二行開始。標題不入庫
for (int r = 1; r < totalRows; r++) {
Row row = sheet.getRow(r);
if (row == null) continue;
student = new StudentEntity();
//循環Excel的列
for (int c = 0; c < this.totalCells; c++) {
Cell cell = row.getCell(c);
if (null != cell) {
if (c == 0) {
student.setStudentId((int) cell.getNumericCellValue());//學號
} else if (c == 1) {
cell.setCellType(Cell.CELL_TYPE_STRING);
student.setStudentName(cell.getStringCellValue());//學生姓名
} else if (c == 2) {
cell.setCellType(Cell.CELL_TYPE_STRING);
student.setClassName(cell.getStringCellValue());//班級
} else if (c == 3) {
cell.setCellType(Cell.CELL_TYPE_STRING);
student.setMajor(cell.getStringCellValue());//專業
}
student.setPassword("00000000");
}
}
//添加學生
System.out.println(student);
if (student.getStudentId() != 0 && student.getStudentName() != "" && student.getClassName() != null && student.getMajor() != "") {
studentList.add(student);
} else if (student.getStudentId() != 0 && student.getStudentName() == "") {
error = new ErrorJson();
error.setId(student.getStudentId());
error.setErrors("名字不能為空");
errorList.add(error);
} else if (student.getStudentId() != 0 && student.getClassName() == null) {
error = new ErrorJson();
error.setId(student.getStudentId());
error.setErrors("班級不能為空");
errorList.add(error);
} else if (student.getStudentId() != 0 && student.getMajor() == "") {
error = new ErrorJson();
error.setId(student.getStudentId());
error.setErrors("專業不能為空");
errorList.add(error);
}
}
modelMap.put("result", studentList);
modelMap.put("error", errorList);
return modelMap;
}
示例5: readStudentValue
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
* 讀取Excel裏麵客戶的信息
* @param wb
* @return
*/
private Map<String, Object> readStudentValue(Workbook wb) {
//得到第一個shell
Sheet sheet = wb.getSheetAt(0);
Map<String, Object> modelMap = new HashMap<>();
//得到Excel的行數
this.totalRows = sheet.getPhysicalNumberOfRows();
//得到Excel的列數(前提是有行數)
if (totalRows >= 1 && sheet.getRow(0) != null) {
this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
}
List<ClassroomEntity> classList = new ArrayList<ClassroomEntity>();
ClassroomEntity classroom;
List<ErrorCJson> errorList = new ArrayList<ErrorCJson>();
ErrorCJson error;
//循環Excel行數,從第二行開始。標題不入庫
for (int r = 1; r < totalRows; r++) {
Row row = sheet.getRow(r);
if (row == null) continue;
classroom = new ClassroomEntity();
//循環Excel的列
for (int c = 0; c < this.totalCells; c++) {
Cell cell = row.getCell(c);
if (null != cell) {
if (c == 0) {
cell.setCellType(Cell.CELL_TYPE_STRING);
classroom.setClassroom(cell.getStringCellValue());//教室名
} else if (c == 1) {
classroom.setPeopleNum((int) cell.getNumericCellValue());//教室容量
}
}
}
System.out.println(classroom);
if (classroom.getClassroom() != null && classroom.getPeopleNum() >=0 && classroom.getPeopleNum() <1000 ) {
classList.add(classroom);
}else if(classroom.getPeopleNum() <0 && classroom.getPeopleNum() >1000){
error = new ErrorCJson();
error.setCourseId(classroom.getClassroom());
error.setErrors("教室容量過小或過大");
}
}
modelMap.put("result", classList);
modelMap.put("error", errorList);
return modelMap;
}
示例6: readInfoValue
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
* 讀取Excel裏麵客戶的信息
* @param wb
* @return
*/
private Map<String, Object> readInfoValue(Workbook wb) {
//得到第一個shell
Sheet sheet = wb.getSheetAt(0);
Map<String, Object> modelMap = new HashMap<>();
//得到Excel的行數
this.totalRows = sheet.getPhysicalNumberOfRows();
//得到Excel的列數(前提是有行數)
if (totalRows >= 1 && sheet.getRow(0) != null) {
this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
}
List<InfoEntity> infoList = new ArrayList<InfoEntity>();
InfoEntity info;
List<ErrorJson> errorList = new ArrayList<ErrorJson>();
ErrorJson error;
//循環Excel行數,從第二行開始。標題不入庫
for (int r = 1; r < totalRows; r++) {
Row row = sheet.getRow(r);
if (row == null) continue;
info = new InfoEntity();
//循環Excel的列
for (int c = 0; c < this.totalCells; c++) {
Cell cell = row.getCell(c);
if (null != cell) {
if (c == 0) {
cell.setCellType(Cell.CELL_TYPE_STRING);
info.setTitle(cell.getStringCellValue());//title
} else if (c == 1) {
cell.setCellType(Cell.CELL_TYPE_STRING);
info.setContext(cell.getStringCellValue());//context
} else if (c == 2) {
Date ti =new Date();
Timestamp time = new Timestamp(ti.getTime());
info.setTime(time);//time
} else if (c == 3) {
cell.setCellType(Cell.CELL_TYPE_STRING);
info.setSender(cell.getStringCellValue());//sender
}
else if (c == 4) {
info.setStudentId((int) cell.getNumericCellValue());//學號
}
}
}
//添加學生
System.out.println(info);
if (info.getStudentId()!=0&&info.getTitle()!=""&&info.getContext()!=""&&info.getTime()!=null&&info.getSender()!="") {
infoList.add(info);
} else if (info.getStudentId()==0) {
error = new ErrorJson();
error.setId(info.getId());
error.setErrors("學號不能為空");
errorList.add(error);
} else if ( info.getTitle()=="") {
error = new ErrorJson();
error.setId(info.getId());
error.setErrors("title不能為空");
errorList.add(error);
} else if (info.getId() != 0 && info.getContext() == "") {
error = new ErrorJson();
error.setId(info.getId());
error.setErrors("內容不能為空");
errorList.add(error);
} else if (info.getId() != 0 && info.getSender() == "") {
error = new ErrorJson();
error.setId(info.getId());
error.setErrors("發送者不能為空");
errorList.add(error);
}
}
modelMap.put("result", infoList);
modelMap.put("error", errorList);
return modelMap;
}
示例7: copyCellByBlankSpace
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
* 複製單位格(空白行的複製,即隻複製格式和固定文字,不填充數據)
*
* @author ZhengWei(HY)
* @createDate 2017-07-03
* @version v1.0
*
* @param i_RTemplate 模板對象
* @param i_TemplateCell 模板中的單元格對象
* @param i_DataWorkbook 數據工作薄
* @param i_DataCell 數據中的單元格對象
* @param io_RSystemValue 係統變量信息
* @param i_Datas 本行對應的數據
* @param io_RValue 小計循環的迭代器
* @return
*/
public final static void copyCellByBlankSpace(RTemplate i_RTemplate ,Cell i_TemplateCell ,RWorkbook i_DataWorkbook ,Cell i_DataCell ,RSystemValue io_RSystemValue)
{
// 複製樣式
i_DataCell.setCellStyle(i_DataWorkbook.getCellStyle(i_RTemplate ,i_TemplateCell.getCellStyle().getIndex()));
// 複製評論
copyComment(i_RTemplate ,i_TemplateCell ,i_DataWorkbook ,i_DataCell);
// 複製數據類型
CellType v_CellType = i_TemplateCell.getCellTypeEnum();
// i_DataCell.setCellType(v_CellType); 不能在此統一設置,原因是:下麵代碼對類型是有浮動的
if ( v_CellType == CellType.NUMERIC )
{
i_DataCell.setCellType(v_CellType);
if ( HSSFDateUtil.isCellDateFormatted(i_TemplateCell) )
{
i_DataCell.setCellValue(i_TemplateCell.getDateCellValue());
}
else
{
i_DataCell.setCellValue(i_TemplateCell.getNumericCellValue());
}
}
else if ( v_CellType == CellType.STRING )
{
RichTextString v_TemplateRichText = i_TemplateCell.getRichStringCellValue();
String v_ValueName = v_TemplateRichText.toString();
if ( i_RTemplate.isExists(v_ValueName) )
{
i_DataCell.setCellType(v_CellType);
i_DataCell.setCellValue("");
}
else
{
i_DataCell.setCellType(v_CellType);
copyRichTextStyle(i_RTemplate ,v_TemplateRichText ,i_DataWorkbook ,i_DataCell);
}
}
else if ( v_CellType == CellType.BOOLEAN )
{
i_DataCell.setCellType(v_CellType);
i_DataCell.setCellValue(i_TemplateCell.getBooleanCellValue());
}
else if ( v_CellType == CellType.FORMULA)
{
i_DataCell.setCellType(v_CellType);
i_DataCell.setCellFormula(i_TemplateCell.getCellFormula());
}
else
{
// Nothing.
i_DataCell.setCellType(v_CellType);
}
}