Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8455613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:19:44+00:00 2026-06-10T12:19:44+00:00

I want to apply a text alignment in table cell in a table with

  • 0

I want to apply a text alignment in table cell in a table with OpenXML.

I don’t understand why it is not applied.

Table table = new Table();
TableRow tableHeader = new TableRow();
table.AppendChild<TableRow>(tableHeader);
TableCell tableCell = new TableCell();
tableHeader.AppendChild<TableCell>(tableCell);
Paragraph paragraph = new Paragraph(new Run(new Text("test")));
ParagraphProperties paragraphProperties = new ParagraphProperties();
JustificationValues? justification = GetJustificationFromString("centre");
if (justification != null)
{
     paragraphProperties.AppendChild<Justification>(new Justification() { Val = justification });
}
paragraph.AppendChild<ParagraphProperties>(paragraphProperties);
tableCell.AppendChild<Paragraph>(paragraph);


public static JustificationValues? GetJustificationFromString(string alignment)
{
    switch(alignment)
    {
        case "centre" : return JustificationValues.Center;
        case "droite" : return JustificationValues.Right;
        case "gauche" : return JustificationValues.Left;
        default: return null;
    }
}

Thx for you help !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:19:45+00:00Added an answer on June 10, 2026 at 12:19 pm

    Does it work if you were to apply the paragraphProperties to the parent cell rather than the paragraph?

    Table table = new Table();
    TableRow tableHeader = new TableRow();
    table.AppendChild<TableRow>(tableHeader);
    TableCell tableCell = new TableCell();
    tableHeader.AppendChild<TableCell>(tableCell);
    ParagraphProperties paragraphProperties = new ParagraphProperties();
    Paragraph paragraph = new Paragraph(new Run(new Text("test")));
    JustificationValues? justification = GetJustificationFromString("centre");
    
    // Use System.Nullable<T>.HasValue instead of the null check.
    if (justification.HasValue)
    {
        // Using System.Nullable<T>.Value to obtain the value and resolve a warning 
        // that occurs when using 'justification' by itself.
        paragraphProperties.AppendChild<Justification>(new Justification() { Val = justification.Value });
    }
    
    // append the paragraphProperties to the tableCell rather than the paragraph element
    tableCell.AppendChild<ParagraphProperties>(paragraphProperties);
    tableCell.AppendChild<Paragraph>(paragraph);
    Console.WriteLine(table.OuterXml);
    

    table.OuterXml before:

    <w:tbl xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
      <w:tr>
        <w:tc>
          <w:p>
            <w:r>
              <w:t>test</w:t>
            </w:r>
            <w:pPr>
              <w:jc w:val="center" />
            </w:pPr>
          </w:p>
        </w:tc>
      </w:tr>
    </w:tbl>   
    

    table.OuterXml after:

    <w:tbl xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
        <w:tr>
        <w:tc>
            <w:pPr>
            <w:jc w:val="center" />
            </w:pPr>
            <w:p>
            <w:r>
                <w:t>test</w:t>
            </w:r>
            </w:p>
        </w:tc>
        </w:tr>
    </w:tbl>
    

    I’m fairly new to OpenXml. Is the result saved to a word document and viewed in word?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to apply right alignment on the last cell of every table row,
I want to apply text-decoration:line-through to a table row which will be looped as
I want to place a text and button in a table cell. The button
I want to apply shadow effect to text of type NSString. Though I understand
I want to apply some CSS to text that I can't get marked up
I want to apply texture to the transparent png(bitmap), but I don't want to
I just want to apply text shadow to <span> elements in Internet Explorer 6-9.
I want to apply ckeditor on specific textarea in django admin form not on
I want to apply a format (align text, format for the currency 0000.00) to
I want to apply animation on UILabel text. I write the code to increase

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.