use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class SettingExternalFunction method main.
public static void main(String[] args) throws IOException {
// or new HSSFWorkbook()
Workbook wb = new XSSFWorkbook();
// register the add-in
wb.addToolPack(new BloombergAddIn());
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
row.createCell(0).setCellFormula("BDP(\"GOOG Equity\",\"CHG_PCT_YTD\")/100");
row.createCell(1).setCellFormula("BDH(\"goog us equity\",\"EBIT\",\"1/1/2005\",\"12/31/2009\",\"per=cy\",\"curr=USD\") ");
row.createCell(2).setCellFormula("BDS(\"goog us equity\",\"top_20_holders_public_filings\") ");
FileOutputStream out = new FileOutputStream("bloomberg-demo.xlsx");
wb.write(out);
out.close();
wb.close();
}
use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class XSSFFileHandler method handleFile.
@Override
public void handleFile(InputStream stream, String path) throws Exception {
// ignore password protected files
if (POIXMLDocumentHandler.isEncrypted(stream))
return;
final XSSFWorkbook wb;
// make sure the potentially large byte-array is freed up quickly again
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(stream, out);
final byte[] bytes = out.toByteArray();
checkXSSFReader(OPCPackage.open(new ByteArrayInputStream(bytes)));
wb = new XSSFWorkbook(new ByteArrayInputStream(bytes));
}
// use the combined handler for HSSF/XSSF
handleWorkbook(wb);
// TODO: some documents fail currently...
//XSSFFormulaEvaluator evaluator = new XSSFFormulaEvaluator(wb);
//evaluator.evaluateAll();
// also verify general POIFS-stuff
new POIXMLDocumentHandler().handlePOIXMLDocument(wb);
// and finally ensure that exporting to XML works
exportToXML(wb);
// this allows to trigger a heap-dump at this point to see which memory is still allocated
//HeapDump.dumpHeap("/tmp/poi.hprof", false);
wb.close();
}
use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class TestXSSFChartLegend method testLegendPositionAccessMethods.
@Test
public void testLegendPositionAccessMethods() throws IOException {
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet();
Drawing<?> drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
Chart chart = drawing.createChart(anchor);
ChartLegend legend = chart.getOrCreateLegend();
legend.setPosition(LegendPosition.TOP_RIGHT);
assertEquals(LegendPosition.TOP_RIGHT, legend.getPosition());
wb.close();
}
use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class TestXSSFChartLegend method test_setOverlay_chartLegendSetToTrue_expectOverlayInitialValueSetToTrue.
@Test
public void test_setOverlay_chartLegendSetToTrue_expectOverlayInitialValueSetToTrue() throws IOException {
// Arrange
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet();
Drawing<?> drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
Chart chart = drawing.createChart(anchor);
ChartLegend legend = chart.getOrCreateLegend();
// Act
legend.setOverlay(true);
// Assert
assertTrue(legend.isOverlay());
wb.close();
}
use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class XSSFRowShifter method shiftFormula.
/**
* Shift a formula using the supplied FormulaShifter
*
* @param row the row of the cell this formula belongs to. Used to get a reference to the parent workbook.
* @param formula the formula to shift
* @param shifter the FormulaShifter object that operates on the parsed formula tokens
* @return the shifted formula if the formula was changed,
* <code>null</code> if the formula wasn't modified
*/
private static String shiftFormula(Row row, String formula, FormulaShifter shifter) {
Sheet sheet = row.getSheet();
Workbook wb = sheet.getWorkbook();
int sheetIndex = wb.getSheetIndex(sheet);
final int rowIndex = row.getRowNum();
XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create((XSSFWorkbook) wb);
try {
Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.CELL, sheetIndex, rowIndex);
String shiftedFmla = null;
if (shifter.adjustFormula(ptgs, sheetIndex)) {
shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs);
}
return shiftedFmla;
} catch (FormulaParseException fpe) {
// Log, but don't change, rather than breaking
logger.log(POILogger.WARN, "Error shifting formula on row ", row.getRowNum(), fpe);
return formula;
}
}
Aggregations