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 Jul 06, 2021 2:09 am

Hello,
I have 2 questions.
1. i have a html document which generated dynamically. once loaded the document in to instance of Spire.Doc, how do i identify specific table ? can i use ID, css class to do that?
2. when i load html document in to spire.doc my table widths has been changed ( i want them to be full width) . how do i fix this. please refer to attached html
sample html.zip

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

Tue Jul 06, 2021 1:18 pm

Below are my answers to your questions.
1) There is no way to identify table in terms of ID and css class. But the title identification for table tag in html could be identified by our Spire.Doc. You could add the title for your html as follows.
Code: Select all
<table title="tableTitle"><tr><td><p>test</p></td></tr></table>

Then use the code below to obtain the corresponding table by our product. Unfortunately, I found the following code failed to obtain the table title when testing. I have logged this issue into our bug tracking system with the ticket SPIREDOC-6309 for fixing, once it is resolved, I will inform you immediately. Sorry for the inconvenience caused.
Code: Select all
//Load html file
Document document = new Document();
document.LoadFromFile(HtmlfilePath, FileFormat.Html, Spire.Doc.Documents.XHTMLValidationType.None);
foreach (Section section in document.Sections)
{
    foreach (Table table in section.Tables)
    {
        //Identify table by title
        if (table.Title.Equals("tableTitle"))
        {
            //...
        }
    }
}


2) The table width in generated Word document is determined by the width settings in your HTML. I tested your html but didn't find that the width changed. What you want is to generate the table widths which fit to the whole Word width, right? If so, you could change the table width setting in your HTML to 100%, or you can use our product to change the table width to 100%. Sample code is shown as follows. If there is any misunderstanding, please provide detailed information to clarify.
Code: Select all
foreach (Section section in document.Sections)
{
      foreach (Table table in section.Tables)
       {
             //Change the table width to 100%
             table.PreferredWidth = new PreferredWidth(WidthType.Percentage, 100);
       }
}

Sincerely,
Annika
E-iceblue support team
User avatar

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

Fri Aug 20, 2021 11:32 am

Hello,

Thank you for your patience.
Glad to inform you that we have just released Spire.Office (Hot Fix) Version: 6.8.2 which solves the problem of getting the table title invalid. Please download it from the following links.
Website link:
https://www.e-iceblue.com/Download/down ... t-now.html
Nuget link:
https://www.nuget.org/packages/Spire.Office/6.8.2
https://www.nuget.org/packages/Spire.Of ... Core/6.8.2


Sincerely,
Annika
E-iceblue support team
User avatar

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

Wed Sep 08, 2021 10:17 am

Hi,

Hope you are doing well!
Have you tried the new version of Spire.Office? Is the issue resolved now? Any feedback will be greatly appreciated.

Sincerely,
Annika
E-iceblue support team
User avatar

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

Return to Spire.Doc