本文整理汇总了Java中org.apache.poi.ss.usermodel.Workbook.getCreationHelper方法的典型用法代码示例。如果您正苦于以下问题:Java Workbook.getCreationHelper方法的具体用法?Java Workbook.getCreationHelper怎么用?Java Workbook.getCreationHelper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.ss.usermodel.Workbook
的用法示例。
在下文中一共展示了Workbook.getCreationHelper方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluateFormulas
import org.apache.poi.ss.usermodel.Workbook; //导入方法依赖的package包/类
public static void evaluateFormulas(String fileName) throws IOException {
xLogger.fine("Entering evaluateFormulas. fileName: {0}", fileName);
// Create a InoutStream from the bytes in the cloud storage.
// Create a template workbook
// Evaluate the formulas
// Save the workbook.
if (fileName == null || fileName.isEmpty()) {
xLogger.severe("Cannot evaluate formulas in a null or empty file");
return;
}
InputStream is = null;
OutputStream os = null;
// Create a workbook from the bytes
try {
// Get the template bytes from GCS ( Note: By now the data has been added to the appropriate sheet/s)
is = _storageUtil.getInputStream(CustomReportsExportMgr.CUSTOMREPORTS_BUCKETNAME, fileName);
if (is == null) {
xLogger.severe("Failed to create Input stream for {0}", fileName);
return;
}
Workbook
templateWb =
WorkbookFactory.create(
is); // From the bytes downloaded from the google cloud storage, form the Workbook
if (templateWb != null) {
CreationHelper createHelper = templateWb.getCreationHelper();
xLogger.fine("Created createHelper. {0}", createHelper);
if (createHelper != null) {
FormulaEvaluator evaluator = createHelper.createFormulaEvaluator();
xLogger.fine("Created evaluator. {0}", evaluator);
if (evaluator != null) {
evaluator.evaluateAll();
xLogger.fine("After evaluator.evaluateAll");
templateWb.setForceFormulaRecalculation(
true); // Added this line because some formula cells were not getting updated even after calling evaluateAll
xLogger.fine("After templateWb.setForceFormulaRecalculation");
// Write to file
xLogger.fine("Now creating baos");
os =
_storageUtil
.getOutputStream(CustomReportsExportMgr.CUSTOMREPORTS_BUCKETNAME, fileName,
false);
xLogger.fine("os: {0}", os);
templateWb.write(os); // Write the workbook to OutputStream
xLogger.fine("Wrote templateWb to baos");
} // end if evaluator != null
} // end if createHelper != null
} // end if templateWb != null
} catch (Exception e) {
xLogger.severe("{0} while evaluating formulas in the file {1}. Message: {2}",
e.getClass().getName(), fileName, e.getMessage(), e);
} finally {
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
}
xLogger.fine("Exiting evaluateFormulas");
}
示例2: ExcelTestHelper
import org.apache.poi.ss.usermodel.Workbook; //导入方法依赖的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();
}