本文整理汇总了Java中org.docx4j.wml.Tr类的典型用法代码示例。如果您正苦于以下问题:Java Tr类的具体用法?Java Tr怎么用?Java Tr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Tr类属于org.docx4j.wml包,在下文中一共展示了Tr类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: main
import org.docx4j.wml.Tr; //导入依赖的package包/类
/**
* 跟前面的做的一样, 我们再一次创建了一个表格, 并添加了三个单元格, 其中有两个
* 单元带有样式. 在新方法中我们传进表格行, 单元格内容, 是否为粗体及字体大小作
* 为参数. 你需要注意, 因为the Office Open specification规范定义这个属性是半个
* 点(half-point)大小, 因此字体大小需要是你想在Word中显示大小的两倍,
*/
public static void main (String[] args) throws Docx4JException {
wordMLPackage = WordprocessingMLPackage.createPackage();
factory = Context.getWmlObjectFactory();
Tbl table = factory.createTbl();
Tr tableRow = factory.createTr();
addRegularTableCell(tableRow, "Normal text");
addStyledTableCell(tableRow, "Bold text", true, null);
addStyledTableCell(tableRow, "Bold large text", true, "40");
table.getContent().add(tableRow);
addBorders(table);
wordMLPackage.getMainDocumentPart().addObject(table);
wordMLPackage.save(new java.io.File("src/main/files/HelloWord6.docx") );
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:24,代码来源:TableWithStyledContent.java
示例2: addMergedCell
import org.docx4j.wml.Tr; //导入依赖的package包/类
/**
* 我们创建一个单元格和单元格属性对象.
* 也创建了一个纵向合并对象. 如果合并值不为null, 将它设置到合并对象中. 然后将该对象添加到
* 单元格属性并将属性添加到单元格中. 最后设置单元格内容并将单元格添加到行中.
* 如果合并值为'restart', 表明要开始一个新行. 如果为null, 继续按前面的行处理, 也就是合并单元格.
*/
public void addMergedCell(Tr row, String content, String vMergeVal) {
Tc tableCell = factory.createTc();
TcPr tableCellProperties = new TcPr();
VMerge merge = new VMerge();
if(vMergeVal != null){
merge.setVal(vMergeVal);
}
tableCellProperties.setVMerge(merge);
tableCell.setTcPr(tableCellProperties);
if(content != null) {
tableCell.getContent().add(wmlPackage.getMainDocumentPart(). createParagraphOfText(content));
}
row.getContent().add(tableCell);
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:24,代码来源:WordprocessingMLPackageRender.java
示例3: main
import org.docx4j.wml.Tr; //导入依赖的package包/类
/**
* 首先我们创建包和对象工厂, 因此在类的随处我们都可以使用它们. 然后我们创建一个表格并添加
* 边框. 接下来我们创建一个表格行并在第一个域添加一些文本.
* 对于第二个域, 我们用与前面一样的图片创建一个段落并添加进去. 最后把行添加到表格中, 并将
* 表格添加到包中, 然后保存这个包.
*/
public static void main (String[] args) throws Exception {
wordMLPackage = WordprocessingMLPackage.createPackage();
factory = Context.getWmlObjectFactory();
Tbl table = factory.createTbl();
addBorders(table);
Tr tr = factory.createTr();
P paragraphOfText = wordMLPackage.getMainDocumentPart().createParagraphOfText("Field 1");
addTableCell(tr, paragraphOfText);
File file = new File("src/main/resources/iProfsLogo.png");
P paragraphWithImage = addInlineImageToParagraph(createInlineImage(file));
addTableCell(tr, paragraphWithImage);
table.getContent().add(tr);
wordMLPackage.getMainDocumentPart().addObject(table);
wordMLPackage.save(new java.io.File("src/main/files/HelloWord8.docx"));
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:28,代码来源:AddingAnInlineImageToTable.java
示例4: replaceTable
import org.docx4j.wml.Tr; //导入依赖的package包/类
public static void replaceTable(String[] placeholders, List<Map<String, String>> textToAdd,
WordprocessingMLPackage template) throws Docx4JException, JAXBException {
List<Tbl> tables = getTargetElements(template.getMainDocumentPart(), Tbl.class);
// 1. find the table
Tbl tempTable = getTable(tables, placeholders[0]);
List<Tr> rows = getTargetElements(tempTable, Tr.class);
// first row is header, second row is content
if (rows.size() == 2) {
// this is our template row
Tr templateRow = (Tr) rows.get(1);
for (Map<String, String> replacements : textToAdd) {
// 2 and 3 are done in this method
addRowToTable(tempTable, templateRow, replacements);
}
// 4. remove the template row
tempTable.getContent().remove(templateRow);
}
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:24,代码来源:WMLPackageUtils.java
示例5: getTblAllTr
import org.docx4j.wml.Tr; //导入依赖的package包/类
/**
* @Description: 得到表格所有的行
*/
public List<Tr> getTblAllTr(Tbl tbl) {
List<Object> objList = getAllElementFromObject(tbl, Tr.class);
List<Tr> trList = new ArrayList<Tr>();
if (objList == null) {
return trList;
}
for (Object obj : objList) {
if (obj instanceof Tr) {
Tr tr = (Tr) obj;
trList.add(tr);
}
}
return trList;
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:19,代码来源:Docx4j_工具类_S3_Test.java
示例6: setTrHeight
import org.docx4j.wml.Tr; //导入依赖的package包/类
/**
* @Description:设置tr高度
*/
public void setTrHeight(Tr tr, String heigth) {
TrPr trPr = getTrPr(tr);
CTHeight ctHeight = new CTHeight();
ctHeight.setVal(new BigInteger(heigth));
TrHeight trHeight = new TrHeight(ctHeight);
trHeight.set(trPr);
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:11,代码来源:Docx4j_工具类_S3_Test.java
示例7: getTcCellSizeWithMergeNum
import org.docx4j.wml.Tr; //导入依赖的package包/类
/**
* @Description: 得到行的列数
*/
public int getTcCellSizeWithMergeNum(Tr tr) {
int cellSize = 1;
List<Tc> tcList = getTrAllCell(tr);
if (tcList == null || tcList.size() == 0) {
return cellSize;
}
cellSize = tcList.size();
for (Tc tc : tcList) {
TcPr tcPr = getTcPr(tc);
GridSpan gridSpan = tcPr.getGridSpan();
if (gridSpan != null) {
cellSize += gridSpan.getVal().intValue() - 1;
}
}
return cellSize;
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:20,代码来源:Docx4j_工具类_S3_Test.java
示例8: removeTrByIndex
import org.docx4j.wml.Tr; //导入依赖的package包/类
/**
* @Description: 删除指定行 删除后行数减一
*/
public boolean removeTrByIndex(Tbl tbl, int index) {
boolean flag = false;
if (index < 0) {
return flag;
}
List<Object> objList = tbl.getContent();
if (objList == null) {
return flag;
}
int k = -1;
for (int i = 0, len = objList.size(); i < len; i++) {
Object obj = XmlUtils.unwrap(objList.get(i));
if (obj instanceof Tr) {
k++;
if (k == index) {
tbl.getContent().remove(i);
flag = true;
break;
}
}
}
return flag;
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:27,代码来源:Docx4j_工具类_S3_Test.java
示例9: addMergedCell
import org.docx4j.wml.Tr; //导入依赖的package包/类
/**
* 我们创建一个单元格和单元格属性对象.
* 也创建了一个纵向合并对象. 如果合并值不为null, 将它设置到合并对象中. 然后将该对象添加到
* 单元格属性并将属性添加到单元格中. 最后设置单元格内容并将单元格添加到行中.
*
* 如果合并值为'restart', 表明要开始一个新行. 如果为null, 继续按前面的行处理, 也就是合并单元格.
*/
private static void addMergedCell(Tr row, String content, String vMergeVal) {
Tc tableCell = factory.createTc();
TcPr tableCellProperties = new TcPr();
VMerge merge = new VMerge();
if(vMergeVal != null){
merge.setVal(vMergeVal);
}
tableCellProperties.setVMerge(merge);
tableCell.setTcPr(tableCellProperties);
if(content != null) {
tableCell.getContent().add(
wordMLPackage.getMainDocumentPart().
createParagraphOfText(content));
}
row.getContent().add(tableCell);
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:27,代码来源:TableWithMergedCells.java
示例10: setTableTrHeight
import org.docx4j.wml.Tr; //导入依赖的package包/类
public void setTableTrHeight(ObjectFactory factory, Tr tr, String heigth) {
TrPr trPr = tr.getTrPr();
if (trPr == null) {
trPr = factory.createTrPr();
}
CTHeight ctHeight = new CTHeight();
ctHeight.setVal(new BigInteger(heigth));
TrHeight trHeight = new TrHeight(ctHeight);
trHeight.set(trPr);
tr.setTrPr(trPr);
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:12,代码来源:Docx4J_例子2.java
示例11: setTableTrHeight
import org.docx4j.wml.Tr; //导入依赖的package包/类
public void setTableTrHeight(ObjectFactory factory,Tr tr,String heigth){
TrPr trPr=tr.getTrPr();
if(trPr==null){
trPr=factory.createTrPr();
}
CTHeight ctHeight=new CTHeight();
ctHeight.setVal(new BigInteger(heigth));
TrHeight trHeight=new TrHeight(ctHeight);
trHeight.set(trPr);
tr.setTrPr(trPr);
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:12,代码来源:Docx4J_简单例子2.java
示例12: main
import org.docx4j.wml.Tr; //导入依赖的package包/类
/**
* 创建一个带边框的表格并添加一行. 然后添加两个带内容的单元格并给定宽度.
*/
public static void main (String[] args) throws Docx4JException {
wordMLPackage = WordprocessingMLPackage.createPackage();
factory = Context.getWmlObjectFactory();
Tbl table = factory.createTbl();
addBorders(table);
Tr tr = factory.createTr();
addTableCellWithWidth(tr, "Field 1", 2500);
addTableCellWithWidth(tr, "Field 2", 0);
table.getContent().add(tr);
wordMLPackage.getMainDocumentPart().addObject(table);
wordMLPackage.save(new java.io.File("src/main/HelloWord133.docx") );
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:21,代码来源:SettingColumnWidthForTable.java
示例13: repeatRows
import org.docx4j.wml.Tr; //导入依赖的package包/类
private void repeatRows(final WordprocessingMLPackage document) {
for (TableRowCoordinates rCoords : tableRowsToRepeat.keySet()) {
List<Object> expressionContexts = tableRowsToRepeat.get(rCoords);
for (final Object expressionContext : expressionContexts) {
Tr rowClone = XmlUtils.deepCopy(rCoords.getRow());
DocumentWalker walker = new BaseDocumentWalker(rowClone) {
@Override
protected void onParagraph(P paragraph) {
placeholderReplacer.resolveExpressionsForParagraph(paragraph, expressionContext, document);
}
};
walker.walk();
rCoords.getParentTableCoordinates().getTable().getContent().add(rowClone);
}
rCoords.getParentTableCoordinates().getTable().getContent().remove(rCoords.getRow());
// TODO: remove "repeatTableRow"-comment from cloned rows!
}
}
开发者ID:thombergs,项目名称:docx-stamper,代码行数:19,代码来源:RepeatProcessor.java
示例14: paragraphsInNestedTablesAreRemoved
import org.docx4j.wml.Tr; //导入依赖的package包/类
private void paragraphsInNestedTablesAreRemoved(WordprocessingMLPackage document) {
final List<Tbl> tables = new ArrayList<>();
CoordinatesWalker walker = new BaseCoordinatesWalker(document) {
@Override
protected void onTable(TableCoordinates tableCoordinates) {
tables.add(tableCoordinates.getTable());
}
};
walker.walk();
Tbl nestedTable = tables.get(1);
Tc cell = (Tc) ((JAXBElement) ((Tr) nestedTable.getContent().get(1)).getContent().get(0)).getValue();
P p1 = (P) cell.getContent().get(0);
Assert.assertEquals(1, cell.getContent().size());
Assert.assertEquals("This paragraph stays untouched.", new ParagraphWrapper(p1).getText());
}
开发者ID:thombergs,项目名称:docx-stamper,代码行数:18,代码来源:ConditionalDisplayOfParagraphsTest.java
示例15: addTableCell
import org.docx4j.wml.Tr; //导入依赖的package包/类
private void addTableCell(Tr tableRow, BandElement be, P paragraph, int width, Map<String, Object> style, int horizontalMergedCells, String verticalMergedVal, boolean isImage) {
Tc tableCell = factory.createTc();
if (isImage) {
addImageCellStyle(tableCell, be, paragraph, style);
} else {
addHyperlinkCellStyle(tableCell, be, paragraph, style);
}
setCellWidth(tableCell, width);
setCellVMerge(tableCell, verticalMergedVal);
setCellHMerge(tableCell, horizontalMergedCells);
if (!isImage) {
if ((be != null) && !be.isWrapText()) {
setCellNoWrap(tableCell);
}
}
tableRow.getContent().add(tableCell);
}
开发者ID:nextreports,项目名称:nextreports-engine,代码行数:18,代码来源:DocxExporter.java
示例16: addRowToTable
import org.docx4j.wml.Tr; //导入依赖的package包/类
public static void addRowToTable(Tbl reviewtable, Tr templateRow, Map<String, String> replacements) {
Tr workingRow = (Tr) XmlUtils.deepCopy(templateRow);
List<?> textElements = getTargetElements(workingRow, Text.class);
for (Object object : textElements) {
Text text = (Text) object;
String replacementValue = (String) replacements.get(text.getValue());
if (replacementValue != null)
text.setValue(replacementValue);
}
reviewtable.getContent().add(workingRow);
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:13,代码来源:WMLPackageUtils.java
示例17: newTable
import org.docx4j.wml.Tr; //导入依赖的package包/类
public Tbl newTable(int row,int cell) {
//创建表格对象
Tbl table = factory.createTbl();
for (int i = 0; i < row; i++) {
Tr tableRow = factory.createTr();
for (int j = 0; j < cell; j++) {
newCell(tableRow, "");
}
table.getContent().add(tableRow);
}
return table;
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:13,代码来源:DocxElementWmlRender.java
示例18: addTableRowWithMergedCells
import org.docx4j.wml.Tr; //导入依赖的package包/类
/**
* 本方法创建一行, 并向其中添加合并列, 然后添加再两个普通的单元格. 随后将该行添加到表格
*/
public void addTableRowWithMergedCells(String mergedContent, String field1Content, String field2Content, Tbl table) {
Tr tableRow1 = factory.createTr();
addMergedColumn(tableRow1, mergedContent);
addTableCell(tableRow1, field1Content);
addTableCell(tableRow1, field2Content);
table.getContent().add(tableRow1);
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:14,代码来源:WordprocessingMLPackageRender.java
示例19: addMergedColumn
import org.docx4j.wml.Tr; //导入依赖的package包/类
/**
* 本方法添加一个合并了其它行单元格的列单元格. 如果传进来的内容是null, 传空字符串和一个为null的合并值.
*/
public void addMergedColumn(Tr row, String content) {
if (content == null) {
addMergedCell(row, "", null);
} else {
addMergedCell(row, content, "restart");
}
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:11,代码来源:WordprocessingMLPackageRender.java
示例20: addTableCellWithWidth
import org.docx4j.wml.Tr; //导入依赖的package包/类
/**
* 本方法创建一个单元格并将给定的内容添加进去.
* 如果给定的宽度大于0, 将这个宽度设置到单元格.
* 最后, 将单元格添加到行中.
*/
public void addTableCellWithWidth(Tr row, String content, int width){
Tc tableCell = factory.createTc();
tableCell.getContent().add(wmlPackage.getMainDocumentPart().createParagraphOfText(content));
if (width > 0) {
setCellWidth(tableCell, width);
}
row.getContent().add(tableCell);
}
开发者ID:vindell,项目名称:docx4j-template,代码行数:14,代码来源:WordprocessingMLPackageRender.java
注:本文中的org.docx4j.wml.Tr类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论