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.

Tue Nov 23, 2021 3:21 pm

Hi there,
As the title, I can not append html with a table have a lot of columns (sample table in attachment file)
Please check any issue in here.
Thanks,

minhtd_buca
 
Posts: 3
Joined: Fri Jul 02, 2021 7:51 am

Wed Nov 24, 2021 5:59 am

Hello,

Thank you for your inquiry.
Is the sample Word file you provided the result of using our Spire.Doc to convert HTML to Word? Do you want the table to be displayed completely on the Word page(as shown in the screenshot)? If yes, please refer to the sample code below. If I misunderstand your requirement, please provide your html file, the expected result document or a screenshot of the result. You could attach them here or send them to us via email (support@e-iceblue.com). Thanks in advance.
Code: Select all
 Document document = new Document("sample.docx");
 Table table = document.Sections[0].Tables[0] as Table;   
 table.AutoFit(AutoFitBehaviorType.AutoFitToWindow);
 document.SaveToFile("output.docx", FileFormat.Docx);

Sincerely,
Annika
E-iceblue support team
User avatar

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

Thu Nov 25, 2021 4:47 am

Hi,
I send html content from attactment file, in my case, i use AppendHtml of Spire.Doc.
The expected result is the same with your screenshot in formating.
Please help, thanks!

minhtd_buca
 
Posts: 3
Joined: Fri Jul 02, 2021 7:51 am

Thu Nov 25, 2021 8:16 am

Hello,

Thank you for your sharing.
I tested your HTML file with the following code, and the table in the result file is completely displayed on the page. I have attached my result file (output.docx) and the screenshot of the opened effect (Microsoft Office2016). My test environment is windows7 x64, see the attachment DPI.png for DPI settings. Please try the following code and check output.docx on your side. If the issue still exists, please provide the following information for our reference. Thanks in advance.
1) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).
2) The DPI of your computer.
3) Word file viewing software (such as Microsoft Office2016).
Code: Select all
Document doc = new Document();         
Section section = doc.AddSection();
Paragraph paragraph = section.AddParagraph();
string htmls = File.ReadAllText("sample.html");
paragraph.AppendHTML(htmls);
Table table = doc.Sections[0].Tables[0] as Table;
PreferredWidth width = new PreferredWidth(WidthType.Percentage, 100);
table.PreferredWidth = width;
doc.SaveToFile("output.docx", FileFormat.Docx);

Sincerely,
Annika
E-iceblue support team
User avatar

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

Return to Spire.Doc