本文整理汇总了Java中org.apache.poi.ss.usermodel.Row.createCell方法的典型用法代码示例。如果您正苦于以下问题:Java Row.createCell方法的具体用法?Java Row.createCell怎么用?Java Row.createCell使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.ss.usermodel.Row
的用法示例。
在下文中一共展示了Row.createCell方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildSheet
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
private void buildSheet(SXSSFWorkbook wb,VariableCategory vc,XSSFCellStyle style){
String name=vc.getName();
Sheet sheet=wb.createSheet(name);
Row row=sheet.createRow(0);
List<Variable> variables=vc.getVariables();
for(int i=0;i<variables.size();i++){
sheet.setColumnWidth(i,4000);
Cell cell=row.createCell(i);
Variable var=variables.get(i);
cell.setCellValue(var.getLabel());
cell.setCellStyle(style);
}
}
示例2: addTitleToSheet
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的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;
}
示例3: writeTitle
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
/**
* 向当前Sheet第一行(1-based)写入标题,若用户没有开启写入标题总开关(即{@link #isWriteTitle}为false),
* 或者{@link #titles}为空则不会做任何操作
*/
private void writeTitle() {
if (!this.isWriteTitle || this.titles == null || this.titles.isEmpty()) {
return;
}
this.currentRowInSheet++;
Row row = this.currentSheetPO.createRow(this.currentRowInSheet);
row.setHeight(this.rowHeight < 0 ? -1 : this.rowHeight);
for (int i = 0; i < this.titles.size(); i++) {
Cell cell = row.createCell(i);
cell.setCellStyle(this.defaultTitleCellStyle);
cell.setCellValue(this.titles.get(i));
}
this.realRowInSheet++;
this.realRowInExcel++;
}
示例4: feedDetailsSheet
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的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 });
}
示例5: writeDailyVisits
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的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
示例6: createSheetDataRow
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
private static <T> void createSheetDataRow(List<T> dataList, int dataRowNum,
int listStart, int listEnd,ExportInfo exportInfo,
Map<Field, CellStyle> dataCellStyleMap, List<Field> availableFields,Sheet sheet)
throws IllegalAccessException, InvocationTargetException {
Map<Field, ExportFieldInfo> fieldInfoMap = exportInfo.getFieldInfoMap();
Cell cell;
Field field;
Row row;
T obj ;
int dataSize = dataList.size() ;
listEnd = listEnd > dataSize ? dataSize : listEnd ;
int fieldListSize = availableFields.size();
int dataHightInPoint = exportInfo.getDataHightInPoint();
for(int i = listStart ; i < listEnd ; i++ , dataRowNum ++){
obj = dataList.get(i);
row = sheet.createRow(dataRowNum );
row.setHeightInPoints(dataHightInPoint);
for(int j = 0 ; j < fieldListSize ; j++){
field = availableFields.get(j);
if(field == null ){
continue;
}
cell= row.createCell(j);
Object returnVal = obj;
List<Method> methods = fieldInfoMap.get(field).getMethodChain();
for(Method method : methods){
if (returnVal == null) {
continue;
}
returnVal = method.invoke(returnVal);
}
setCellValue(cell, fieldInfoMap.get(field), returnVal, obj);
if(dataCellStyleMap != null && dataCellStyleMap.get(field) != null){
cell.setCellStyle(dataCellStyleMap.get(field));
}
}
}
}
示例7: CreateCell
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的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);
}
}
示例8: writeValue
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
/**
* @param column
* @param line
* @param value
* @param style
*/
private void writeValue(String column, int line, String value, CellStyle style) {
logger.debug("Writing: [{}] at line [{}] in column [{}]", value, line, column);
final int colIndex = columns.indexOf(column);
final Sheet sheet = workbook.getSheetAt(0);
final Row row = sheet.getRow(line);
Cell cell = row.getCell(colIndex);
if (cell != null) {
row.removeCell(cell);
}
cell = row.createCell(colIndex);
cell.setCellStyle(style);
cell.setCellValue(value);
saveOpenExcelFile();
}
示例9: addCell
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的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: createSummaryColumns
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
private void createSummaryColumns(Sheet sheet) {
Row headerRow = sheet.createRow(ROW_INDEX_COLUMNS_DESCRIPTIONS);
headerRow.setHeightInPoints(40);
Cell headerCell;
for (int i = 0; i < titlesSummary.length; i++) {
headerCell = headerRow.createCell(i);
headerCell.setCellValue(titlesSummary[i]);
headerCell.setCellStyle(styles.get("header"));
}
}
示例11: copyRowByBlankSpace
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
/**
* 行复制功能(空白行的复制,即只复制格式和固定文字,不填充数据)
*
* @author ZhengWei(HY)
* @createDate 2017-07-03
* @version v1.0
*
* @param i_RTemplate 模板
* @param i_TemplateRow 模板中的行对象
* @param i_DataWorkbook 数据工作薄
* @param io_RTotal 将数据写入Excel时的辅助统计信息。
* @param io_RSystemValue 系统变量信息
* @param i_DataRow 数据中的行对象
* @param i_Datas 本行对应的数据
*
* @return 返回本方法内一共生成多少新行。
*/
public final static int copyRowByBlankSpace(RTemplate i_RTemplate ,Row i_TemplateRow ,RWorkbook i_DataWorkbook ,RTotal io_RTotal ,RSystemValue io_RSystemValue ,Row i_DataRow)
{
i_DataRow.setHeight( i_TemplateRow.getHeight());
i_DataRow.setZeroHeight(i_TemplateRow.getZeroHeight());
int v_CellCount = i_TemplateRow.getLastCellNum();
for (int v_CellIndex=0; v_CellIndex<v_CellCount; v_CellIndex++)
{
Cell v_TemplateCell = i_TemplateRow.getCell(v_CellIndex);
if ( v_TemplateCell == null )
{
continue;
}
Cell v_DataCell = i_DataRow.getCell(v_CellIndex);
if ( v_DataCell == null )
{
v_DataCell = i_DataRow.createCell(v_CellIndex);
}
copyCellByBlankSpace(i_RTemplate ,v_TemplateCell ,i_DataWorkbook ,v_DataCell ,io_RSystemValue);
}
return 0;
}
示例12: writeComment
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的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
示例13: writeCell
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
/**
* @param row 0-based index
* @param column 0-based index
*/
public static void writeCell(Sheet sheet, int row, int column, String value) {
Row r = sheet.getRow(row);
if (r == null) {
r = sheet.createRow(row);
}
Cell cell = r.getCell(column);
if (cell == null) {
cell = r.createCell(column, Cell.CELL_TYPE_STRING);
}
cell.setCellValue(value);
}
示例14: dataTableTitile
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
private void dataTableTitile(Sheet s, String titile, CellStyle csTitulo, CellStyle csTituloP,CellStyle csTituloTabelaNBorder) {
Row r = s.createRow(linha);
Cell c = r.createCell(2);
createCellM(c, r, s, csTitulo, linha, linha + 3, ConfigDoc.Empresa.NOME, 1, 22);
linha += 4;
r = s.createRow(linha);
createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.ENDERECO, 1, 22);
linha++;
r = s.createRow(linha);
createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.CAIXAPOSTAL, 1, 22);
linha++;
r = s.createRow(linha);
createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, 1, 22);
linha++;
r = s.createRow(linha);
createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.SOCIEDADE, 1, 22);
linha += 3;
r = s.createRow(linha);
createCellM(c, r, s, csTituloTabelaNBorder, linha, linha, "TOTAL PREMIUM COLLECTED ON TRAVEL INSURANCE AND TAXES FOR "+titile, 1, 10);
linha += 2;
}
示例15: initialize
import org.apache.poi.ss.usermodel.Row; //导入方法依赖的package包/类
/**
* 初始化函数
* @param title 表格标题,传“空值”,表示无标题
* @param headerList 表头列表
*/
private void initialize(String title, List<String> headerList) {
this.wb = new SXSSFWorkbook(500);
this.sheet = wb.createSheet("Export");
this.styles = createStyles(wb);
// Create title
if (StringUtils.isNotBlank(title)){
Row titleRow = sheet.createRow(rownum++);
titleRow.setHeightInPoints(30);
Cell titleCell = titleRow.createCell(0);
titleCell.setCellStyle(styles.get("title"));
titleCell.setCellValue(title);
sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(),
titleRow.getRowNum(), titleRow.getRowNum(), headerList.size()-1));
}
// Create header
if (headerList == null){
throw new RuntimeException("headerList not null!");
}
Row headerRow = sheet.createRow(rownum++);
headerRow.setHeightInPoints(16);
for (int i = 0; i < headerList.size(); i++) {
Cell cell = headerRow.createCell(i);
cell.setCellStyle(styles.get("header"));
String[] ss = StringUtils.split(headerList.get(i), "**", 2);
if (ss.length==2){
cell.setCellValue(ss[0]);
Comment comment = this.sheet.createDrawingPatriarch().createCellComment(
new XSSFClientAnchor(0, 0, 0, 0, (short) 3, 3, (short) 5, 6));
comment.setString(new XSSFRichTextString(ss[1]));
cell.setCellComment(comment);
}else{
cell.setCellValue(headerList.get(i));
}
sheet.autoSizeColumn(i);
}
for (int i = 0; i < headerList.size(); i++) {
int colWidth = sheet.getColumnWidth(i)*2;
sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth);
}
log.debug("Initialize success.");
}