How to extract and save Section to HTML without losing List number using .NET

Hi,
We are using Aspose.Words to process our word documents. We are reading a section (part of the document) from a .docx file and saving it as HTML. The code works fine however we are running into a scenario where the section content continues the numbering. For example: 3.1, 3.2, 3.2,… etc. After saving that section to HTML the numbering is reset. i.e. it changes to 1.1, 1.2, 1.3,… etc.

Here is an example of the original document and what it shows after importing to HTML.
Original Document.png (1.6 KB)
After importing to HTML.png (1.2 KB)

Our requirement is to save the section, as it is, to HTML without changing the numbering. Is this possible?
If yes, then could you please share with me any sample code, link, or demo that shows this?
Please let me know if there is any other way to achieve this.

Thank you.

@sunil.ferro

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output file that shows the undesired behavior.
  • Please attach the expected output file that shows the desired behavior.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Please extract the AsposeWordDemo.zip (4.7 MB)

Go to AsposeWordDemo\bin\Debug.
Double click on AsposeWordDemo.exe.
It will create a file in Debug\Doc\Output. This is the output html file where you will notice that under ‘Section 3’ the sub points are showing up as 1, 2, 3 instead of 3.1, 3.2, 3.3.
The input file is in Debug\Doc\Input.

Thank you.

@sunil.ferro

We have tested the scenario using the latest version of Aspose.Words for .NET 20.6 and have not found the shared issue. So, please use Aspose.Words for .NET 20.6. We have attached the output HTML with this post for your kind reference. output 20.6.zip (1014 Bytes)

Hi,
Thanks for your reply. We checked at our end by downloading and using Aspose.Words 20.6.0.0 in our application. Basically our requirement is to read each section i.e. marked with style “Heading 1” in the word document. We want each section as a separate html without losing its numbering in the source file.

Could you please refer to this demo - AsposeWordDemo_v20.6.zip (5.9 MB)

Let me know if we are missing anything.
Thanks.

@sunil.ferro

Please note that Aspose.Words mimics the behavior of MS Word. If you perform the same scenario using MS Word, you will get the same output.

In your code, you are removing the two lists from the document. This will restart the list number from 1.

Is there any way to get the HTML content, as we see in Word, without resetting the numbering?

@sunil.ferro

In your case, we suggest you following solution

  1. Please get the list label using ListLabel.LabelValue property.
  2. Insert section break as you are doing in your code.
  3. Set the starting number for each list that you want to get using ListLevel.StartAt property.

Hope this helps you…

Hi,
Property ListLabel.StartAt is working, however property ListLabel.LabelValue returns 0 instead of 3. Please see files - Code, Input and Ouput.
Code.png (4.5 KB)

Input.png (9.2 KB)

Output.png (2.4 KB)

Could you please let me know if I am missing anything?

Please refer to this demo AsposeWordDemo_20200731.zip (5.7 MB)

Would it be possible to provide a sample working code that will help in demonstrating this?

Thanks for the help.

@sunil.ferro

We have modified the code and attached it with this post for your kind reference. Hope this helps you.
Program.zip (1.8 KB)

If you still face problem, please share complete detail of your use case. We will then answer your query accordingly.