Convert HTML list to word bulleted list

Hi,
I have text field in sql database:

<ol><li>Aaaaaaaaa<ol><li>Fghj</li><li>Mjfj</li><li>fdh</li></ol></li><li>Dddddddd</li><li>Ffffffffffff</li></ol>

This text I can see on html page like:

<OL>
<LI>Aaaaaaaaa 
<OL>
<LI>Fghj 
<LI>Mjfj 
<LI>fdh</LI></OL>
<LI>Dddddddd 
<LI>Ffffffffffff</LI></OL>

In aspose.word I need to replace bookmark with this field and show in proper word format.
Is it possible in aspose?
Thanks,
pa

Hi Godson,
Thanks for your inquiry. You can create bookmark with the contents of shared html by using Aspose.Words as shown below. I have attached the output Docx file with this post.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.StartBookmark("MyBookmark");
builder.InsertHtml(@"<ol><li>Aaaaaaaaa<ol><li>Fghj</li><li>Mjfj</li><li>fdh</li></ol></li><li>Dddddddd</li><li>Ffffffffffff</li></ol>");
builder.EndBookmark("MyBookmark");
doc.Save(MyDir + "AsposeOut.docx");

pamanager:
In aspose.word I need to replace bookmark with this field and show in proper word format.

It would be great if you please share some more detail about your inquiry. Do you want to replace html content with some bookmark contents? Please share a sample input/output Word documents here. I will share the code according to your requirement.

Hi Tahir,
Thank you for response.
What about to get proper word format for the table

DataTable AvaDocTable = GetTable("AvaDoc", 2);

table has one record with two fields:

  1. Item_No = 1
  2. Description_1 = '<ol><li>Aaaaaaaaa<ol><li>Fghj</li><li>Mjfj</li><li>fdh</li></ol></li><li>Dddddddd</li><li>Ffffffffffff</li></ol>'

Now in word document docInforbid I have bookmark table:

«TableStart:AvaDocGrid1»«Item_No» «Description_1»«TableEnd:AvaDocGrid1»

And code to update table bookmark: docInforbid.MailMerge.ExecuteWithRegions(AvaDocTable);
How can I show field ‘Description_1’ in word format like

  1. Aaaaaaaaa
  2. Fghj
  3. Mjfj
  4. fdh
  5. Dddddddd
  6. Ffffffffffff

Thank you,
pa

Hi Godson,

Thanks for sharing the details. According to your shared detail, you are using Mail Merge with Regions. In this case, please use the following code snippet for your kind reference. The following code example shows how to mail merge HTML data into a document. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "in.doc");

// Add a handler for the MergeField event.
doc.MailMerge.FieldMergingCallback = new HandleMergeFieldInsertHtml();

// Get DataTable
DataTable AvaDocTable = GetTable("AvaDoc", 2);
// Execute mail merge.
doc.MailMerge.ExecuteWithRegions(AvaDocTable);
// Save resulting document with a new name.
doc.Save(MyDir + "MailMerge.InsertHtml Out.doc");
private class HandleMergeFieldInsertHtml : IFieldMergingCallback
{
    /// 
    /// This is called when merge field is actually merged with data in the document.
    /// 
    void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
    {
        if (e.DocumentFieldName.Equals("Description_1"))
        {
            // Insert the text for this merge field as HTML data, using DocumentBuilder.
            DocumentBuilder builder = new DocumentBuilder(e.Document);
            builder.MoveToMergeField(e.DocumentFieldName);
            builder.InsertHtml((string)e.FieldValue);
            // The HTML text itself should not be inserted.
            // We have already inserted it as an HTML.
            e.Text = "";
        }
    }
    void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
    {
        // Do nothing.
    }
}

Thank you Tahir.
It is works.

Hi Tahir,
Is it possible in Aspose to convert text from Word document to html.
I have code:

System.Web.UI.HtmlControls.HtmlTextArea ss = (System.Web.UI.HtmlControls.HtmlTextArea)form1.FindControl("source");
Document doc = new Document(@"c:\in02073.doc");
ss.Value = doc.GetText();

In this case ss.Value not formated as in the word document.
What can I do?
Thanks,
pa

Hi Godson,

Thanks for your inquiry. Yes, you can convert text from MS Word document to HTML. You may extract contents from MS Word document and save those contents to HTML by using the approach shared here:
https://docs.aspose.com/words/net/how-to-extract-selected-content-between-nodes-in-a-document/

Please read following documentation link for the extraction of contents from document:
https://docs.aspose.com/words/net/how-to-extract-selected-content-between-nodes-in-a-document/

You can convert complete MS Word document to HTML by using following code snippet.

Document doc = new Document(MyDir + "in.docx");
doc.Save(MyDir + "AsposeOut.html",SaveFormat.Html);

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

Hi Tahir,

My question was not about how to save document in html format.

I need to convert uploaded document to html format (with tags) and assign to the control System.Web.UI.HtmlControls.HtmlTextArea

I need to get value like
'<ol><li>Aaaaaaaaa<ol><li>Fghj</li><li>Mjfj</li><li>fdh</li></ol></li><li>Dddddddd</li><li>Ffffffffffff</li></ol>'

and assign to

System.Web.UI.HtmlControls.HtmlTextArea ss = 
'<ol><li>Aaaaaaaaa<ol><li>Fghj</li><li>Mjfj</li><li>fdh</li></ol></li><li>Dddddddd</li><li>Ffffffffffff</li></ol>'

Is it possible?
Thanks,
pa

Hi Godson,

Thanks for the detail.

pamanager:
I need to convert uploaded document to html format (with tags) and assign to the control System.Web.UI.HtmlControls.HtmlTextArea

You can convert uploaded document to html format (with tags) and assign to the control System.Web.UI.HtmlControls.HtmlTextArea as shown below:

// Load in the document
Document doc = new Document(MyDir + "in.docx");
// Save document to stream as html 
MemoryStream htmlStream = new MemoryStream();
SaveOptions options = SaveOptions.CreateSaveOptions(SaveFormat.Html);
doc.Save(htmlStream, options);
htmlStream.Position = 0;
StreamReader reader = new StreamReader(htmlStream);
string html = reader.ReadToEnd();
reader.Close();
HtmlTextArea tArea = new HtmlTextArea();
tArea.Value = html;
tArea.Rows = 10;
tArea.Cols = 100;
this.form1.Controls.Add(tArea);

*pamanager:

I need to get value like’*

Unfortunately, there is no direct way to extract specific section of document as html. However, you can extract contents from document as described here:
https://docs.aspose.com/words/net/how-to-extract-selected-content-between-nodes-in-a-document/
https://docs.aspose.com/words/net/how-to-extract-selected-content-between-nodes-in-a-document/
Following example shows how to extract the content between specific paragraphs using the ExtractContent method shared at above documentation links.

// Load in the document
Document doc = new Document(MyDir + "Test18.docx");
// Gather the nodes. The GetChild method uses 0-based index
Paragraph startPara = (Paragraph)doc.FirstSection.GetChild(NodeType.Paragraph, 2, true);
Paragraph endPara = (Paragraph)doc.FirstSection.GetChild(NodeType.Paragraph, 6, true);
// Extract the content between these nodes in the document. Include these markers in the extraction.
ArrayList extractedNodes = ExtractContent(startPara, endPara, true);
// Insert the content into a new separate document and save it to disk.
Document dstDoc = GenerateDocument(doc, extractedNodes);
// Save document to stream as html 
MemoryStream htmlStream = new MemoryStream();
SaveOptions options = SaveOptions.CreateSaveOptions(SaveFormat.Html);
dstDoc.Save(htmlStream, options);
htmlStream.Position = 0;
StreamReader reader = new StreamReader(htmlStream);
string html = reader.ReadToEnd();
reader.Close();
HtmlTextArea tArea = new HtmlTextArea();
tArea.Value = html;
tArea.Rows = 10;
tArea.Cols = 100;
this.form1.Controls.Add(tArea);

Thank you very much.
pa

Hi Godson,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.