use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class CreateTable method main.
public static void main(String[] args) throws IOException {
Workbook wb = new XSSFWorkbook();
XSSFSheet sheet = (XSSFSheet) wb.createSheet();
//Create
XSSFTable table = sheet.createTable();
table.setDisplayName("Test");
CTTable cttable = table.getCTTable();
//Style configurations
CTTableStyleInfo style = cttable.addNewTableStyleInfo();
style.setName("TableStyleMedium2");
style.setShowColumnStripes(false);
style.setShowRowStripes(true);
//Set which area the table should be placed in
AreaReference reference = new AreaReference(new CellReference(0, 0), new CellReference(2, 2));
cttable.setRef(reference.formatAsString());
cttable.setId(1);
cttable.setName("Test");
cttable.setTotalsRowCount(1);
CTTableColumns columns = cttable.addNewTableColumns();
columns.setCount(3);
CTTableColumn column;
XSSFRow row;
XSSFCell cell;
for (int i = 0; i < 3; i++) {
//Create column
column = columns.addNewTableColumn();
column.setName("Column");
column.setId(i + 1);
//Create row
row = sheet.createRow(i);
for (int j = 0; j < 3; j++) {
//Create cell
cell = row.createCell(j);
if (i == 0) {
cell.setCellValue("Column" + j);
} else {
cell.setCellValue("0");
}
}
}
FileOutputStream fileOut = new FileOutputStream("ooxml-table.xlsx");
wb.write(fileOut);
fileOut.close();
wb.close();
}
use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class CreateUserDefinedDataFormats method main.
public static void main(String[] args) throws IOException {
//or new HSSFWorkbook();
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("format sheet");
CellStyle style;
DataFormat format = wb.createDataFormat();
Row row;
Cell cell;
short rowNum = 0;
short colNum = 0;
row = sheet.createRow(rowNum);
cell = row.createCell(colNum);
cell.setCellValue(11111.25);
style = wb.createCellStyle();
style.setDataFormat(format.getFormat("0.0"));
cell.setCellStyle(style);
row = sheet.createRow(++rowNum);
cell = row.createCell(colNum);
cell.setCellValue(11111.25);
style = wb.createCellStyle();
style.setDataFormat(format.getFormat("#,##0.0000"));
cell.setCellStyle(style);
FileOutputStream fileOut = new FileOutputStream("ooxml_dataFormat.xlsx");
wb.write(fileOut);
fileOut.close();
wb.close();
}
use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class CustomXMLMapping method main.
public static void main(String[] args) throws Exception {
OPCPackage pkg = OPCPackage.open(args[0]);
XSSFWorkbook wb = new XSSFWorkbook(pkg);
for (XSSFMap map : wb.getCustomXMLMappings()) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
ByteArrayOutputStream os = new ByteArrayOutputStream();
exporter.exportToXML(os, true);
String xml = os.toString("UTF-8");
System.out.println(xml);
}
pkg.close();
}
use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class WorkbookProperties method main.
public static void main(String[] args) throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
workbook.createSheet("Workbook Properties");
POIXMLProperties props = workbook.getProperties();
/**
* Extended properties are a predefined set of metadata properties
* that are specifically applicable to Office Open XML documents.
* Extended properties consist of 24 simple properties and 3 complex properties stored in the
* part targeted by the relationship of type
*/
POIXMLProperties.ExtendedProperties ext = props.getExtendedProperties();
ext.getUnderlyingProperties().setCompany("Apache Software Foundation");
ext.getUnderlyingProperties().setTemplate("XSSF");
/**
* Custom properties enable users to define custom metadata properties.
*/
POIXMLProperties.CustomProperties cust = props.getCustomProperties();
cust.addProperty("Author", "John Smith");
cust.addProperty("Year", 2009);
cust.addProperty("Price", 45.50);
cust.addProperty("Available", true);
FileOutputStream out = new FileOutputStream("workbook.xlsx");
workbook.write(out);
out.close();
workbook.close();
}
use of org.apache.poi.xssf.usermodel.XSSFWorkbook in project poi by apache.
the class WorkingWithBorders method main.
public static void main(String[] args) throws IOException {
//or new HSSFWorkbook();
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("borders");
// Create a row and put some cells in it. Rows are 0 based.
Row row = sheet.createRow((short) 1);
// Create a cell and put a value in it.
Cell cell = row.createCell((short) 1);
cell.setCellValue(4);
// Style the cell with borders all around.
CellStyle style = wb.createCellStyle();
style.setBorderBottom(BorderStyle.THIN);
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderLeft(BorderStyle.THIN);
style.setLeftBorderColor(IndexedColors.GREEN.getIndex());
style.setBorderRight(BorderStyle.THIN);
style.setRightBorderColor(IndexedColors.BLUE.getIndex());
style.setBorderTop(BorderStyle.MEDIUM_DASHED);
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
cell.setCellStyle(style);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("xssf-borders.xlsx");
wb.write(fileOut);
fileOut.close();
wb.close();
}
Aggregations