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.

Mon Oct 26, 2015 2:58 pm

Hi,

I create my final document by assembling sections.
The fact is that it is possible that my section starts with a text area which floats and so it's not where I would want to be.

On the attached picture, I drew quickly the rendering I get.
My second text area is too high. I'd want it to be after the red line aligned with the second paragraph, like at the beginning.

Is there a way to really separate them so that I can have the expected result?

Best regards.

s.fardilha
 
Posts: 35
Joined: Tue Aug 11, 2015 9:20 am

Tue Oct 27, 2015 3:57 am

Hi,

Thanks for your inquiry.
Please provide us your word document, which can help us to check the setting information of your text area and provide you solution quickly.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3044
Joined: Wed Jun 27, 2012 8:50 am

Tue Oct 27, 2015 8:49 am

I forgot to say that my section ends with a table in this case, but it is not all the time.
You can see in attachment that the text area goes too high.

Is there another solution than putting the table with WrapTextAround to false?

I'd like to have a clean separation between every section without having to think what's inside and without having to put a page break...

s.fardilha
 
Posts: 35
Joined: Tue Aug 11, 2015 9:20 am

Wed Oct 28, 2015 3:52 am

Hi,

Please try the below code.
Code: Select all
  Document document = new Document();
            document.LoadFromFile("..\\..\\test_spire.docx");
            foreach (Section section in document.Sections)
            {
                if (section.Tables.Count > 0)
                {
                    for (int i = 1; i < section.Tables[0].Rows.Count; i++)
                    {
                        section.AddParagraph();
                    }
                }
            }
            string result = "result.docx";
            document.SaveToFile(result,FileFormat.Docx2013);

If it is not what you want, please share a result document you expect.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3044
Joined: Wed Jun 27, 2012 8:50 am

Wed Oct 28, 2015 10:06 am

Hi,

It's a trick which only works if the table cells are displayed on one line.
If there's one (or several) rows in the table in which the content is on more than one line, there won't be enough added paragraph.

Is there a way to determine the total height of the table and then add programmatically the corresponding number of paragraph ?
Not a very clean solution, but if it's the only one...

s.fardilha
 
Posts: 35
Joined: Tue Aug 11, 2015 9:20 am

Thu Oct 29, 2015 3:34 am

Hi,

Thanks for your message.
For your issue, at present there are only two solutions.
Solution 1:
Set Table with WrapTextAround to false and alignment to right, you have mentioned it previous.
Solution2:
Set fixed height for each row so that get table height, and then add a placeholder(e.g., a blank picture, paragraphs) with same height as table at end of section .
Code: Select all
         
                   //Get Table height
                    Table table=section.Tables[0] as Table;
                    float height = 0;
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        height += table.Rows[i].Height;
                    }


Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3044
Joined: Wed Jun 27, 2012 8:50 am

Thu Oct 29, 2015 11:38 am

Hi,

The first solution is not good given though it implies it can modify the expected layout...

About the second one, there is a problem : I can't fix the height of a row given though I don't know in advance what will be the content...
Is there a way to know the row height with its inserted content?

Edit : I just thought that if the text before the table is long, it could wrap the table and then I would add too much paragraphs...
Is there a way to put an "invisible" element after the table with WrapTextAround at false?

s.fardilha
 
Posts: 35
Joined: Tue Aug 11, 2015 9:20 am

Fri Oct 30, 2015 7:01 am

Hi,

It is very complex to get the row height with its inserted content, we do not recommend to do that. If you cannot use solution1, soultion2 is the only one to be done at present.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3044
Joined: Wed Jun 27, 2012 8:50 am

Fri Oct 30, 2015 11:18 am

So there is no way to for example add an invisible table with WrapTextAround at false to create an artificial separation?

I'll see what is the better solution for what I'd want to do...

s.fardilha
 
Posts: 35
Joined: Tue Aug 11, 2015 9:20 am

Mon Nov 02, 2015 7:31 am

Hi,

We have tried the solution with an invisible table with WrapTextAround at false,it didn't work. It affected other elements's layout.
Sorry that at present we have no ideas for your issue but Solution 1 and Solution 2.
Solution 1:
Set Table with WrapTextAround to false and alignment to right when don't fix row height.
Solution2:
Set fixed height for each row so that get table height, and then add a placeholder(e.g., a blank picture, paragraphs) with same height as table at end of section .


Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3044
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc

cron