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 May 24, 2021 7:56 am

Hi!

I have a question regarding tables and word documents.

Sometimes, we generate word documents from HTML. This html contains tables that don't fit the horizontal margins of the document.

My question is: Is there any thing that we can do to reduce this tables in order to make them fit the document correctly?

Thank you in advance!

beatriz.gomezcarrero
 
Posts: 5
Joined: Mon May 24, 2021 7:51 am

Mon May 24, 2021 8:42 am

Hello,

Thanks for your inquiry.
To help us investigate your issue more quickly and accurately, please provide your input file and the desired output. You could send them to us (support@e-iceblue.com) via email. Thanks in advance.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Mon May 24, 2021 8:52 pm

Hi Brian,

I sent the files through e-mail. But, I'm attaching an example of them in this thread just in case.

I understand that in this example the table width is causing that result, but we are looking for an option that automatically reduces the table's margins and width in order to see all the content without further adjustment after transformation.

The Spire.Doc version used is 9.4.1.4040.

Regards,

--
N. Lionel

N.Lionel
 
Posts: 4
Joined: Fri Apr 16, 2021 3:36 am

Tue May 25, 2021 6:22 am

Hello,

Thanks for your sharing.
Our Spire.Doc is based on Microsoft Word. I tried to open your html file in Microsoft Word and got a similar result to our product. I’m afraid that it is not possible to automatically reduce the table's margins and width without further adjustment after transformation.

In order to achieve your desired effect, we recommend that you use the following code.
Code: Select all
            Document document = new Document();
            document.LoadFromFile("test7.html", FileFormat.Html, XHTMLValidationType.None);
            Section section = document.Sections[0];

            foreach (Table table in section.Tables)
            {
                table.AutoFit( AutoFitBehaviorType.AutoFitToWindow);
            }
            document.SaveToFile("HtmlFileToWord.docx", FileFormat.Docx);



Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Tue Jun 01, 2021 10:15 am

Hello,

Greetings from E-iceblue!
How is your issue now? Could you please give us some feedback at your convenience? Did the code we provided work for you?

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.Doc