Show table header in verticle

I am using the InsertHtml method for preparing a Word document while using mail merge. In my HTML I have used Writing-mode='vertical-rl' that displays some header text vertically but when I use executeWithRegion the converted word file displays the header text horizontally.
Please refer to the attached screenshots for a better understanding

As you can see in the attached screenshot, the LastName and Age are vertical but after conversion to word, this header text also displays horizontally.
Is there any solution when using inserthtml method?

@SachinSingh Could you please provide your html and documents here for testing? We will check the scenario and provide you more information.

sure,
here is the HTML

<table style='border:1px solid black; width:100%;display:inline-table;font:arial;font-size:7pt'><thead><tr style='border: 1px solid black;background-color:#d9d9d9'><th style='border: 1px solid black;'>Candidate Name</th><th style='border: 1px solid black;'>ID Number</th><th style='border: 1px solid black;'>Interview Date</th><th style='border: 1px solid black;'><span style='writing-mode: vertical-rl;transform: rotate(180deg);text-align: left;max-height: 150px;'>Interviewer1's Score</span></th><th style='border: 1px solid black;'><span style='writing-mode: vertical-rl;transform: rotate(180deg);text-align: left;max-height: 150px;'>Interviewer2's Score</span></th><th style='border: 1px solid black;'>Final Score</th><th style='border: 1px solid black;'><span style='writing-mode: vertical-rl;transform: rotate(180deg);text-align: left;max-height: 150px;'>Interviewer1's Commment</span></th><th style='border: 1px solid black;'><span style='writing-mode: vertical-rl;transform: rotate(180deg);text-align: left;max-height: 150px;'>Interviewer2's Commment</span></th><th style='border: 1px solid black;'>Application Status</th><th style='border: 1px solid black;'>ApplicantType</th></tr></thead><tbody><tr style='border: 1px solid black;'><td style='border: 1px solid black;'>Evaluation  </td><td style='border: 1px solid black;'>3141YJZ</td><td style='border: 1px solid black;'>02-Sep-23</td><td style='border: 1px solid black;'>40</td><td style='border: 1px solid black;'>40</td><td style='border: 1px solid black;'>80</td><td style='border: 1px solid black;'>c4</td><td style='border: 1px solid black;'>C1</td><td style='border: 1px solid black;'>Selected</td><td style='border: 1px solid black;'>External</td></tr><tr style='border: 1px solid black;'><td style='border: 1px solid black;'>Sachin  Singh</td><td style='border: 1px solid black;'>A243SYI</td><td style='border: 1px solid black;'>13-Sep-23</td><td style='border: 1px solid black;'>20</td><td style='border: 1px solid black;'></td><td style='border: 1px solid black;'>20</td><td style='border: 1px solid black;'>NA</td><td style='border: 1px solid black;'></td><td style='border: 1px solid black;'>Selected</td><td style='border: 1px solid black;'>External</td></tr></tbody></table>

I want interviewerscore and Interviewercomment header columns should be in vertical
I am actually fetching the data from the database and then preparing the HTML in c# then I am preparing a DataTable and Adding one column to that data table with the Html, later I am using executewithRegions and on FieldMerging Callback event i am using InsertHtml

DataTable dt = new DataTable("tblAssessmentDetails");
DataColumn dtaColumn;
DataRow myDataRow;
dtaColumn = new DataColumn();

dtaColumn.DataType = typeof(String);

dtaColumn.ColumnName = "AssessmentDetails";
dt.Columns.Add(dtaColumn);

myDataRow = dt.NewRow();

myDataRow["AssessmentDetails"] = str;
dt.Rows.Add(myDataRow);
ds.Tables.Add(dt);


if (e.DocumentFieldName == "AssessmentDetails")
{
    // Add parsed HTML data to the document's body.
    DocumentBuilder builder = new DocumentBuilder(e.Document);
    builder.MoveToMergeField(e.DocumentFieldName);
    builder.InsertHtml((string)e.FieldValue, true);

    // Since we have already inserted the merged content manually,
    // we will not need to respond to this event by returning content via the "Text" property. 
    e.Text = string.Empty;
}

The Doc file sipmly contain one Merge tag as below

«TableStart:tblAssessmentDetails»
     «AssessmentDetails»
«TableEnd:tblAssessmentDetails»

Note:- you can get the HTML by editing the post.

@SachinSingh The behavior is expected. Aspose.Words mimics MS Word behavior. If you open the provided HTML in MS Word text rotation will also ne ignored.
As a workaround, I can suggest you to use writing-mode in table cell. For example see the following HTML:

<html>
<body>
    <table>
        <tr>
            <td style="">Horizontal</td>
            <td style="writing-mode:tb-rl; -moz-transform:rotate(180deg); -ms-transform:rotate(180deg); transform:rotate(180deg); -webkit-transform:rotate(180deg)">Vertical</td>
            <td style="writing-mode:tb-rl;">Vertical</td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </table>
</body>
</html>

No, even this doesn’t work
here is the screenshot

However i found the solution, we need to use mso-rotate:-90 on td, now it is working fine.

@alexey.noskov but after mail merge even mso-rotate:-90 is not working and Word is downloading without applying CSS.

@SachinSingh I have tested with the HTML provided in my previous answer and it works as expected. Here is code used for testing:

Document doc = new Document(@"C:\Temp\in.docx");
doc.MailMerge.FieldMergingCallback = new InsertHtmlFieldMergingCallback();
doc.MailMerge.Execute(new string[] { "test" }, new string[] { File.ReadAllText(@"C:\Temp\in.html") });
doc.Save(@"C:\Temp\out.docx");
private class InsertHtmlFieldMergingCallback : IFieldMergingCallback
{
    public void FieldMerging(FieldMergingArgs args)
    {
        DocumentBuilder builder = new DocumentBuilder(args.Document);
        builder.MoveToField(args.Field, true);
        builder.InsertHtml((string)args.FieldValue);
        args.FieldValue = null;
    }

    public void ImageFieldMerging(ImageFieldMergingArgs args)
    {
        // Do nothing.
    }
}

in.docx (12.3 KB)
in.zip (320 Bytes)
out.docx (10.1 KB)

@alexey.noskov i am using executewithregions as i have multiple c# datatables and with that all my styles on html tables are being lost. I don’t know why so.

@SachinSingh Which version of Aspose.Words do you use? Have you tried using the latest 23.9 version?
Also, please note, Aspose.Words is designed to work with MS Word documents at first. While loading HTML document, it is converted to Aspose.Words DOM and due to differences in HTML documents and MS Word documents object models it is not always possible to provide 100% fidelity after processing HTML document.

@alexey.noskov i am using Aspose.Words for .NET (Description) version 21.3.0.0 . Isn’t it possible for this version? As in my Organization i can’t change the version it may affect other functionalities.

@SachinSingh I have tested with 21.3 version and the output is correct: out.docx (10.2 KB)

Thanks, it is working now. Thanks for the help.

1 Like