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