use of org.apache.poi.hssf.usermodel.HSSFCellStyle in project adempiere by adempiere.
the class AbstractExcelExporter method createTableHeader.
private void createTableHeader(HSSFSheet sheet) {
short colnumMax = 0;
HSSFRow row = sheet.createRow(0);
// for all columns
short colnum = 0;
for (int col = 0; col < getColumnCount(); col++) {
if (colnum > colnumMax)
colnumMax = colnum;
//
if (isColumnPrinted(col)) {
HSSFCell cell = row.createCell(colnum);
// header row
HSSFCellStyle style = getHeaderStyle(col);
cell.setCellStyle(style);
String str = fixString(getHeaderName(col));
cell.setCellValue(new HSSFRichTextString(str));
colnum++;
}
// printed
}
// for all columns
// m_workbook.setRepeatingRowsAndColumns(m_sheetCount, 0, 0, 0, 0);
}
use of org.apache.poi.hssf.usermodel.HSSFCellStyle in project poi by apache.
the class InCellLists method numberedListInCell.
/**
* Inserts a numbered list into a single cell.
*
* @param workbook A reference to the HSSFWorkbook that 'contains' the
* cell.
* @param listItems An ArrayList whose elements encapsulate the text for
* the lists items.
* @param cell An instance of the HSSFCell class that encapsulates a
* reference to the spreadsheet cell into which the list
* will be written.
* @param startingValue A primitive int containing the number for the first
* item in the list.
* @param increment A primitive int containing the value that should be used
* to calculate subsequent item numbers.
*/
public void numberedListInCell(HSSFWorkbook workbook, ArrayList<String> listItems, HSSFCell cell, int startingValue, int increment) {
StringBuilder buffer = new StringBuilder();
int itemNumber = startingValue;
// Note that again, an HSSFCellStye object is required and that
// it's wrap text property should be set to 'true'
HSSFCellStyle wrapStyle = workbook.createCellStyle();
wrapStyle.setWrapText(true);
// with one difference; a number prefixed to the items text.
for (String listItem : listItems) {
buffer.append(itemNumber).append(". ");
buffer.append(listItem);
buffer.append("\n");
itemNumber += increment;
}
// The StringBuffer's contents are the source for the contents
// of the cell.
cell.setCellValue(new HSSFRichTextString(buffer.toString().trim()));
cell.setCellStyle(wrapStyle);
}
use of org.apache.poi.hssf.usermodel.HSSFCellStyle in project poi by apache.
the class CreateDateCells 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(0);
// Create a cell and put a date value in it. The first cell is not styled as a date.
HSSFCell cell = row.createCell(0);
cell.setCellValue(new Date());
// we style the second cell as a date (and time). It is important to create a new cell style from the workbook
// otherwise you can end up modifying the built in style and effecting not only this cell but other cells.
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
cell = row.createCell(1);
cell.setCellValue(new Date());
cell.setCellStyle(cellStyle);
// 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.HSSFCellStyle in project poi by apache.
the class HSSFReadWrite method testCreateSampleSheet.
/**
* given a filename this outputs a sample sheet with just a set of
* rows/cells.
*/
private static void testCreateSampleSheet(String outputFilename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
try {
HSSFSheet s = wb.createSheet();
HSSFCellStyle cs = wb.createCellStyle();
HSSFCellStyle cs2 = wb.createCellStyle();
HSSFCellStyle cs3 = wb.createCellStyle();
HSSFFont f = wb.createFont();
HSSFFont f2 = wb.createFont();
f.setFontHeightInPoints((short) 12);
f.setColor((short) 0xA);
f.setBold(true);
f2.setFontHeightInPoints((short) 10);
f2.setColor((short) 0xf);
f2.setBold(true);
cs.setFont(f);
cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)"));
cs2.setBorderBottom(BorderStyle.THIN);
cs2.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cs2.setFillForegroundColor((short) 0xA);
cs2.setFont(f2);
wb.setSheetName(0, "HSSF Test");
int rownum;
for (rownum = 0; rownum < 300; rownum++) {
HSSFRow r = s.createRow(rownum);
if ((rownum % 2) == 0) {
r.setHeight((short) 0x249);
}
for (int cellnum = 0; cellnum < 50; cellnum += 2) {
HSSFCell c = r.createCell(cellnum);
c.setCellValue(rownum * 10000 + cellnum + (((double) rownum / 1000) + ((double) cellnum / 10000)));
if ((rownum % 2) == 0) {
c.setCellStyle(cs);
}
c = r.createCell(cellnum + 1);
c.setCellValue(new HSSFRichTextString("TEST"));
// 50 characters divided by 1/20th of a point
s.setColumnWidth(cellnum + 1, (int) (50 * 8 / 0.05));
if ((rownum % 2) == 0) {
c.setCellStyle(cs2);
}
}
}
// draw a thick black border on the row at the bottom using BLANKS
rownum++;
rownum++;
HSSFRow r = s.createRow(rownum);
cs3.setBorderBottom(BorderStyle.THICK);
for (int cellnum = 0; cellnum < 50; cellnum++) {
HSSFCell c = r.createCell(cellnum);
c.setCellStyle(cs3);
}
s.addMergedRegion(new CellRangeAddress(0, 3, 0, 3));
s.addMergedRegion(new CellRangeAddress(100, 110, 100, 110));
// end draw thick black border
// create a sheet, set its title then delete it
wb.createSheet();
wb.setSheetName(1, "DeletedSheet");
wb.removeSheetAt(1);
// end deleted sheet
FileOutputStream out = new FileOutputStream(outputFilename);
try {
wb.write(out);
} finally {
out.close();
}
} finally {
wb.close();
}
}
use of org.apache.poi.hssf.usermodel.HSSFCellStyle 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();
}
Aggregations