Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files from any .NET platform (C#, VB.NET, ASP.NET, .NET Core) and Java applications (J2SE and J2EE) with fast and high quality performance.

Sun Aug 22, 2021 8:27 am

I need to align 2 labels and its Dynamic text as shown in the attachment.

Please note that I have used tables for demonstration purposes only so that you can have a clear picture of the problem
Left label and Right label text are always fixed as shown below. however, rest of the table cell content varies according to data.
Left label and its content have to be left aligned and Right label and it’s content has to be right aligned.
However, if dynamic content can not fit in one line it has to break as shown in Scenario 3.
I need to know how to achieve below demonstrated behavior programmatically.
text align issue.png
You do not have the required permissions to view the files attached to this post.

infra
 
Posts: 12
Joined: Tue Apr 03, 2018 12:05 pm

Mon Aug 23, 2021 12:47 pm

Hello,

Thank you for your inquiry.
Our Spire.Doc can add a listStyle for paragraph to achieve the effect you want. But for line-wrapped text, when it is set to right-aligned, it is not easy to control the position of listStyle. Therefore, for this case, I suggest that you do not set the text to be right-aligned. Sample code is shown below. If there is any question, please feel free to write back.

Code: Select all
            Document doc = new Document();
            Section section = doc.AddSection();
            Table table = section.AddTable(true);
            table.ResetCells(1, 2);
            table.Rows[0].Cells[0].SetCellWidth(200, CellWidthType.Point);
            table.Rows[0].Cells[1].SetCellWidth(200, CellWidthType.Point);
            table.Rows[0].Cells[0].AddParagraph().AppendText("Left Label: This is slightly longer text in one line");
            table.Rows[0].Cells[1].AddParagraph().AppendText("Right Label: This is slightly longer text in one line");

            ListStyle bulletList = new ListStyle(doc,ListType.Bulleted);
            bulletList.Levels[0].BulletCharacter = "\x002d.";
            bulletList.Levels[0].CharacterFormat.FontName = "Arial";
            bulletList.Levels[0].PatternType = ListPatternType.Arabic;

            bulletList.Name = "Left Label";
           
            bulletList.Levels[0].NumberPosition = -60f;
            bulletList.Levels[0].FollowCharacter = FollowCharacterType.Space;
            bulletList.Levels[0].TextPosition = 60f;
            doc.ListStyles.Add(bulletList);

            table.Rows[0].Cells[0].Paragraphs[0].ListFormat.ApplyStyle(bulletList.Name);
            table.Rows[0].Cells[1].Paragraphs[0].ListFormat.ApplyStyle(bulletList.Name);

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 432
Joined: Wed Apr 07, 2021 2:50 am

Fri Sep 10, 2021 10:11 am

Hi,

Hope you're doing well!
How is your issue going? Did the code we provided work for you? Any feedback will be greatly appreciated.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 432
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc