本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFRow.createCell方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFRow.createCell方法的具体用法?Java HSSFRow.createCell怎么用?Java HSSFRow.createCell使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hssf.usermodel.HSSFRow
的用法示例。
在下文中一共展示了HSSFRow.createCell方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeHeader
import org.apache.poi.hssf.usermodel.HSSFRow; //导入方法依赖的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.HSSFRow; //导入方法依赖的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.HSSFRow; //导入方法依赖的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.HSSFRow; //导入方法依赖的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: createContent
import org.apache.poi.hssf.usermodel.HSSFRow; //导入方法依赖的package包/类
public void createContent(WebInput wi, DocInfo di)throws ControllerException {
HSSFWorkbook wb = di.getExcelDocument();
// 创建HSSFSheet对象
HSSFSheet sheet = wb.createSheet("sheet0");
// 创建HSSFRow对象
HSSFRow row = sheet.createRow((short) 0);
// 创建HSSFCell对象
HSSFCell cell = row.createCell((short) 0);
// 用来处理中文问题
// cell.setEncoding(HSSFCell.ENCODING_UTF_16);
// 设置单元格的值
// cell.setCellValue("Hello World! 你好,中文世界");
String info = wi.getParameter("info");
HSSFRichTextString rts = new HSSFRichTextString(info);
cell.setCellValue(rts);
HSSFCell cell2 = row.createCell((short) 1);
cell2.setCellValue(new HSSFRichTextString(
"Beetle Web Framework 页面生成Excel文件演示!"));
}
示例6: writeBody
import org.apache.poi.hssf.usermodel.HSSFRow; //导入方法依赖的package包/类
void writeBody(HSSFSheet sheet){
Set<String> keySet = getColumnJson().keySet();
List<T> ts = getData();
for (T t:ts) {
// Class cls = t.getClass();
int cellNumber = 0;//将cellNumber从0开始
HSSFRow row = sheet.createRow(addRowNumber());//创建新的一行
for(String key:keySet){
try {
HSSFCell cell = row.createCell(cellNumber++);
Object value = getValueByKey(t, key);
setCellValue(cell, value);
pubMaxValue(key, value);
} catch (Exception e) {
throw new RuntimeException("writeBody", e);
}
}
}
}
示例7: createHeader
import org.apache.poi.hssf.usermodel.HSSFRow; //导入方法依赖的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: writeDirectTestData
import org.apache.poi.hssf.usermodel.HSSFRow; //导入方法依赖的package包/类
@Override
protected void writeDirectTestData(final ERTable table, final Map<NormalColumn, String> data, final String database) {
final HSSFRow row = sheet.createRow(rowNum++);
int col = 0;
for (final NormalColumn column : table.getExpandedColumns()) {
final HSSFCell cell = row.createCell(col++);
final String value = Format.null2blank(data.get(column));
if (value == null || "null".equals(value.toLowerCase())) {
} else {
cell.setCellValue(new HSSFRichTextString(value));
}
}
}
示例9: write
import org.apache.poi.hssf.usermodel.HSSFRow; //导入方法依赖的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();
}
示例10: writeCondtions
import org.apache.poi.hssf.usermodel.HSSFRow; //导入方法依赖的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();
}
}
示例11: test_001
import org.apache.poi.hssf.usermodel.HSSFRow; //导入方法依赖的package包/类
@Test
public void test_001()
{
HSSFWorkbook v_Workbook = new HSSFWorkbook();
HSSFSheet v_Sheet = v_Workbook.createSheet("测试单元格颜色");
v_Sheet.setColumnWidth(0 ,2560);
for (int v_RowIndex=0; v_RowIndex<4000; v_RowIndex++)
{
HSSFRow v_Row = v_Sheet.createRow(v_RowIndex);
for (int v_ColIndex=0; v_ColIndex<1; v_ColIndex++)
{
HSSFCell v_Cell = v_Row.createCell(v_ColIndex);
HSSFCellStyle v_CellStyle = v_Workbook.createCellStyle();
v_CellStyle.setFillForegroundColor((short)(v_RowIndex + 1));
v_CellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
v_Cell.setCellStyle(v_CellStyle);
v_Cell.setCellValue("" + (v_RowIndex + 1));
}
}
ExcelHelp.save(v_Workbook ,"/Users/hy/Downloads/测试2003版本的单元格颜色");
}
示例12: createSheet
import org.apache.poi.hssf.usermodel.HSSFRow; //导入方法依赖的package包/类
private void createSheet(String table, HSSFSheet sheet) {
HSSFRow rowA = sheet.createRow(0);
ArrayList<String> columns = getColumns(table);
for (int i = 0; i < columns.size(); i++) {
HSSFCell cellA = rowA.createCell(i);
cellA.setCellValue(new HSSFRichTextString("" + columns.get(i)));
}
insertItemToSheet(table, sheet, columns);
}
示例13: writeTableHeader
import org.apache.poi.hssf.usermodel.HSSFRow; //导入方法依赖的package包/类
@Override
protected void writeTableHeader(final ERDiagram diagram, final ERTable table) {
final String sheetName = table.getPhysicalName();
sheet = workbook.createSheet(sheetName);
rowNum = 0;
final HSSFRow row = sheet.createRow(rowNum++);
int col = 0;
for (final NormalColumn column : table.getExpandedColumns()) {
final HSSFCell cell = row.createCell(col++);
cell.setCellValue(new HSSFRichTextString(column.getPhysicalName()));
}
}
示例14: createHeader
import org.apache.poi.hssf.usermodel.HSSFRow; //导入方法依赖的package包/类
private void createHeader(
HSSFWorkbook wb,
HSSFSheet sheet,
List<TascaDadaDto> informeCamps) {
HSSFFont bold;
bold = wb.createFont();
bold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
bold.setColor(HSSFColor.WHITE.index);
HSSFCellStyle headerStyle;
headerStyle = wb.createCellStyle();
headerStyle.setFillPattern(HSSFCellStyle.FINE_DOTS);
headerStyle.setFillBackgroundColor(HSSFColor.GREY_80_PERCENT.index);
headerStyle.setFont(bold);
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);
for (TascaDadaDto camp : informeCamps) {
sheet.autoSizeColumn(colNum);
cell = xlsRow.createCell(colNum++);
cell.setCellValue(new HSSFRichTextString(StringUtils.capitalize(camp.getCampEtiqueta())));
cell.setCellStyle(headerStyle);
}
}
示例15: getCell
import org.apache.poi.hssf.usermodel.HSSFRow; //导入方法依赖的package包/类
/**
* Convenient method to obtain the cell in the given sheet, row and column.
* <p>Creates the row and the cell if they still doesn't already exist.
* Thus, the column can be passed as an int, the method making the needed downcasts.
* @param sheet a sheet object. The first sheet is usually obtained by workbook.getSheetAt(0)
* @param row the row number
* @param col the column number
* @return the HSSFCell
*/
protected HSSFCell getCell(HSSFSheet sheet, int row, int col) {
HSSFRow sheetRow = sheet.getRow(row);
if (sheetRow == null) {
sheetRow = sheet.createRow(row);
}
HSSFCell cell = sheetRow.getCell(col);
if (cell == null) {
cell = sheetRow.createCell(col);
}
return cell;
}