本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFCell.setCellValue方法的典型用法代碼示例。如果您正苦於以下問題:Java HSSFCell.setCellValue方法的具體用法?Java HSSFCell.setCellValue怎麽用?Java HSSFCell.setCellValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.hssf.usermodel.HSSFCell
的用法示例。
在下文中一共展示了HSSFCell.setCellValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: makeHeader
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
private void makeHeader ( final List<Field> columns, final HSSFSheet sheet )
{
final Font font = sheet.getWorkbook ().createFont ();
font.setFontName ( "Arial" );
font.setBoldweight ( Font.BOLDWEIGHT_BOLD );
font.setColor ( HSSFColor.WHITE.index );
final CellStyle style = sheet.getWorkbook ().createCellStyle ();
style.setFont ( font );
style.setFillForegroundColor ( HSSFColor.BLACK.index );
style.setFillPattern ( PatternFormatting.SOLID_FOREGROUND );
final HSSFRow row = sheet.createRow ( 0 );
for ( int i = 0; i < columns.size (); i++ )
{
final Field field = columns.get ( i );
final HSSFCell cell = row.createCell ( i );
cell.setCellValue ( field.getHeader () );
cell.setCellStyle ( style );
}
}
示例2: insertItemToSheet
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
private void insertItemToSheet(String table, HSSFSheet sheet, ArrayList<String> columns) {
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
Cursor cursor = database.rawQuery("select * from " + table, null);
cursor.moveToFirst();
int n = 1;
while (!cursor.isAfterLast()) {
HSSFRow rowA = sheet.createRow(n);
for (int j = 0; j < columns.size(); j++) {
HSSFCell cellA = rowA.createCell(j);
if (cursor.getType(j) == Cursor.FIELD_TYPE_BLOB) {
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) j, n, (short) (j + 1), n + 1);
anchor.setAnchorType(3);
patriarch.createPicture(anchor, workbook.addPicture(cursor.getBlob(j), HSSFWorkbook.PICTURE_TYPE_JPEG));
} else {
cellA.setCellValue(new HSSFRichTextString(cursor.getString(j)));
}
}
n++;
cursor.moveToNext();
}
cursor.close();
}
示例3: writeXLSFile
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
public static void writeXLSFile() throws IOException {
HSSFWorkbook wbObj = new HSSFWorkbook();
HSSFSheet sheet = wbObj.createSheet(sheetName);
for (int row = 0; row < tableData.size(); row++) {
HSSFRow rowObj = sheet.createRow(row);
rowData = tableData.get(row);
for (int col = 0; col < rowData.size(); col++) {
HSSFCell cellObj = rowObj.createCell(col);
cellObj.setCellValue(rowData.get(col));
}
}
FileOutputStream fileOut = new FileOutputStream(excelFileName);
wbObj.write(fileOut);
wbObj.close();
fileOut.flush();
fileOut.close();
}
示例4: createColumnHeaders
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
/**
*/
protected void createColumnHeaders() {
final HSSFRow headersRow = this.sheet.createRow(0);
final HSSFFont font = this.workbook.createFont();
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
final HSSFCellStyle style = this.workbook.createCellStyle();
style.setFont(font);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
int counter = 1;
for (int i = 0; i < this.model.getColumnCount(); i++) {
final HSSFCell cell = headersRow.createCell(counter++);
// cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(this.model.getColumnName(i));
cell.setCellStyle(style);
}
}
示例5: setValue
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
/**
* @param cell
* @param value
*/
private void setValue(final HSSFCell cell, final Object value) {
if (value == null) {
cell.setCellValue("-");
} else if (value instanceof Float || value instanceof Double || value instanceof Integer || value instanceof Long
|| value instanceof BigDecimal) {
cell.setCellValue(Double.parseDouble(value.toString()));
} else if (value instanceof String) {
cell.setCellValue(value.toString());
} else if (value instanceof Date) {
cell.setCellValue((Date) value);
} else {
logger.info("No Special excel r endering for class : " + value.getClass().getName());
cell.setCellValue(value.toString());
}
}
示例6: writeDirectTestData
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
@Override
protected void writeDirectTestData(ERTable table,
Map<NormalColumn, String> data, String database) {
HSSFRow row = this.sheet.createRow(this.rowNum++);
int col = 0;
for (NormalColumn column : table.getExpandedColumns()) {
HSSFCell cell = row.createCell(col++);
String value = Format.null2blank(data.get(column));
if (value == null || "null".equals(value.toLowerCase())) {
} else {
cell.setCellValue(new HSSFRichTextString(value));
}
}
}
示例7: createHeader
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
private boolean createHeader(WorkbookGeneratorContext context,
HSSFSheet sheet,
HSSFCellStyle style) {
if (context.headerNames == null || context.headerNames.isEmpty()) {
return false;
}
int headerRowIndex = 0;
HSSFRow rowHeader = sheet.createRow(headerRowIndex);
for (int i = 0; i < context.headerNames.size(); i++) {
HSSFCell cell = rowHeader.createCell(i);
sheet.autoSizeColumn((short) i);
cell.setCellStyle(style);
cell.setCellValue(new HSSFRichTextString(context.headerNames.get(i)));
}
return true;
}
示例8: writeSheetHead
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
/**
* 初始化表頭
* @param sheet
* @param columnJson
* @param rowNumber
*/
private static void writeSheetHead(HSSFSheet sheet,JSONObject columnJson,int rowNumber){
if (logger.isDebugEnabled()) {
logger.debug("writeSheetHead(HSSFSheet, JSONObject, int) - start"); //$NON-NLS-1$
}
Set<String> keySet = columnJson.keySet();
int cellNumber = 0;
HSSFRow row = sheet.createRow(rowNumber);
for (String k : keySet) {//k:GOODS_NO
String name = columnJson.getString(k);//品項編碼
sheet.autoSizeColumn(cellNumber);
HSSFCell cell = row.createCell(cellNumber++);
cell.setCellValue(name);
}
if (logger.isDebugEnabled()) {
logger.debug("writeSheetHead(HSSFSheet, JSONObject, int) - end"); //$NON-NLS-1$
}
}
示例9: createContentHeader
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
/**
* @param sheet
* @param strings
*/
public final void createContentHeader(final HSSFSheet sheet,
final String... strings) {
HSSFRow row;
HSSFCell cell;
row = sheet.createRow(CONTENT_HEADER);
for (int i = 0; i < strings.length; i++) {
cell = row.createCell(i);
cell.setCellValue(strings[i]);
cell.setCellStyle(heading3Cs);
}
sheet.createFreezePane(0, CONTENT_HEADER + 1);
sheet.setAutoFilter(new CellRangeAddress(CONTENT_HEADER, CONTENT_HEADER,
0, strings.length - 1));
}
示例10: WorkbookWriter
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
/**
* Constructor.
*
* @param xlsFileName
* the file name of the xls to write
* @param languages
* the languages to be processed
*/
public WorkbookWriter(final String xlsFileName, final String[] languages) {
super(xlsFileName);
HSSFRow firstRow = sheet.createRow(rowNumber++);
HSSFCell firstCell = firstRow.createCell(COLUMN_PROPERTIES_FILE_NAME);
firstCell.setCellValue("Properties file (default language)");
HSSFCell secondCell = firstRow.createCell(COLUMN_PROPERTY_KEY);
secondCell.setCellValue("Key");
HSSFCell thirdCell = firstRow.createCell(COLUMN_DEFAULT_LANG);
thirdCell.setCellValue("Default value");
int nextColumnNumber = COLUMN_DEFAULT_LANG + 1;
for (String lang : languages) {
langColumnNumber.put(lang, nextColumnNumber);
HSSFCell cell = firstRow.createCell(nextColumnNumber++);
cell.setCellValue(lang);
}
}
示例11: addUnitDocumentIntoTheRow
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
private void addUnitDocumentIntoTheRow(UnitDocument document, HSSFRow row,
LinkedHashMap<String, Integer> columPoints,
LinkedHashMap<String, String> map) throws Exception {
// TODO Auto-generated method stub
HSSFCell cell;
int count=0;
for(String key : map.keySet()){
String colum=map.get(key);
String mathodName="get"+key;
Object args[]=new Object[0];
Object result=null;
String value;
if((result=ReflectionUtil.invokeMethod(document, mathodName, args))!=null){
value=result.toString();
cell=row.createCell(columPoints.get(colum));
cell.setCellValue(value);
}
}
}
示例12: setNumericCell
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
protected void setNumericCell(HSSFCell cell, BigDecimal value, HSSFWorkbook workbook)
{
if(logger.isDebugEnabled())
logger.debug("setNumericCell(cell={}, value={}, workbook={}) - start",
new Object[] {cell, value, workbook} );
cell.setCellValue( ((BigDecimal)value).doubleValue() );
HSSFDataFormat df = workbook.createDataFormat();
int scale = ((BigDecimal)value).scale();
short format;
if(scale <= 0){
format = df.getFormat("####");
}
else {
String zeros = createZeros(((BigDecimal)value).scale());
format = df.getFormat("####." + zeros);
}
if(logger.isDebugEnabled())
logger.debug("Using format '{}' for value '{}'.", String.valueOf(format), value);
HSSFCellStyle cellStyleNumber = workbook.createCellStyle();
cellStyleNumber.setDataFormat(format);
cell.setCellStyle(cellStyleNumber);
}
示例13: addRow
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
protected void addRow(HSSFWorkbook workbook, HSSFSheet sheet, Object value, int row, int column) {
HSSFRow hssfRow = sheet.getRow(row);
hssfRow = (hssfRow == null) ? sheet.createRow(row) : hssfRow;
HSSFCell cell = hssfRow.getCell(column);
cell = (cell == null) ? hssfRow.createCell(column) : cell;
String cellValue = (value == null) ? "" : value.toString();
DecimalFormat decimalFormatter = new DecimalFormat("###,###,###,##0.00");
try {
double doubleValue = decimalFormatter.parse(cellValue).doubleValue();
DataFormat dataFormat = workbook.createDataFormat();
HSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setDataFormat(dataFormat.getFormat("###,###,###,##0.00"));
cell.setCellValue(doubleValue);
} catch (ParseException e) {
cell.setCellValue(cellValue);
}
formatCell(workbook, cell);
}
示例14: createSheetHead
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
private LinkedHashMap<String,Integer> createSheetHead(HSSFSheet sheet, HSSFCellStyle style,LinkedHashMap<String,String> map) {
HSSFRow row = sheet.createRow(2);
row.setHeight((short)1000);
HSSFCell cell;
int count=0;
LinkedHashMap<String,Integer> columPoints=new LinkedHashMap<String,Integer>();
for(String value:map.values()){
cell=row.createCell(count);
cell.setCellValue(value);
cell.setCellStyle(style);
columPoints.put(value, count);
count++;
}
return columPoints;
}
示例15: getBook
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
private HSSFWorkbook getBook() {
HSSFWorkbook book = new HSSFWorkbook();
int i = 0;
for (Entry<String, TextSheet> x : this.sheets.entrySet()) {
HSSFSheet sheet = book.createSheet();
book.setSheetName(i, x.getKey());
List<HashMap<String, String>> rows = x.getValue().getRows();
for (int k = 0; k < rows.size(); k++) {
HSSFRow row = sheet.createRow(k);
HashMap<String, String> c = rows.get(k);
int n = 0;
for (Entry<String, String> d : c.entrySet()) {
HSSFCell cell = row.createCell((short) n);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(d.getValue().toString());
n++;
}
}
i++;
}
return book;
}