当前位置: 首页>>代码示例>>Java>>正文


Java DataFormat.getFormat方法代码示例

本文整理汇总了Java中org.apache.poi.ss.usermodel.DataFormat.getFormat方法的典型用法代码示例。如果您正苦于以下问题:Java DataFormat.getFormat方法的具体用法?Java DataFormat.getFormat怎么用?Java DataFormat.getFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.ss.usermodel.DataFormat的用法示例。


在下文中一共展示了DataFormat.getFormat方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setCellValue

import org.apache.poi.ss.usermodel.DataFormat; //导入方法依赖的package包/类
protected static void setCellValue(Workbook wb, Cell cell, Object value) {
	if (cell == null) {
		return;
	}
	if (value instanceof Boolean) {
		cell.setCellValue((Boolean)value);		
	} else if (value instanceof Number) {
		cell.setCellValue(((Number)value).doubleValue());
	} else if (value instanceof Date) {
		CellStyle cellStyle = wb.createCellStyle();
		DataFormat poiFormat = wb.createDataFormat();
		// Format: 0x16, "m/d/yy h:mm"
		final short format = poiFormat.getFormat(BuiltinFormats.getBuiltinFormat(0x16));
		cellStyle.setDataFormat(format);
		cell.setCellValue(((Date)value));
		cell.setCellStyle(cellStyle);
	} else if (value instanceof Calendar) {
		cell.setCellValue(((Calendar)value));
	} else if (value != null) {
		cell.setCellValue(value.toString());
	} else {
		cell.setCellValue("");
		cell.setCellType(Cell.CELL_TYPE_BLANK);
	}
}
 
开发者ID:qafedev,项目名称:qafe-platform,代码行数:26,代码来源:DocumentExporter.java

示例2: ExcelTestHelper

import org.apache.poi.ss.usermodel.DataFormat; //导入方法依赖的package包/类
ExcelTestHelper(final String parent, boolean generateXls) throws Exception {
  this.xls = generateXls;

  // Create a test Excel sheet with all types of supported data
  Workbook wb = generateXls ? new HSSFWorkbook() : new XSSFWorkbook();

  CreationHelper creationHelper = wb.getCreationHelper();
  DataFormat dataFormat = creationHelper.createDataFormat();
  short fmt = dataFormat.getFormat("yyyy-mm-dd hh:mm:ss");
  CellStyle style = wb.createCellStyle();
  style.setDataFormat(fmt);

  Sheet sheetWithHeader = wb.createSheet("Sheet 1");

  // Create header row
  Row headerRow = sheetWithHeader.createRow((short) 0);
  headerRow.createCell(0).setCellValue("Number");
  headerRow.createCell(1).setCellValue("String1");
  headerRow.createCell(2).setCellValue("String2");
  headerRow.createCell(3).setCellValue("MyTime");
  headerRow.createCell(4).setCellValue("Formula");
  headerRow.createCell(5).setCellValue("Boolean");
  headerRow.createCell(6).setCellValue("Error");
  generateSheetData(sheetWithHeader, style, (short)1);

  Sheet sheetWithoutHeader = wb.createSheet("Sheet 2");
  generateSheetData(sheetWithoutHeader, style, (short)0);

  testFilePath = new File(parent, "excelTestFile").getPath();

  // Write the output to a file
  FileOutputStream fileOut = new FileOutputStream(testFilePath);
  wb.write(fileOut);
  fileOut.close();
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:36,代码来源:ExcelTestHelper.java

示例3: getFormatPattern

import org.apache.poi.ss.usermodel.DataFormat; //导入方法依赖的package包/类
@Override
public String getFormatPattern() {
    final DataFormat dataFormat = cell.getSheet().getWorkbook().createDataFormat();
    final short formatIndex = getFormatIndex();
    
    String formatPattern = dataFormat.getFormat(formatIndex);
    if(formatPattern == null) {
        formatPattern = "";
    }
    
    return formatPattern;
    
}
 
开发者ID:mygreen,项目名称:excel-cellformatter,代码行数:14,代码来源:POICell.java

示例4: setDataFormat

import org.apache.poi.ss.usermodel.DataFormat; //导入方法依赖的package包/类
/**
 * Set specified cell format
 *
 * @param excelFieldFormat the specified format
 * @param cell             the cell to set up format
 */
private void setDataFormat( String excelFieldFormat, Cell cell ) {
  if ( log.isDebug() ) {
    logDebug( BaseMessages.getString( PKG, "ExcelWriterStep.Log.SetDataFormat", excelFieldFormat, CellReference
      .convertNumToColString( cell.getColumnIndex() ), cell.getRowIndex() ) );
  }

  DataFormat format = data.wb.createDataFormat();
  short formatIndex = format.getFormat( excelFieldFormat );
  CellStyle style = data.wb.createCellStyle();
  style.cloneStyleFrom( cell.getCellStyle() );
  style.setDataFormat( formatIndex );
  cell.setCellStyle( style );
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:20,代码来源:ExcelWriterStep.java

示例5: changeValueIfNeeded

import org.apache.poi.ss.usermodel.DataFormat; //导入方法依赖的package包/类
private void changeValueIfNeeded(Cell cell) {

		//validate
		String originalValue = cell.getStringCellValue();
		if (originalValue == null || originalValue.isEmpty()) return;
		
		//interprets
		Object result = interpreter.parseTemplate(originalValue, context, variables, formatter);
		
		//converts
		if (result != null) {
			
			if (formatter.format() != null) {
				
				//create data format
				DataFormat df = workbook.createDataFormat();
				short sdf = df.getFormat(formatter.format());
				
				//set format
				CellStyle style = cell.getCellStyle();
				if (style == null) {
					style = workbook.createCellStyle();
				}
				style.setDataFormat(sdf);
				
			}
			
			if (result instanceof Date) {
				
				cell.setCellType(Cell.CELL_TYPE_NUMERIC);
				cell.setCellValue((Date) result);
				
			} else if (result instanceof Calendar) {
				
				cell.setCellType(Cell.CELL_TYPE_NUMERIC);
				cell.setCellValue((Calendar) result);
				
			} else if (result instanceof Number) {
				
				cell.setCellType(Cell.CELL_TYPE_NUMERIC);
				Number numValue = (Number) result;
				cell.setCellValue(numValue.doubleValue());
				
			} else if (result instanceof Boolean) {
				
				cell.setCellType(Cell.CELL_TYPE_BOOLEAN);
				Boolean boolValue = (Boolean) result;
				cell.setCellValue(boolValue);
				
			} else  {

				String strValue = result.toString();
				if (!originalValue.equals(strValue)) {
					cell.setCellType(Cell.CELL_TYPE_STRING);
					cell.setCellValue(strValue);
				}
			
			}
			
		} else {
			cell.setCellValue((String) null);
		}
		
	}
 
开发者ID:utluiz,项目名称:t-rex,代码行数:65,代码来源:PoiSheetParser.java

示例6: dateFormat

import org.apache.poi.ss.usermodel.DataFormat; //导入方法依赖的package包/类
public static short dateFormat(Workbook workbook) {
	DataFormat format = workbook.createDataFormat();
	return format.getFormat("mm/dd/yyyy hh:mm");
}
 
开发者ID:GreenDelta,项目名称:olca-modules,代码行数:5,代码来源:Excel.java


注:本文中的org.apache.poi.ss.usermodel.DataFormat.getFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。