use of org.apache.poi.hssf.usermodel.HSSFCell in project poi by apache.
the class Outlines method test1.
public String test1() {
sheet1.groupColumn(4, 7);
for (int row = 0; row < 200; row++) {
HSSFRow r = sheet1.createRow(row);
for (int column = 0; column < 200; column++) {
HSSFCell c = r.createCell(column);
c.setCellValue(column);
}
}
return "Two expanded groups.";
}
use of org.apache.poi.hssf.usermodel.HSSFCell in project poi by apache.
the class ReadWriteWorkbook method main.
public static void main(String[] args) throws IOException {
FileInputStream fileIn = null;
FileOutputStream fileOut = null;
try {
fileIn = new FileInputStream("workbook.xls");
POIFSFileSystem fs = new POIFSFileSystem(fileIn);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(2);
if (row == null)
row = sheet.createRow(2);
HSSFCell cell = row.getCell(3);
if (cell == null)
cell = row.createCell(3);
cell.setCellType(CellType.STRING);
cell.setCellValue("a test");
// Write the output to a file
fileOut = new FileOutputStream("workbookout.xls");
wb.write(fileOut);
} finally {
if (fileOut != null)
fileOut.close();
if (fileIn != null)
fileIn.close();
}
}
use of org.apache.poi.hssf.usermodel.HSSFCell in project poi by apache.
the class CreateCells 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 value in it.
HSSFCell cell = row.createCell(0);
cell.setCellValue(1);
// Or do it on one line.
row.createCell(1).setCellValue(1.2);
row.createCell(2).setCellValue("This is a string");
row.createCell(3).setCellValue(true);
// 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 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.HSSFCell 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();
}
}
Aggregations