|| headerColumnNumber > numCols) {
throw new IllegalArgumentException("Can not create table with the given parameters:\n"
+ "Rows " + numRows + ", Columns " + numCols + ", HeaderRows " + headerRowNumber + ", HeaderColumns " + headerColumnNumber);
}
OdfFileDom dom = document.getContentDom();
OdfOfficeAutomaticStyles styles = dom.getAutomaticStyles();
//1. create table element
TableTableElement newTEle = (TableTableElement) OdfXMLFactory.newOdfElement(dom,
OdfName.newName(OdfDocumentNamespace.TABLE, "table"));
String tablename = getUniqueTableName(document);
newTEle.setTableNameAttribute(tablename);
//create style
OdfStyle tableStyle = styles.newStyle(OdfStyleFamily.Table);
String stylename = tableStyle.getStyleNameAttribute();
tableStyle.setProperty(StyleTablePropertiesElement.Width, DEFAULT_TABLE_WIDTH + "in");
tableStyle.setProperty(StyleTablePropertiesElement.Align, DEFAULT_TABLE_ALIGN);
newTEle.setStyleName(stylename);
// 2. create column elements
// 2.0 create column style
OdfStyle columnStyle = styles.newStyle(OdfStyleFamily.TableColumn);
String columnStylename = columnStyle.getStyleNameAttribute();
columnStyle.setProperty(StyleTableColumnPropertiesElement.ColumnWidth,
new DecimalFormat("000.0000").format(DEFAULT_TABLE_WIDTH / numCols) + "in");
columnStyle.setProperty(StyleTableColumnPropertiesElement.RelColumnWidth, Math.round(DEFAULT_REL_TABLE_WIDTH / numCols) + "*");
// 2.1 create header column elements
if (headerColumnNumber > 0) {
TableTableHeaderColumnsElement headercolumns = (TableTableHeaderColumnsElement) OdfXMLFactory.newOdfElement(dom, OdfName.newName(OdfDocumentNamespace.TABLE, "table-header-columns"));
TableTableColumnElement headercolumn = (TableTableColumnElement) OdfXMLFactory.newOdfElement(dom, OdfName.newName(OdfDocumentNamespace.TABLE, "table-column"));
headercolumn.setTableNumberColumnsRepeatedAttribute(headerColumnNumber);
headercolumns.appendChild(headercolumn);
newTEle.appendChild(headercolumns);
headercolumn.setStyleName(columnStylename);
}
//2.2 create common column elements
TableTableColumnElement columns = (TableTableColumnElement) OdfXMLFactory.newOdfElement(dom,
OdfName.newName(OdfDocumentNamespace.TABLE, "table-column"));
columns.setTableNumberColumnsRepeatedAttribute(numCols - headerColumnNumber);
columns.setStyleName(columnStylename);
newTEle.appendChild(columns);
//3. create row elements
//3.0 create 4 kinds of styles
OdfStyle lefttopStyle=null,leftbottomStyle=null,righttopStyle=null,rightbottomStyle=null;
if (!document.getMediaTypeString().equals(OdfMediaType.SPREADSHEET.getMediaTypeString())) {
lefttopStyle = styles.newStyle(OdfStyleFamily.TableCell);
setLeftTopBorderStyleProperties(lefttopStyle);
leftbottomStyle = styles.newStyle(OdfStyleFamily.TableCell);
setLeftBottomBorderStylesProperties(leftbottomStyle);
righttopStyle = styles.newStyle(OdfStyleFamily.TableCell);
setRightTopBorderStyleProperties(righttopStyle);
rightbottomStyle = styles.newStyle(OdfStyleFamily.TableCell);
setRightBottomBorderStylesProperties(rightbottomStyle);
}
//3.1 create header row elements
if( headerRowNumber > 0)