Table Cell text/formatting with more than one font

Hi,

My client want to have more than one font (family, size, type, kerning, spacing) in one cell.

Is this possible?

Or, can it be done with more cells as children of the parent cell and what would be possible issues with this approach?

Thanks,

Marcel

Hi Marcel,

Thank you very much for your inquiry.

Yes, it is possible. You can have text in more then one font in one cell using com.aspose.words.Font and com.aspose.words.ParagraphFormat classes to specify the font family, size, type, spacing etc. If you are generating documents using com.aspose.words.DocumentBuilder, following code snippet should help you understand it in a better way:

String csPath = "C:\\Temp\\";
// Create new document and Document builder.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a table cell and some text in it.
builder.insertCell();
builder.write("Text in cell 1.");
// Insert another cell.
builder.insertCell();
// Set font color to BLUE, turn underlining 
// the text on and write some text.
builder.getFont().setColor(Color.BLUE);
builder.getFont().setUnderline(Underline.SINGLE);
builder.writeln("Text in cell 2 - line 1");
// clear formatting settings.
builder.getFont().clearFormatting();
// Set font to bold, set font to Verdana 8.5, 
// font color to RED, dotted underlining and write some text
builder.setBold(true);
builder.getFont().setName("Verdana");
builder.getFont().setSize(8.5);
builder.getFont().setColor(Color.RED);
builder.getFont().setUnderline(Underline.DOTTED);
builder.writeln("Text in cell 2 - line 2");
// clear formatting settings.
builder.getFont().clearFormatting();
// End this row in table.
builder.endRow();
// Insert cell and write some text with default formatting
builder.insertCell();
builder.writeln("Text in cell 3 - line 1");
// Set font size to 24, set font to Calibri and set 
// spacing after line to 12 points, then write some text
builder.getFont().setSize(24);
builder.getFont().setName("Calibri");
builder.getParagraphFormat().setSpaceAfter(12);
builder.writeln("Formatting applied in cell 3 - line 2");
// Clear font and paragraph formatting
builder.getFont().clearFormatting();
builder.getParagraphFormat().clearFormatting();
// Write something with default formatting
builder.writeln("Back to normal, cell 3 - line 3 ");
// Insert another cell and  write some text
builder.insertCell();
builder.write("Text in cell 4");
// End second row and table.
builder.endRow();
builder.endTable();
// Save final document.
doc.save(csPath + "out.docx");

To further understand the features of DocumentBuilder please look here. To study how Styles are applied, please have a look here. If you are referring to applying styles in already existing document, you can traverse through nodes and apply the styles wherever required.
About the second part of your question, I don’t think that insertion of new cell nodes inside a parent cell is an applicable solution. Please go through the Aspose.Words Document Object Model specification here for further details.

Please have a look at the attached document which is created using Aspose.Words and contains the table cells and formatted text inside them.

Hope this helps. Please feel free to ask if you have any more queries.