org.apache.poi.ss.usermodel.Cell.setCellValue()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(1938)

本文整理了Java中org.apache.poi.ss.usermodel.Cell.setCellValue()方法的一些代码示例,展示了Cell.setCellValue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cell.setCellValue()方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.Cell
类名称:Cell
方法名:setCellValue

Cell.setCellValue介绍

[英]Set a numeric value for the cell
[中]设置单元格的数值

代码示例

代码示例来源:origin: stackoverflow.com

Cell cell;
   cell = rowxl.createCell(0);
   cell.setCellValue("ABC");
   cell.setCellStyle(style);
   cell = rowxl.createCell(1);
   cell.setCellValue("aaa");
   cell.setCellStyle(style);

代码示例来源:origin: alibaba/easyexcel

public static Cell createCell(Row row, int colNum, CellStyle cellStyle, Object cellValue, Boolean isNum) {
  Cell cell = row.createCell(colNum);
  cell.setCellStyle(cellStyle);
  if (null != cellValue) {
    if (isNum) {
      cell.setCellValue(Double.parseDouble(cellValue.toString()));
    } else {
      cell.setCellValue(cellValue.toString());
    }
  }
  return cell;
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  protected void buildExcelDocument(Map<String, Object> model, Workbook workbook,
      HttpServletRequest request, HttpServletResponse response) throws Exception {
    Sheet sheet = workbook.createSheet("Test Sheet");
    Row row = sheet.createRow(0);
    Cell cell = row.createCell(0);
    cell.setCellValue("Test Value");
  }
};

代码示例来源:origin: stackoverflow.com

Workbook wb = new HSSFWorkbook();
 //Workbook wb = new XSSFWorkbook();
 CreationHelper createHelper = wb.getCreationHelper();
 Sheet sheet = wb.createSheet("new sheet");
 // Create a row and put some cells in it. Rows are 0 based.
 Row row = sheet.createRow((short)0);
 // Create a cell and put a value in it.
 Cell cell = row.createCell(0);
 cell.setCellValue(1);
 // Or do it on one line.
 row.createCell(1).setCellValue(1.2);
 row.createCell(2).setCellValue(
    createHelper.createRichTextString("This is a string"));
 row.createCell(3).setCellValue(true);
 // Write the output to a file
 FileOutputStream fileOut = new FileOutputStream("workbook.xls");
 wb.write(fileOut);
 fileOut.close();

代码示例来源:origin: stackoverflow.com

InputStream inp = new FileInputStream("wb.xls");
 Workbook wb = WorkbookFactory.create(inp);
 Sheet sheet = wb.getSheetAt([sheet index]);
 Row row = sheet.getRow([row index]);
 Cell cell = row.getCell([cell index]);
 String cellContents = cell.getStringCellValue(); 
 //Modify the cellContents here
 // Write the output to a file
 cell.setCellValue(cellContents); 
 FileOutputStream fileOut = new FileOutputStream("wb.xls");
 wb.write(fileOut);
 fileOut.close();

代码示例来源:origin: stackoverflow.com

File f = new File(directory+"users.xlsx");

FileInputStream fileInputStream = new FileInputStream(f);

Workbook workbook = WorkbookFactory.create(fileInputStream);
fileInputStream.close();
sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(4);
for(int i = 0; i<5; i++)
{
Cell cell = row1.getCell(i);
cell.setCellValue(formattedDate);
cell.setCellStyle(normalStyle);
}

 FileOutputStream out = new FileOutputStream(f, false);
        workbook.write(out);
        out.close();

代码示例来源:origin: stackoverflow.com

try {           
   FileInputStream fileInput = new FileInputStream("sample.xls");         
   BufferedInputStream bufferInput = new BufferedInputStream(fileInput);            
   POIFSFileSystem poiFileSystem = new POIFSFileSystem(bufferInput);            
   Biff8EncryptionKey.setCurrentUserPassword("password");            
   HSSFWorkbook workbook = new HSSFWorkbook(poiFileSystem, true);            
   HSSFSheet sheet = workbook.getSheetAt(0);           
   HSSFRow row = sheet.createRow(0);
   Cell cell = row.createCell(0);
   cell.setCellValue("Hello World"); 
   FileOutputStream fileOut = new FileOutputStream(fname);
   workbook.writeProtectWorkbook(Biff8EncryptionKey.getCurrentUserPassword(), "");
   workbook.write(fileOut);
 } catch (Exception ex) {
 }

代码示例来源:origin: rakam-io/rakam

final Cell cell = headerRow.createCell(i);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellValue(metadata.get(i).getName());
  Cell cell = row.createCell(c, excelType);
  writeExcelValue(cell, objects.get(c), type);

代码示例来源:origin: stackoverflow.com

Workbook wb = new HSSFWorkbook();
Sheet s1 = wb.createSheet();
for (int i=0; i<test.size(); i++) {
  String firstname = 
  Row r = s1.createRow(i);

  Map<String,String> personData = test.get(i);

  Cell fn = r.createCreateCell(0, Cell.CELL_TYPE_STRING);
  fn.setCellValue(data.get("personfirstname"));

  Cell ln = r.createCreateCell(1, Cell.CELL_TYPE_STRING);
  ln.setCellValue(data.get("personlastname"));
}

代码示例来源:origin: stackoverflow.com

Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("format sheet");
CellStyle style;
DataFormat format = wb.createDataFormat();
Row row;
Cell cell;
short rowNum = 0;
short colNum = 0;

row = sheet.createRow(rowNum++);
cell = row.createCell(colNum);
cell.setCellValue(11111.25);
style = wb.createCellStyle();
style.setDataFormat(format.getFormat("0.0"));
cell.setCellStyle(style);

row = sheet.createRow(rowNum++);
cell = row.createCell(colNum);
cell.setCellValue(11111.25);
style = wb.createCellStyle();
style.setDataFormat(format.getFormat("#,##0.0000"));
cell.setCellStyle(style);

FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();

代码示例来源:origin: stackoverflow.com

public  void setData(String adr,String sht,int rn,int cn,String val) throws Exception{

  FileInputStream fsIP= new FileInputStream(new File(adr)); //Read the spreadsheet that needs to be updated

  XSSFWorkbook wb = new XSSFWorkbook(fsIP); //Access the workbook

  XSSFSheet worksheet = wb.getSheet(sht); //Access the worksheet, so that we can update / modify it.

  Cell cell = null; // declare a Cell object

  cell = worksheet.getRow(rn).getCell(cn);   // Access the second cell in second row to update the value

  cell.setCellValue(val);  // Get current cell value value and overwrite the value

  fsIP.close(); //Close the InputStream

  FileOutputStream output_file =new FileOutputStream(new File(adr));  //Open FileOutputStream to write updates

  wb.write(output_file); //write changes

  output_file.close();  //close the stream   
}

代码示例来源:origin: primefaces/primefaces

protected void addColumnValue(Row row, String value) {
  int cellIndex = row.getLastCellNum() == -1 ? 0 : row.getLastCellNum();
  Cell cell = row.createCell(cellIndex);
  cell.setCellValue(createRichTextString(value));
  if (facetStyle != null) {
    cell.setCellStyle(facetStyle);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  protected void buildExcelDocument(Map<String, Object> model, Workbook workbook,
      HttpServletRequest request, HttpServletResponse response) throws Exception {
    Sheet sheet = workbook.createSheet("Test Sheet");
    Row row = sheet.createRow(0);
    Cell cell = row.createCell(0);
    cell.setCellValue("Test Value");
  }
};

代码示例来源:origin: looly/hutool

final CellStyle cellStyle = styleSet.getCellStyle();
if(isHeader && null != headCellStyle) {
  cell.setCellStyle(headCellStyle);
} else if (null != cellStyle) {
  cell.setCellStyle(cellStyle);
  cell.setCellValue(StrUtil.EMPTY);
}else if (value instanceof FormulaCellValue) {
} else if (value instanceof Date) {
  if (null != styleSet && null != styleSet.getCellStyleForDate()) {
    cell.setCellStyle(styleSet.getCellStyleForDate());
  cell.setCellValue((Date) value);
} else if (value instanceof Calendar) {
  cell.setCellValue((Calendar) value);
} else if (value instanceof Boolean) {
  cell.setCellValue((Boolean) value);
} else if (value instanceof RichTextString) {
  cell.setCellValue((RichTextString) value);
} else if (value instanceof Number) {
  if ((value instanceof Double || value instanceof Float) && null != styleSet && null != styleSet.getCellStyleForNumber()) {
    cell.setCellStyle(styleSet.getCellStyleForNumber());
  cell.setCellValue(((Number) value).doubleValue());
} else {
  cell.setCellValue(value.toString());

代码示例来源:origin: stackoverflow.com

Row r = sheet.getRow(9); // 10-1
if (r == null) {
  // First cell in the row, create
  r = sheet.createRow(9);
}

Cell c = r.getCell(3); // 4-1
if (c == null) {
  // New cell
  c = r.createCell(3, Cell.CELL_TYPE_NUMERIC);
}
c.setCellValue(100);

代码示例来源:origin: stackoverflow.com

Row headerRow = personSheet.createRow(0);
Cell nameHeaderCell = headerRow.createCell(0);
Cell addressHeaderCell = headerRow.createCell(1);
  String address = resultSet.getString("address");
  Row dataRow = personSheet.createRow(row);
  Cell dataNameCell = dataRow.createCell(0);
  dataNameCell.setCellValue(name);
  Cell dataAddressCell = dataRow.createCell(1);
  dataAddressCell.setCellValue(address);
FileOutputStream fileOut = new FileOutputStream(outputDirPath);
wb.write(fileOut);
fileOut.close();

代码示例来源:origin: stackoverflow.com

InputStream inp = new FileInputStream("wb.xls");
 Workbook wb = WorkbookFactory.create(inp);
 Sheet sheet = wb.getSheetAt([sheet index]);
 Row row = sheet.getRow([row index]);
 Cell cell = row.getCell([cell index]);
 String cellContents = cell.getStringCellValue(); 
 //Modify the cellContents here
 // Write the output to a file
 cell.setCellValue(cellContents); 
 FileOutputStream fileOut = new FileOutputStream("wb.xls");
 wb.write(fileOut);
 fileOut.close();

代码示例来源:origin: primefaces/primefaces

protected void addColumnValue(Row row, List<UIComponent> components, UIColumn column) {
  int cellIndex = row.getLastCellNum() == -1 ? 0 : row.getLastCellNum();
  Cell cell = row.createCell(cellIndex);
  FacesContext context = FacesContext.getCurrentInstance();
  if (column.getExportFunction() != null) {
    cell.setCellValue(createRichTextString(exportColumnByFunction(context, column)));
  }
  else {
    StringBuilder builder = new StringBuilder();
    for (UIComponent component : components) {
      if (component.isRendered()) {
        String value = exportValue(context, component);
        if (value != null) {
          builder.append(value);
        }
      }
    }
    cell.setCellValue(createRichTextString(builder.toString()));
  }
  if (cellStyle != null) {
    cell.setCellStyle(cellStyle);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  protected void buildExcelDocument(Map<String, Object> model, Workbook workbook,
      HttpServletRequest request, HttpServletResponse response) throws Exception {
    Sheet sheet = workbook.createSheet("Test Sheet");
    Row row = sheet.createRow(0);
    Cell cell = row.createCell(0);
    cell.setCellValue("Test Value");
  }
};

代码示例来源:origin: looly/hutool

final CellStyle cellStyle = styleSet.getCellStyle();
if(isHeader && null != headCellStyle) {
  cell.setCellStyle(headCellStyle);
} else if (null != cellStyle) {
  cell.setCellStyle(cellStyle);
  cell.setCellValue(StrUtil.EMPTY);
}else if (value instanceof FormulaCellValue) {
} else if (value instanceof Date) {
  if (null != styleSet && null != styleSet.getCellStyleForDate()) {
    cell.setCellStyle(styleSet.getCellStyleForDate());
  cell.setCellValue((Date) value);
} else if (value instanceof Calendar) {
  cell.setCellValue((Calendar) value);
} else if (value instanceof Boolean) {
  cell.setCellValue((Boolean) value);
} else if (value instanceof RichTextString) {
  cell.setCellValue((RichTextString) value);
} else if (value instanceof Number) {
  if ((value instanceof Double || value instanceof Float) && null != styleSet && null != styleSet.getCellStyleForNumber()) {
    cell.setCellStyle(styleSet.getCellStyleForNumber());
  cell.setCellValue(((Number) value).doubleValue());
} else {
  cell.setCellValue(value.toString());

相关文章