Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Nov 20, 2019 9:04 pm

testfile.zip


Hi,
I'm trying to insert few paragraphs in table cells and my text is not looking correct. Could you please help me? I'm using latest Spire nuget with C#.net

If I dont load the template, my paragraphs are looking fine, however with my template, they wont work.

Code: Select all
  var doc = new SP.Document();
           var fileName1 = "1.0.0.docx";
           doc.LoadFromFile("My path here");
         
            doc.AddSection();

            var table = doc.LastSection.AddTable(false);

            table.PreferredWidth = new SP.PreferredWidth(SP.WidthType.Percentage, 100);

            CharacterFormat format = new CharacterFormat(doc);
            if (mylang == "Arabic")
            {
                format.Bidi = true;
            }

            var stringValues = new List<string> {"Testing the titles as is giving few problems so keeping long test values for demo and test purposes please make sure the content remains same and dont change anything",
            "Testing the titles as is giving few problems so keeping long test values for demo and test purposes please make sure the content remains same and dont change anything",
            "Executive Board of our Organizations Development Programme/Other fund related stuff/Our Office for Project Services "};

            foreach (var string1 in stringValues)
            {
                var row = table.AddRow(false, 4);

                row.RowFormat.BackColor = Color.White;
                var paragraph = row.Cells[0].AddParagraph();
               
                TextRange range = paragraph.AppendText(string1);
                range.CharacterFormat.FontName = "Times New Roman";
                range.CharacterFormat.FontSize = 16;
                range.CharacterFormat.Bold = true;
                paragraph.Format.HorizontalAlignment = HorizontalAlignment.Left;
             


                TextRange range1 = paragraph.AppendText(" - " + "my test value");
                range1.CharacterFormat.FontName = "Times New Roman";
                range1.CharacterFormat.FontSize = 15;
                range1.CharacterFormat.TextColor = Color.FromArgb(89, 89, 89);
                range1.CharacterFormat.Bold = true;
           
                table.ApplyHorizontalMerge(row.GetRowIndex(), 0, 3);
            }
            var fileName = "testfile";

            doc.SaveToFile(fileName + ".docx");
 
            SP.Document document = new SP.Document();
            document.LoadFromFile(fileName + ".docx");
         
            document.SaveToFile(fileName + ".pdf");



Attaching my template and the word and pdf files. Appreciate your help.

Thanks,
Santhoshi.

santuvssantu
 
Posts: 98
Joined: Fri Feb 12, 2016 5:21 pm

Thu Nov 21, 2019 10:43 am

Hi,

Thanks for your inquiry.
After investigation, I found that the paper size and the paper margins are different between the two result files. The table in the two files are different, so the text wrap for the paragraph in the table is different. Note while creating a new file, Spire will generate a file with A4 size by default. I found changing the table width could achieve the same effect like the new created file you want. Below is the code for you.

Code: Select all
            table.PreferredWidth = new PreferredWidth(WidthType.Percentage, 106);

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Fri Nov 22, 2019 12:58 pm

Thanks alot Amber, that worked perfectly.

Sorry, I didnt realize about the paper size.


Regards,
Santhoshi.

santuvssantu
 
Posts: 98
Joined: Fri Feb 12, 2016 5:21 pm

Mon Nov 25, 2019 1:13 am

Hi,

Thanks for your feedback. Sorry to reply late for weekend.
Any question, welcome to contact us. Have a nice day.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Return to Spire.Doc