Controlling the font in a table cell (Java)

Using the Java API’s, I’m not sure how I can control the font of a table cell.
Attached is a sample of the table I’m trying to produce. Here’s the code I currently have

com.aspose.words.Document doc = new com.aspose.words.Document(new ByteArrayInputStream(uploadFile.getFileData());
com.aspose.words.DocumentBuilder builder = new com.aspose.words.DocumentBuilder(doc);
builder.getRowFormat().setHeadingFormat(true);
builder.getRowFormat().setAllowBreakAcrossPages(true);
builder.insertCell();
builder.getCellFormat().setWidth(30 + 125 + 325 + 75 + 30 + 30);
builder.getCellFormat().setHorizontalMerge(com.aspose.words.CellMerge.FIRST);
builder.getCellFormat().setVerticalAlignment(com.aspose.words.CellVerticalAlignment.CENTER);
builder.writeln("This is row 1 cell 1");
builder.insertCell();
builder.getCellFormat().setWidth(0);
builder.getCellFormat().setHorizontalMerge(com.aspose.words.CellMerge.PREVIOUS);
builder.insertCell();
builder.getCellFormat().setWidth(0);
builder.getCellFormat().setHorizontalMerge(com.aspose.words.CellMerge.PREVIOUS);
builder.insertCell();
builder.getCellFormat().setWidth(0);
builder.getCellFormat().setHorizontalMerge(com.aspose.words.CellMerge.PREVIOUS);
builder.insertCell();
builder.getCellFormat().setWidth(0);
builder.getCellFormat().setHorizontalMerge(com.aspose.words.CellMerge.PREVIOUS);
builder.insertCell();
builder.getCellFormat().setWidth(0);
builder.getCellFormat().setHorizontalMerge(com.aspose.words.CellMerge.PREVIOUS);
builder.endRow();
builder.getRowFormat().setAllowBreakAcrossPages(true);
builder.insertCell();
builder.getCellFormat().setWidth(30);
builder.getCellFormat().setHorizontalMerge(com.aspose.words.CellMerge.NONE);
builder.getCellFormat().setVerticalAlignment(com.aspose.words.CellVerticalAlignment.CENTER);
builder.writeln("Lvl");
builder.insertCell();
builder.getCellFormat().setWidth(150);
builder.getCellFormat().setVerticalAlignment(com.aspose.words.CellVerticalAlignment.CENTER);
builder.writeln("Section");
builder.insertCell();
builder.getCellFormat().setWidth(325);
builder.getCellFormat().setVerticalAlignment(com.aspose.words.CellVerticalAlignment.CENTER);
builder.writeln("Critical Function");
builder.insertCell();
builder.getCellFormat().setWidth(75);
builder.getCellFormat().setVerticalAlignment(com.aspose.words.CellVerticalAlignment.CENTER);
builder.writeln("Critical # Staff");
builder.insertCell();
builder.getCellFormat().setWidth(30);
builder.getCellFormat().setVerticalAlignment(com.aspose.words.CellVerticalAlignment.CENTER);
builder.writeln("RTO");
builder.insertCell();
builder.getCellFormat().setWidth(30);
builder.getCellFormat().setVerticalAlignment(com.aspose.words.CellVerticalAlignment.CENTER);
builder.writeln("W/S");
builder.endRow();

builder.endTable();

Hi, Paul,

In fact, using the Java API is very little differs from using the Net API. The best point to get a structural view of using API is Aspose.Words Wiki: https://docs.aspose.com/words/net/. It’s also the section that declares Java API differences: https://docs.aspose.com/words/net/product-overview/. In the section “Building Documents Dynamically” you can find how to insert document elements (and tables too): https://docs.aspose.com/words/net/programming-with-documents/

I can’t to know what you exactly want to do with your sample, but I build a similar table with that code:

// initialize Document and DocumentBuilder
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// set default values
builder.getRowFormat().setAllowBreakAcrossPages(true);
builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
// heading row
builder.getRowFormat().setHeadingFormat(true);
builder.insertCell();
builder.getCellFormat().setWidth(30 + 125 + 325 + 75 + 30 + 30);
builder.writeln("This is row 1 cell 1");
builder.endRow();
// next row
builder.getRowFormat().setHeadingFormat(false);
builder.insertCell();
builder.getCellFormat().setWidth(30);
builder.writeln("Lvl");
builder.insertCell();
builder.getCellFormat().setWidth(125);
builder.writeln("Section");
builder.insertCell();
builder.getCellFormat().setWidth(325);
builder.writeln("Critical Function");
builder.insertCell();
builder.getCellFormat().setWidth(75);
builder.writeln("Critical # Staff");
builder.insertCell();
builder.getCellFormat().setWidth(30);
builder.writeln("RTO");
builder.insertCell();
builder.getCellFormat().setWidth(30);
builder.writeln("W/S");
builder.endRow();
builder.endTable();
doc.save("C:\tmp\pwatson_test_1.doc");

Best Regards,