Table heading

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?

@Ragulkr

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");
    }
}

Explanation:

  • Document and DocumentBuilder: A new document is created using the Document class, and a DocumentBuilder is instantiated to facilitate the insertion of content.
  • HTML Table: The HTML string defines a table with specific styles for vertical writing mode and rotation. The white-space: nowrap; style ensures that the text does not wrap.
  • Insert HTML: The insertHtml method of the DocumentBuilder is used to insert the HTML table into the document.
  • Save Document: Finally, the document is saved in the desired format.

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