use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow in project poi by apache.
the class AligningCells method centerAcrossSelection.
/**
* Center a text over multiple columns using ALIGN_CENTER_SELECTION
*
* @param wb the workbook
* @param row the row to create the cell in
* @param start_column the column number to create the cell in and where the selection starts
* @param end_column the column number where the selection ends
* @param valign the horizontal alignment for the cell.
*/
private static void centerAcrossSelection(XSSFWorkbook wb, XSSFRow row, int start_column, int end_column, VerticalAlignment valign) {
CreationHelper ch = wb.getCreationHelper();
// Create cell style with ALIGN_CENTER_SELECTION
XSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setAlignment(HorizontalAlignment.CENTER_SELECTION);
cellStyle.setVerticalAlignment(valign);
// Create cells over the selected area
for (int i = start_column; i <= end_column; i++) {
XSSFCell cell = row.createCell(i);
cell.setCellStyle(cellStyle);
}
// Set value to the first cell
XSSFCell cell = row.getCell(start_column);
cell.setCellValue(ch.createRichTextString("Align It"));
// Make the selection
CTRowImpl ctRow = (CTRowImpl) row.getCTRow();
// Add object with format start_coll:end_coll. For example 1:3 will span from
// cell 1 to cell 3, where the column index starts with 0
//
// You can add multiple spans for one row
Object span = start_column + ":" + end_column;
List<Object> spanList = new ArrayList<Object>();
spanList.add(span);
//add spns to the row
ctRow.setSpans(spanList);
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow in project poi by apache.
the class XWPFFootnote method getTableCell.
/**
* get the TableCell which belongs to the TableCell
*
* @param cell
* @see org.apache.poi.xwpf.usermodel.IBody#getTableCell(CTTc cell)
*/
public XWPFTableCell getTableCell(CTTc cell) {
XmlCursor cursor = cell.newCursor();
cursor.toParent();
XmlObject o = cursor.getObject();
if (!(o instanceof CTRow)) {
return null;
}
CTRow row = (CTRow) o;
cursor.toParent();
o = cursor.getObject();
cursor.dispose();
if (!(o instanceof CTTbl)) {
return null;
}
CTTbl tbl = (CTTbl) o;
XWPFTable table = getTable(tbl);
if (table == null) {
return null;
}
XWPFTableRow tableRow = table.getRow(row);
if (tableRow == null) {
return null;
}
return tableRow.getTableCell(cell);
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow in project poi by apache.
the class XWPFHeaderFooter method getTableCell.
/**
* get the TableCell which belongs to the TableCell
*
* @param cell
*/
public XWPFTableCell getTableCell(CTTc cell) {
XmlCursor cursor = cell.newCursor();
cursor.toParent();
XmlObject o = cursor.getObject();
if (!(o instanceof CTRow)) {
cursor.dispose();
return null;
}
CTRow row = (CTRow) o;
cursor.toParent();
o = cursor.getObject();
cursor.dispose();
if (!(o instanceof CTTbl)) {
return null;
}
CTTbl tbl = (CTTbl) o;
XWPFTable table = getTable(tbl);
if (table == null) {
return null;
}
XWPFTableRow tableRow = table.getRow(row);
return tableRow.getTableCell(cell);
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow in project poi by apache.
the class XWPFTable method insertNewTableRow.
/**
* inserts a new tablerow
*
* @param pos
* @return the inserted row
*/
public XWPFTableRow insertNewTableRow(int pos) {
if (pos >= 0 && pos <= tableRows.size()) {
CTRow row = ctTbl.insertNewTr(pos);
XWPFTableRow tableRow = new XWPFTableRow(row, this);
tableRows.add(pos, tableRow);
return tableRow;
}
return null;
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow in project poi by apache.
the class XWPFTableCell method getTableCell.
/**
* get the TableCell which belongs to the TableCell
*/
public XWPFTableCell getTableCell(CTTc cell) {
XmlCursor cursor = cell.newCursor();
cursor.toParent();
XmlObject o = cursor.getObject();
if (!(o instanceof CTRow)) {
return null;
}
CTRow row = (CTRow) o;
cursor.toParent();
o = cursor.getObject();
cursor.dispose();
if (!(o instanceof CTTbl)) {
return null;
}
CTTbl tbl = (CTTbl) o;
XWPFTable table = getTable(tbl);
if (table == null) {
return null;
}
XWPFTableRow tr = table.getRow(row);
if (tr == null) {
return null;
}
return tr.getTableCell(cell);
}
Aggregations