use of org.apache.poi.hssf.usermodel.HSSFCell in project poi by apache.
the class FrillsAndFills 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);
// Aqua background
HSSFCellStyle style = wb.createCellStyle();
style.setFillBackgroundColor(HSSFColorPredefined.AQUA.getIndex());
style.setFillPattern(FillPatternType.BIG_SPOTS);
HSSFCell cell = row.createCell(1);
cell.setCellValue("X");
cell.setCellStyle(style);
// Orange "foreground", foreground being the fill foreground not the font color.
style = wb.createCellStyle();
style.setFillForegroundColor(HSSFColorPredefined.ORANGE.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cell = row.createCell(2);
cell.setCellValue("X");
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 RepeatingRowsAndColumns method main.
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("first sheet");
HSSFSheet sheet2 = wb.createSheet("second sheet");
HSSFSheet sheet3 = wb.createSheet("third sheet");
HSSFFont boldFont = wb.createFont();
boldFont.setFontHeightInPoints((short) 22);
boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
HSSFCellStyle boldStyle = wb.createCellStyle();
boldStyle.setFont(boldFont);
HSSFRow row = sheet1.createRow(1);
HSSFCell cell = row.createCell(0);
cell.setCellValue("This quick brown fox");
cell.setCellStyle(boldStyle);
// Set the columns to repeat from column 0 to 2 on the first sheet
sheet1.setRepeatingColumns(CellRangeAddress.valueOf("A:C"));
// Set the rows to repeat from row 0 to 2 on the second sheet.
sheet2.setRepeatingRows(CellRangeAddress.valueOf("1:3"));
// Set the the repeating rows and columns on the third sheet.
CellRangeAddress cra = CellRangeAddress.valueOf("D1:E2");
sheet3.setRepeatingColumns(cra);
sheet3.setRepeatingRows(cra);
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 SVTableModel method getValueAt.
@Override
public Object getValueAt(int row, int col) {
HSSFRow r = st.getRow(row);
HSSFCell c = null;
if (r != null) {
c = r.getCell(col);
}
return c;
}
use of org.apache.poi.hssf.usermodel.HSSFCell in project poi by apache.
the class ExcelToFoConverter method processRow.
/**
* @return maximum 1-base index of column that were rendered, zero if none
*/
protected int processRow(HSSFWorkbook workbook, CellRangeAddress[][] mergedRanges, HSSFRow row, Element tableRowElement) {
final HSSFSheet sheet = row.getSheet();
final short maxColIx = row.getLastCellNum();
if (maxColIx <= 0) {
return 0;
}
final List<Element> emptyCells = new ArrayList<Element>(maxColIx);
if (isOutputRowNumbers()) {
Element tableRowNumberCellElement = processRowNumber(row);
emptyCells.add(tableRowNumberCellElement);
}
int maxRenderedColumn = 0;
for (int colIx = 0; colIx < maxColIx; colIx++) {
if (!isOutputHiddenColumns() && sheet.isColumnHidden(colIx))
continue;
CellRangeAddress range = ExcelToHtmlUtils.getMergedRange(mergedRanges, row.getRowNum(), colIx);
if (range != null && (range.getFirstColumn() != colIx || range.getFirstRow() != row.getRowNum()))
continue;
HSSFCell cell = row.getCell(colIx);
// spanning using overlapping blocks
int divWidthPx = 0;
{
divWidthPx = getColumnWidth(sheet, colIx);
boolean hasBreaks = false;
for (int nextColumnIndex = colIx + 1; nextColumnIndex < maxColIx; nextColumnIndex++) {
if (!isOutputHiddenColumns() && sheet.isColumnHidden(nextColumnIndex))
continue;
if (row.getCell(nextColumnIndex) != null && !isTextEmpty(row.getCell(nextColumnIndex))) {
hasBreaks = true;
break;
}
divWidthPx += getColumnWidth(sheet, nextColumnIndex);
}
if (!hasBreaks)
divWidthPx = Integer.MAX_VALUE;
}
Element tableCellElement = foDocumentFacade.createTableCell();
if (range != null) {
if (range.getFirstColumn() != range.getLastColumn())
tableCellElement.setAttribute("number-columns-spanned", String.valueOf(range.getLastColumn() - range.getFirstColumn() + 1));
if (range.getFirstRow() != range.getLastRow())
tableCellElement.setAttribute("number-rows-spanned", String.valueOf(range.getLastRow() - range.getFirstRow() + 1));
}
boolean emptyCell;
if (cell != null) {
emptyCell = processCell(workbook, cell, tableCellElement, getColumnWidth(sheet, colIx), divWidthPx, row.getHeight() / 20f);
} else {
tableCellElement.appendChild(foDocumentFacade.createBlock());
emptyCell = true;
}
if (emptyCell) {
emptyCells.add(tableCellElement);
} else {
for (Element emptyCellElement : emptyCells) {
tableRowElement.appendChild(emptyCellElement);
}
emptyCells.clear();
tableRowElement.appendChild(tableCellElement);
maxRenderedColumn = colIx;
}
}
return maxRenderedColumn + 1;
}
use of org.apache.poi.hssf.usermodel.HSSFCell in project poi by apache.
the class TestIndirect method testMultipleWorkbooks.
@Test
public void testMultipleWorkbooks() throws Exception {
HSSFWorkbook wbA = createWBA();
HSSFCell cellA = wbA.getSheetAt(0).createRow(10).createCell(0);
HSSFFormulaEvaluator feA = new HSSFFormulaEvaluator(wbA);
HSSFWorkbook wbB = createWBB();
HSSFCell cellB = wbB.getSheetAt(0).createRow(10).createCell(0);
HSSFFormulaEvaluator feB = new HSSFFormulaEvaluator(wbB);
String[] workbookNames = { "MyBook", "Figures for January" };
HSSFFormulaEvaluator[] evaluators = { feA, feB };
HSSFFormulaEvaluator.setupEnvironment(workbookNames, evaluators);
// same wb
confirm(feB, cellB, "INDIRECT(\"'[Figures for January]## Look here!'!A1\")", 42);
// across workbooks
confirm(feA, cellA, "INDIRECT(\"'[Figures for January]## Look here!'!A1\")", 42);
// 2 level recursion
// set up (and check) first level
confirm(feB, cellB, "INDIRECT(\"[MyBook]Sheet2!A1\")", 50);
// points to cellB
confirm(feA, cellA, "INDIRECT(\"'[Figures for January]Sheet1'!A11\")", 50);
wbB.close();
wbA.close();
}
Aggregations