• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java HSSFCell类的典型用法代码示例

java 12次浏览

本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFCell的典型用法代码示例。如果您正苦于以下问题:Java HSSFCell类的具体用法?Java HSSFCell怎么用?Java HSSFCell使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

HSSFCell类属于org.apache.poi.hssf.usermodel包,在下文中一共展示了HSSFCell类的39个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: makeHeader

点赞 4

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 );
    }
}
 

开发者ID:eclipse,
项目名称:neoscada,
代码行数:24,
代码来源:ExportEventsImpl.java

示例2: readXls

点赞 4

import org.apache.poi.hssf.usermodel.HSSFCell; //导入依赖的package包/类
/**
 * Read the Excel 2003-2007
 * 
 * @param path
 *            the path of the Excel
 * @return
 * @throws IOException
 */
public static String readXls(String path) throws IOException {
	InputStream is = new FileInputStream(path);
	HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
	StringBuffer sb = new StringBuffer("");
	// Read the Sheet
	for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
		HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
		if (hssfSheet == null) {
			continue;
		}
		// Read the Row
		for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
			HSSFRow hssfRow = hssfSheet.getRow(rowNum);
			if (hssfRow != null) {
				HSSFCell no = hssfRow.getCell(0);
				HSSFCell name = hssfRow.getCell(1);
				sb.append(no + ":" + name);
				sb.append(";");
			}
		}
	}
	return sb.toString().substring(0, sb.toString().length() - 1);
}
 

开发者ID:wufeisoft,
项目名称:data,
代码行数:32,
代码来源:ReadExcelUtil.java

示例3: getCellValue

点赞 4

import org.apache.poi.hssf.usermodel.HSSFCell; //导入依赖的package包/类
private String getCellValue(HSSFCell cell){
	if(cell == null) return "";
	
	switch (cell.getCellType()) {
	case HSSFCell.CELL_TYPE_STRING: return cell.getStringCellValue();
	case HSSFCell.CELL_TYPE_BOOLEAN : return Boolean.toString(cell.getBooleanCellValue());
	case HSSFCell.CELL_TYPE_NUMERIC : 
		if(HSSFDateUtil.isCellDateFormatted(cell))
			return DateUtils.formatDateTime("yyyyMMdd", HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
		else
			return new BigDecimal(cell.getNumericCellValue()).toPlainString();
	case HSSFCell.CELL_TYPE_FORMULA : return "";
	case HSSFCell.CELL_TYPE_BLANK : return "";
	default:return "";
	}
}
 

开发者ID:ken8271,
项目名称:parrot,
代码行数:17,
代码来源:XlsParser.java

示例4: insertItemToSheet

点赞 4

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();
}
 

开发者ID:androidmads,
项目名称:SQLite2XL,
代码行数:23,
代码来源:SQLiteToExcel.java

示例5: writeXLSFile

点赞 3

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();
		}
 

开发者ID:sergueik,
项目名称:SWET,
代码行数:21,
代码来源:TableEditorEx.java

示例6: createColumnHeaders

点赞 3

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);
	}
}
 

开发者ID:kiswanij,
项目名称:jk-util,
代码行数:18,
代码来源:JKExcelUtil.java

示例7: createHeader

点赞 3

import org.apache.poi.hssf.usermodel.HSSFCell; //导入依赖的package包/类
private void createHeader(HSSFSheet sheet, List<ExpedientConsultaDissenyDto> expedientsConsultaDissenyDto) {
	int rowNum = 0;
	int colNum = 0;

	// Capçalera
	HSSFRow xlsRow = sheet.createRow(rowNum++);

	HSSFCell cell;
	
	cell = xlsRow.createCell(colNum++);
	cell.setCellValue(new HSSFRichTextString(StringUtils.capitalize("Expedient")));
	cell.setCellStyle(headerStyle);
	
	Iterator<Entry<String, DadaIndexadaDto>> it = expedientsConsultaDissenyDto.get(0).getDadesExpedient().entrySet().iterator();
	while (it.hasNext()) {
		Map.Entry<String, DadaIndexadaDto> e = (Map.Entry<String, DadaIndexadaDto>)it.next();
		sheet.autoSizeColumn(colNum);
		cell = xlsRow.createCell(colNum++);
		cell.setCellValue(new HSSFRichTextString(StringUtils.capitalize(e.getValue().getEtiqueta())));
		cell.setCellStyle(headerStyle);
	}
}
 

开发者ID:GovernIB,
项目名称:helium,
代码行数:23,
代码来源:ExpedientInformeController.java

示例8: findMatchColumn

点赞 3

import org.apache.poi.hssf.usermodel.HSSFCell; //导入依赖的package包/类
public static Integer findMatchColumn(final HSSFRow row, final String str) {
    for (int colNum = row.getFirstCellNum(); colNum <= row.getLastCellNum(); colNum++) {
        final HSSFCell cell = row.getCell(colNum);

        if (cell == null) {
            continue;
        }

        if (cell.getCellType() != Cell.CELL_TYPE_STRING) {
            continue;
        }

        final HSSFRichTextString cellValue = cell.getRichStringCellValue();

        if (cellValue.getString().matches(str)) {
            return Integer.valueOf(colNum);
        }
    }

    return null;
}
 

开发者ID:roundrop,
项目名称:ermasterr,
代码行数:22,
代码来源:POIUtils.java

示例9: setComment

点赞 3

import org.apache.poi.hssf.usermodel.HSSFCell; //导入依赖的package包/类
/**
 * See the comment for the given cell
 * 
 * @param cell
 *            the cell
 * @param message
 *            the comment message
 */
public static void setComment(HSSFCell cell, String message) {
	Drawing drawing = cell.getSheet().createDrawingPatriarch();
	CreationHelper factory = cell.getSheet().getWorkbook().getCreationHelper();

	// When the comment box is visible, have it show in a 1x3 space
	ClientAnchor anchor = factory.createClientAnchor();
	anchor.setCol1(cell.getColumnIndex());
	anchor.setCol2(cell.getColumnIndex() + 1);
	anchor.setRow1(cell.getRowIndex());
	anchor.setRow2(cell.getRowIndex() + 1);
	anchor.setDx1(100);
	anchor.setDx2(1000);
	anchor.setDy1(100);
	anchor.setDy2(1000);

	// Create the comment and set the text+author
	Comment comment = drawing.createCellComment(anchor);
	RichTextString str = factory.createRichTextString(message);
	comment.setString(str);
	comment.setAuthor("TURNUS");
	// Assign the comment to the cell
	cell.setCellComment(comment);
}
 

开发者ID:turnus,
项目名称:turnus,
代码行数:32,
代码来源:PoiUtils.java

示例10: getIntCellValue

点赞 3

import org.apache.poi.hssf.usermodel.HSSFCell; //导入依赖的package包/类
public static int getIntCellValue(HSSFSheet sheet, int r, int c) {
	HSSFRow row = sheet.getRow(r);
	if (row == null) {
		return 0;
	}
	HSSFCell cell = row.getCell(c);

	try {
		if (cell.getCellType() != HSSFCell.CELL_TYPE_NUMERIC) {
			return 0;
		}
	} catch (RuntimeException e) {
		System.err.println("Exception at sheet name:"
				+ sheet.getSheetName() + ", row:" + (r + 1) + ", col:"
				+ (c + 1));
		throw e;
	}

	return (int) cell.getNumericCellValue();
}
 

开发者ID:kozake,
项目名称:ermaster-k,
代码行数:21,
代码来源:POIUtils.java

示例11: getCellValue

点赞 3

import org.apache.poi.hssf.usermodel.HSSFCell; //导入依赖的package包/类
/**
 * 获取EXCEL文件单元列值
 * 
 * @param row
 * @param point
 * @return
 */
private static String getCellValue(HSSFRow row, int point) {
	String reString = "";
	try {
		HSSFCell cell = row.getCell((short) point);
		if (cell.getCellType() == 1)
			reString = cell.getStringCellValue();
		else if (cell.getCellType() == 0) {
			reString = convert(cell.getNumericCellValue());
			BigDecimal bd = new BigDecimal(reString);
			reString = bd.toPlainString();
		} else {
			reString = "";
		}
		System.out.println(cell.getCellType() + ":" + cell.getCellFormula());
	} catch (Exception localException) {
	}
	return checkNull(reString);
}
 

开发者ID:fellyvon,
项目名称:wasexport,
代码行数:26,
代码来源:ExcelUtil.java

示例12: parseBooleanCell

点赞 3

import org.apache.poi.hssf.usermodel.HSSFCell; //导入依赖的package包/类
private boolean parseBooleanCell(HSSFCell cell) {
if (cell != null) {
    String value;
    try {
	cell.setCellType(Cell.CELL_TYPE_STRING);
	if (cell.getStringCellValue() != null) {
	    if (cell.getStringCellValue().trim().length() != 0) {
		emptyRow = false;
	    }
	} else {
	    return false;
	}
	value = cell.getStringCellValue().trim();
    } catch (Exception e) {
	cell.setCellType(Cell.CELL_TYPE_NUMERIC);
	double d = cell.getNumericCellValue();
	emptyRow = false;
	value = new Long(new Double(d).longValue()).toString();
    }
    if (StringUtils.equals(value, "1") || StringUtils.equalsIgnoreCase(value, "true")) {
	return true;
    }
}
return false;
   }
 

开发者ID:lamsfoundation,
项目名称:lams,
代码行数:26,
代码来源:ImportService.java

示例13: parseStringCell

点赞 3

import org.apache.poi.hssf.usermodel.HSSFCell; //导入依赖的package包/类
private String parseStringCell(HSSFCell cell) {
if (cell != null) {
    try {
	cell.setCellType(Cell.CELL_TYPE_STRING);
	if (cell.getStringCellValue() != null) {
	    if (cell.getStringCellValue().trim().length() != 0) {
		emptyRow = false;
	    }
	} else {
	    return null;
	}
	// log.debug("string cell value: '"+cell.getStringCellValue().trim()+"'");
	return cell.getStringCellValue().trim();
    } catch (Exception e) {
	cell.setCellType(Cell.CELL_TYPE_NUMERIC);
	double d = cell.getNumericCellValue();
	emptyRow = false;
	// log.debug("numeric cell value: '"+d+"'");
	return (new Long(new Double(d).longValue()).toString());
    }
}
return null;
   }
 

开发者ID:lamsfoundation,
项目名称:lams,
代码行数:24,
代码来源:ImportService.java

示例14: reader

点赞 3

import org.apache.poi.hssf.usermodel.HSSFCell; //导入依赖的package包/类
public static void reader(String filePath) {
	try {
		POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filePath));
		HSSFWorkbook wb = new HSSFWorkbook(fs);
		HSSFSheet sheet = wb.getSheetAt(0);
		HSSFRow row = sheet.getRow(3);
		HSSFCell cell = row.getCell((short) 0);
		int type = cell.getCellType();
		String msg = getCellStringValue(cell);
		System.out.println(type + ":" + msg);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 

开发者ID:wkeyuan,
项目名称:DWSurvey,
代码行数:15,
代码来源:ReadExcelUtil.java

示例15: fillCellValue

点赞 3

import org.apache.poi.hssf.usermodel.HSSFCell; //导入依赖的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("");
	}
}
 

开发者ID:bsteker,
项目名称:bdf2,
代码行数:34,
代码来源:DefaultFillCellInterceptor.java

示例16: createRow

点赞 3

import org.apache.poi.hssf.usermodel.HSSFCell; //导入依赖的package包/类
/**
 *
 * @param rowIndex
 *            int
 */
protected void createRow(final int rowIndex) {
	final HSSFRow row = this.sheet.createRow(rowIndex + 1); // since the
															// rows in
	// excel starts from 1
	// not 0
	final HSSFCellStyle style = this.workbook.createCellStyle();
	style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
	int counter = 1;
	for (int i = 0; i < this.model.getColumnCount(); i++) {
		final HSSFCell cell = row.createCell(counter++);
		// cell.setEncoding(HSSFCell.ENCODING_UTF_16);
		final Object value = this.model.getValueAt(rowIndex, i);
		setValue(cell, value);
		cell.setCellStyle(style);
	}
}
 

开发者ID:kiswanij,
项目名称:jk-util,
代码行数:22,
代码来源:JKExcelUtil.java

示例17: setValue

点赞 3

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());
	}
}
 

开发者ID:kiswanij,
项目名称:jk-util,
代码行数:20,
代码来源:JKExcelUtil.java

示例18: writeCell

点赞 3

import org.apache.poi.hssf.usermodel.HSSFCell; //导入依赖的package包/类
/**
    * Write the value to the cell. Override this method if you have complex data types that may need to be exported.
    * @param value the value of the cell
    * @param cell the cell to write it to
    */
protected void writeCell(Object value, HSSFCell cell, HSSFWorkbook wb)
   {
       if (value instanceof Number)
       {
           Number num = (Number) value;
           cell.setCellValue(num.doubleValue());
       }
       else if (value instanceof Date)
       {
       	HSSFCellStyle cellStyle = wb.createCellStyle();
	    cellStyle.setDataFormat(
	    		wb.getCreationHelper().createDataFormat().getFormat("dd/MM/yyyy HH:mm"));
	    cell.setCellStyle(cellStyle);
		cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
           cell.setCellValue((Date) value);
       }
       else if (value instanceof Calendar)
       {
           cell.setCellValue((Calendar) value);
       }
       else
       {
           cell.setCellValue(new HSSFRichTextString(escapeColumnValue(value)));
       }
   }
 

开发者ID:GovernIB,
项目名称:helium,
代码行数:31,
代码来源:HeliumHssfExportView.java

示例19: createHeader

点赞 3

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;
}
 

开发者ID:otsecbsol,
项目名称:linkbinder,
代码行数:19,
代码来源:PoiWorkbookGeneratorStrategy.java

示例20: write

点赞 3

import org.apache.poi.hssf.usermodel.HSSFCell; //导入依赖的package包/类
public void write(String src) throws IOException{
  HSSFWorkbook wb = new HSSFWorkbook();
  HSSFSheet sheet = wb.createSheet("Resultats");
  
  for (int i=0; i<size(); i++) {
    HSSFRow row = sheet.createRow(i);
    HSSFCell cell = row.createCell(0);
    cell.setCellValue(get(i).area());
  }
  
  
  FileOutputStream fileOut;
    fileOut = new FileOutputStream(src);
    wb.write(fileOut);
    fileOut.close();
}
 

开发者ID:IGNF,
项目名称:geoxygene,
代码行数:17,
代码来源:VectTriangle.java

示例21: write

点赞 3

import org.apache.poi.hssf.usermodel.HSSFCell; //导入依赖的package包/类
public void write(String src) throws IOException{
  
  System.out.println(src);
  HSSFWorkbook wb = new HSSFWorkbook();
  HSSFSheet sheet = wb.createSheet("Resultats");
  
  for (int i=0; i<size(); i++) {
    HSSFRow row = sheet.createRow(i);
    HSSFCell cell = row.createCell(0);
    cell.setCellValue(get(i).area());
  }
  
  
  FileOutputStream fileOut;
    fileOut = new FileOutputStream(src);
    wb.write(fileOut);
    fileOut.close();
}
 

开发者ID:IGNF,
项目名称:geoxygene,
代码行数:19,
代码来源:VectPolygon.java

示例22: writeCondtions

点赞 3

import org.apache.poi.hssf.usermodel.HSSFCell; //导入依赖的package包/类
/**
 * 表头条件
 * @param sheet
 * @param t
 * @param cellCount
 * @return
 */
void writeCondtions(HSSFSheet sheet){
	T t = getConditions();
	if (t!=null) {
		HSSFRow row = sheet.createRow(getRowNumber());
		row.setHeight((short) 500);
		CellRangeAddress cra = new CellRangeAddress(getRowNumber(), getRowNumber(), 0, getColumnJson().size());
		sheet.addMergedRegion(cra);
		HSSFCell cell = row.createCell(0);
		HSSFCellStyle style = cell.getCellStyle();
		style.setAlignment(HorizontalAlignment.CENTER);
		style.setVerticalAlignment(VerticalAlignment.CENTER);
		style.setWrapText(true);
		cell.setCellStyle(style);
		setCellValue(cell, formatCondition(t));
		addRowNumber();
	}
}
 

开发者ID:leiyong0326,
项目名称:phone,
代码行数:25,
代码来源:ExcelExportSuper.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)