use of org.apache.poi.hssf.usermodel.HSSFCell in project poi by apache.
the class WorkingWithFonts method main.
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
HSSFRow row = sheet.createRow(1);
// Create a new font and alter it.
HSSFFont font = wb.createFont();
font.setFontHeightInPoints((short) 24);
font.setFontName("Courier New");
font.setItalic(true);
font.setStrikeout(true);
// Fonts are set into a style so create a new one to use.
HSSFCellStyle style = wb.createCellStyle();
style.setFont(font);
// Create a cell and put a value in it.
HSSFCell cell = row.createCell(1);
cell.setCellValue("This is a test of fonts");
cell.setCellStyle(style);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFCell in project poi by apache.
the class MergedCells method main.
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow(1);
HSSFCell cell = row.createCell(1);
cell.setCellValue("This is a test of merging");
sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 2));
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFCell in project poi by apache.
the class TestFormulaParser method testUnderscore.
/** bug 35027, underscore in sheet name */
@Test
public void testUnderscore() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
wb.createSheet("Cash_Flow");
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
HSSFCell cell;
cell = row.createCell(0);
cell.setCellFormula("Cash_Flow!A1");
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFCell in project poi by apache.
the class TestFormulaParser method testRangeOperator.
@Test
public void testRangeOperator() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFCell cell = sheet.createRow(0).createCell(0);
wb.setSheetName(0, "Sheet1");
// explicit range ':' operator
cell.setCellFormula("Sheet1!B$4:Sheet1!$C1");
assertEquals("Sheet1!B$4:Sheet1!$C1", cell.getCellFormula());
// plain area ref
cell.setCellFormula("Sheet1!B$4:$C1");
// note - area ref is normalised
assertEquals("Sheet1!B1:$C$4", cell.getCellFormula());
// different syntax for plain area ref
cell.setCellFormula("Sheet1!$C1...B$4");
assertEquals("Sheet1!B1:$C$4", cell.getCellFormula());
// with funny sheet name
wb.setSheetName(0, "A1...A2");
cell.setCellFormula("A1...A2!B1");
assertEquals("A1...A2!B1", cell.getCellFormula());
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFCell in project poi by apache.
the class TestFormulaParser method testParseExternalWorkbookReference.
@Test
public void testParseExternalWorkbookReference() throws IOException {
HSSFWorkbook wbA = HSSFTestDataSamples.openSampleWorkbook("multibookFormulaA.xls");
HSSFCell cell = wbA.getSheetAt(0).getRow(0).getCell(0);
// make sure formula in sample is as expected
assertEquals("[multibookFormulaB.xls]BSheet1!B1", cell.getCellFormula());
Ptg[] expectedPtgs = FormulaExtractor.getPtgs(cell);
confirmSingle3DRef(expectedPtgs, 1);
// now try (re-)parsing the formula
Ptg[] actualPtgs = HSSFFormulaParser.parse("[multibookFormulaB.xls]BSheet1!B1", wbA);
// externalSheetIndex 1 -> BSheet1
confirmSingle3DRef(actualPtgs, 1);
// try parsing a formula pointing to a different external sheet
Ptg[] otherPtgs = HSSFFormulaParser.parse("[multibookFormulaB.xls]AnotherSheet!B1", wbA);
// externalSheetIndex 0 -> AnotherSheet
confirmSingle3DRef(otherPtgs, 0);
// try setting the same formula in a cell
cell.setCellFormula("[multibookFormulaB.xls]AnotherSheet!B1");
assertEquals("[multibookFormulaB.xls]AnotherSheet!B1", cell.getCellFormula());
wbA.close();
}
Aggregations