Using insertHtml
method to insert html table.
Using write-mode: vertical-rl, transform: rotate(180deg), whitespace: nowrap
. Styles in table <th>
. I am not getting vertical header in table
How to convert in aspose word?
Using insertHtml
method to insert html table.
Using write-mode: vertical-rl, transform: rotate(180deg), whitespace: nowrap
. Styles in table <th>
. I am not getting vertical header in table
How to convert in aspose word?
To convert an HTML table into an Aspose.Words document while applying specific styles such as vertical writing mode, rotation, and whitespace handling, you can use the DocumentBuilder
class in Aspose.Words. Below is a code example that demonstrates how to achieve this:
import com.aspose.words.*;
public class HtmlTableToAsposeWords {
public static void main(String[] args) throws Exception {
// Create a new document
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Define your HTML table with the required styles
String htmlTable = "<table style='writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap;'>" +
"<tr><th style='background-color: #f0f0f0;'>Header 1</th>" +
"<th style='background-color: #f0f0f0;'>Header 2</th></tr>" +
"<tr><td>Row 1, Cell 1</td><td>Row 1, Cell 2</td></tr>" +
"<tr><td>Row 2, Cell 1</td><td>Row 2, Cell 2</td></tr>" +
"</table>";
// Insert the HTML into the document
builder.insertHtml(htmlTable);
// Save the document
doc.save("HtmlTableToAsposeWords.docx");
}
}
Document
class, and a DocumentBuilder
is instantiated to facilitate the insertion of content.white-space: nowrap;
style ensures that the text does not wrap.insertHtml
method of the DocumentBuilder
is used to insert the HTML table into the document.This approach allows you to convert an HTML table with specific styles into an Aspose.Words document effectively. Make sure to adjust the HTML and styles according to your specific requirements.
@Ragulkr You can use writing-mode
attaribute in html to specify text direction in cells:
<html>
<body>
<table cellspacing="0" cellpadding="0" style="border:0.75pt solid #000000;">
<tr>
<td style="writing-mode:tb-rl;">
Vertical
</td>
<td style="writing-mode:tb-rl;">
Vertical
</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>
You can specify text direction it table cell programmatically using CellFormat.Orientation property