本文整理汇总了Java中org.apache.poi.ss.usermodel.Cell.setCellValue方法的典型用法代码示例。如果您正苦于以下问题:Java Cell.setCellValue方法的具体用法?Java Cell.setCellValue怎么用?Java Cell.setCellValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.ss.usermodel.Cell
的用法示例。
在下文中一共展示了Cell.setCellValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupTotalCell
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
protected void setupTotalCell(Cell cell, final String propId, final int currentRow, final int startRow, int col) {
cell.setCellStyle(getCellStyle(propId, currentRow, startRow, col, true));
final HorizontalAlignment poiAlignment = getGridHolder().getCellAlignment(propId);
CellUtil.setAlignment(cell, poiAlignment);
Class<?> propType = getGridHolder().getPropertyType(propId);
if (isNumeric(propType)) {
CellRangeAddress cra = new CellRangeAddress(startRow, currentRow - 1, col, col);
if (isHierarchical()) {
// 9 & 109 are for sum. 9 means include hidden cells, 109 means exclude.
// this will show the wrong value if the user expands an outlined category, so
// we will range value it first
cell.setCellFormula("SUM(" + cra.formatAsString(hierarchicalTotalsSheet.getSheetName(),
true) + ")");
} else {
cell.setCellFormula("SUM(" + cra.formatAsString() + ")");
}
} else {
if (0 == col) {
cell.setCellValue(createHelper.createRichTextString("Total"));
}
}
}
示例2: setCellValue
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
private static void setCellValue(Cell cell, Object obj){
if(obj == null){
}else if(obj instanceof String){
cell.setCellValue((String) obj);
}else if(obj instanceof Date){
Date date = (Date) obj;
if(date != null){
cell.setCellValue(DateUtils.dfDateTime.format(date));
}
}else if(obj instanceof Calendar){
Calendar calendar = (Calendar) obj;
if(calendar != null){
cell.setCellValue(DateUtils.dfDateTime.format(calendar.getTime()));
}
}else if(obj instanceof Timestamp){
Timestamp timestamp = (Timestamp) obj;
if(timestamp != null){
cell.setCellValue(DateUtils.dfDateTime.format(new Date(timestamp.getTime())));
}
}else if(obj instanceof Double){
cell.setCellValue((Double) obj);
}else{
cell.setCellValue(obj.toString());
}
}
示例3: createFirstRow
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
private static List<String> createFirstRow(String sheetName,
List<Locale> locales, Sheet sheet, CellStyle styleTitle) {
int colIdx = 0;
Row titleRow = sheet.createRow(0);
sheet.setColumnWidth(colIdx, 30 * 256);
Cell titleCell = titleRow.createCell(colIdx++);
titleCell.setCellStyle(styleTitle);
titleCell.setCellValue(getDefaultResourceBundle().getString(
BaseBean.LABEL_SHOP_TRANSLARIONS_KEY));
return createColumnHeaders(sheetName, locales, sheet, styleTitle,
colIdx, titleRow);
}
示例4: setCellValue
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
protected void setCellValue(Cell sheetCell, Object value, Class<?> valueType, Object propId) {
if (null != value) {
if (!isNumeric(valueType)) {
if (java.util.Date.class.isAssignableFrom(valueType)) {
sheetCell.setCellValue((Date) value);
} else {
sheetCell.setCellValue(createHelper.createRichTextString(value.toString()));
}
} else {
try {
// parse all numbers as double, the format will determine how they appear
final Double d = Double.parseDouble(value.toString());
sheetCell.setCellValue(d);
} catch (final NumberFormatException nfe) {
LOGGER.warning("NumberFormatException parsing a numeric value: " + nfe);
sheetCell.setCellValue(createHelper.createRichTextString(value.toString()));
}
}
}
}
示例5: feedDetailsSheet
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
public void feedDetailsSheet(Sheet sheet, boolean exportAsTemplate, List<XLTestStep> xLTestSteps) {
int index = 0;
for (XLTestStep xLTestStep : xLTestSteps) {
index++;
Row row = sheet.createRow(index);
Cell cell = row.createCell(STEPNAME_INDEX);
cell.setCellValue(xLTestStep.getName());
cell = row.createCell(EXPECTED_OR_ACTION_INDEX);
cell.setCellValue(xLTestStep.getExpected());
cell = row.createCell(RESULT_INDEX);
if (exportAsTemplate)
cell.setCellValue("");
else
cell.setCellValue(xLTestStep.getActual());
cell = row.createCell(STATUS_INDEX);
formatCellStatus(sheet, cell);
if (exportAsTemplate)
cell.setCellValue("");
else
cell.setCellValue(Integer.parseInt(xLTestStep.getStatus()));
}
this.autoSize(sheet, new int[] { 0, 1, 2, 3 });
}
示例6: CreateCell
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
public void CreateCell(Cell c, Row r, Sheet s, CellStyle cs, int colinaI, int colinaF, String valorS, int linhaI, int linhaF) {
c = r.createCell(linhaI);
c.setCellStyle(cs);
c.setCellValue(valorS);
s.addMergedRegion(new CellRangeAddress(colinaI, colinaF, linhaI, linhaF));
for (int e = (linhaI + 1); e <= linhaF; e++) {
c = r.createCell(e);
c.setCellStyle(cs);
}
}
示例7: setCellValue
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
* 给一个Cell赋值,若为空则视为"",若不为基本类型及其包装类(日期类型除外),则其值通过toString()获取
*
* @param cell 一个单元格
* @param value 值
* @return 若此单元格写入空数据则返回true, 否则返回false
*/
private boolean setCellValue(Cell cell, Object value) {
boolean isBlankCell = false;
if (value == null) {
cell.setCellValue("");
isBlankCell = true;
} else if (value instanceof String) {
cell.setCellValue((String) value);
} else if (value instanceof Integer) {
cell.setCellValue((Integer) value);
} else if (value instanceof Date) {
cell.setCellValue(this.dateFormat.format(value));
} else if (value instanceof Calendar) {
cell.setCellValue(this.dateFormat.format(value));
} else if (value instanceof Boolean) {
cell.setCellValue((Boolean) value);
} else if (value instanceof Float) {
cell.setCellValue((Float) value);
} else if (value instanceof Double) {
cell.setCellValue((Double) value);
} else if (value instanceof Byte) {
cell.setCellValue((Byte) value);
} else if (value instanceof Short) {
cell.setCellValue((Short) value);
} else {
cell.setCellValue(value.toString());
}
return isBlankCell;
}
示例8: createCellM
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
public static void createCellM(Cell c, Row r, Sheet s, CellStyle cs, int colinaI, int colinaF, String valorS, int linhaI, int linhaF) {
c = r.createCell(linhaI);
c.setCellStyle(cs);
c.setCellValue(valorS);
s.addMergedRegion(new CellRangeAddress(colinaI, colinaF, linhaI, linhaF));
for (int e = (linhaI + 1); e <= linhaF; e++) {
c = r.createCell(e);
c.setCellStyle(cs);
}
}
示例9: addCell
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
* 添加一个单元格
* @param row 添加的行
* @param column 添加列号
* @param val 添加值
* @param align 对齐方式(1:靠左;2:居中;3:靠右)
* @return 单元格对象
*/
public Cell addCell(Row row, int column, Object val, int align, Class<?> fieldType){
Cell cell = row.createCell(column);
CellStyle style = styles.get("data"+(align>=1&&align<=3?align:""));
try {
if (val == null){
cell.setCellValue("");
} else if (val instanceof String) {
cell.setCellValue((String) val);
} else if (val instanceof Integer) {
cell.setCellValue((Integer) val);
} else if (val instanceof Long) {
cell.setCellValue((Long) val);
} else if (val instanceof Double) {
cell.setCellValue((Double) val);
} else if (val instanceof Float) {
cell.setCellValue((Float) val);
} else if (val instanceof Date) {
DataFormat format = wb.createDataFormat();
style.setDataFormat(format.getFormat("yyyy-MM-dd"));
cell.setCellValue((Date) val);
} else {
if (fieldType != Class.class){
cell.setCellValue((String)fieldType.getMethod("setValue", Object.class).invoke(null, val));
}else{
cell.setCellValue((String)Class.forName(this.getClass().getName().replaceAll(this.getClass().getSimpleName(),
"fieldtype."+val.getClass().getSimpleName()+"Type")).getMethod("setValue", Object.class).invoke(null, val));
}
}
} catch (Exception ex) {
log.info("Set cell value ["+row.getRowNum()+","+column+"] error: " + ex.toString());
cell.setCellValue(val.toString());
}
cell.setCellStyle(style);
return cell;
}
示例10: writeDailyVisits
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
* Takes a two-dimensional array of visits. The first indices represent
* months and the second indices represent days. It writes visits to
* corresponding columns.
* @param dailyVisitCounts - a two dimensional array of visits of size [12][31]
*/
public void writeDailyVisits(int[][] dailyVisitCounts) {
for (int i = 1; i < 32; i++) {
Row row = dailyTimesSheet.createRow(i);
Cell cell = row.createCell(0);
cell.setCellValue(i);
for (int j=0; j < dailyVisitCounts.length; j++) {
cell = row.createCell(j+1);
cell.setCellValue(dailyVisitCounts[j][i-1]);
}
}
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:18,代码来源:CollectedDataWriter.java
示例11: createHeader
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
* Creates the header row for the sheet provided.
*
* @param sheet the sheet to create the header for
* @param langs the languages to use in the header
*/
private void createHeader( Sheet sheet,
Map<Locale, Integer> langs)
{
LOG.info("Create header row with languages " + langs.toString());
CellStyle key = sheet.getWorkbook().createCellStyle();
key.setAlignment(CellStyle.ALIGN_CENTER);
key.setBorderBottom(CellStyle.BORDER_MEDIUM);
key.setBorderRight(CellStyle.BORDER_MEDIUM);
Font f = sheet.getWorkbook().createFont();
f.setBoldweight(Font.BOLDWEIGHT_BOLD);
key.setFont(f);
CellStyle hlang = sheet.getWorkbook().createCellStyle();
hlang.setAlignment(CellStyle.ALIGN_CENTER);
hlang.setBorderBottom(CellStyle.BORDER_MEDIUM);
hlang.setBorderRight(CellStyle.BORDER_THIN);
hlang.setFont(f);
Row row = sheet.createRow(this.languageHeaderRow);
Cell cell = row.createCell(this.keyColumn);
cell.setCellStyle(key);
cell.setCellValue("KEY");
for (Entry<Locale, Integer> lang : langs.entrySet())
{
cell = row.createCell(lang.getValue());
cell.setCellStyle(hlang);
cell.setCellValue(lang.getKey().toString());
}
}
示例12: writeRating
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
* Adds the given information as a new row to the sheet.
* @param id: plant ID number
* @param commonName: common name of flower
* @param cultivar: cultivar name of flower
* @param gardenLocation: bed number of flower
* @param likes: number of likes on the flower
* @param dislikes: number of dislikes on the flower
* @param visits: number of visits on the flower
* @param comments: number of comments on the flower
*/
public void writeRating(String id, String commonName, String cultivar, String gardenLocation, int likes, int dislikes, int visits, int comments){
Row row = ratingsSheet.createRow(ratingCount);
Cell cell = row.createCell(0);
cell.setCellValue(id);
cell = row.createCell(1);
cell.setCellValue(commonName);
cell = row.createCell(2);
cell.setCellValue(cultivar);
cell = row.createCell(3);
cell.setCellValue(gardenLocation);
cell = row.createCell(4);
cell.setCellValue(likes);
cell = row.createCell(5);
cell.setCellValue(dislikes);
cell = row.createCell(6);
cell.setCellValue(visits);
cell = row.createCell(7);
cell.setCellValue(comments);
ratingCount++;
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:41,代码来源:CollectedDataWriter.java
示例13: createHeader
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
private int createHeader(Sheet sheet, int rowNum, String[] titles) {
Row headerRow = sheet.createRow(rowNum);
headerRow.setHeightInPoints(40);
Cell headerCell;
int[] cols = new int[titles.length];
for (int i = 0; i < titles.length; i++) {
cols[i] = i;
headerCell = headerRow.createCell(i);
headerCell.setCellValue(titles[i]);
headerCell.setCellStyle(styles.get("header"));
}
autoSize(sheet, cols);
return rowNum;
}
示例14: createCell
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
public static void createCell(Cell c, Row r, Sheet s, CellStyle cs, int colinaI, int colinaF, String valorS, int linhaI, int linhaF) {
c = r.createCell(linhaI);
c.setCellStyle(cs);
c.setCellValue(valorS);
s.setColumnWidth(linhaI, linhaF*1000);
}
示例15: writeComment
import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
* Adds the given information as a new row to the sheet.
* @param id: plant ID number
* @param comment: comment left by visitor
* @param timestamp: time the user left the comment
*/
public void writeComment(String id, String commonName, String cultivar, String gardenLocation, String comment, Date timestamp){
Row row = commentsSheet.createRow((short) commentCount);
Cell cell = row.createCell(0);
cell.setCellValue(id);
cell = row.createCell(1);
cell.setCellValue(commonName);
cell = row.createCell(2);
cell.setCellValue(cultivar);
cell = row.createCell(3);
cell.setCellValue(gardenLocation);
cell = row.createCell(4);
CellStyle style = workbook.createCellStyle();
style.setWrapText(true);
cell.setCellStyle(style);
cell.setCellValue(comment);
cell = row.createCell(5);
cell.setCellValue(timestamp.toString());
commentCount++;
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:34,代码来源:CollectedDataWriter.java