We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Convert HTML list to word bulleted list

Hi,

I have text field in sql database:

  1. Aaaaaaaaa
    1. Fghj
    2. Mjfj
    3. fdh
  2. Dddddddd
  3. Ffffffffffff

This text I can see on html page like:

  1. Aaaaaaaaa
    1. Fghj
    2. Mjfj
    3. fdh
  2. Dddddddd
  3. Ffffffffffff

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.

<span lang=“EN-GB” style=“font-size:10.0pt;font-family:“Courier New”;color:#2B91AF;mso-font-kerning:
0pt;mso-no-proof:yes”>Document<span lang=“EN-GB” style=“font-size:10.0pt;
font-family:“Courier New”;mso-font-kerning:0pt;mso-no-proof:yes”> doc = new Document();<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);

builder.StartBookmark("MyBookmark");

builder.InsertHtml(@"

  1. Aaaaaaaaa
    1. Fghj
    2. Mjfj
    3. fdh
  2. Dddddddd
  3. Ffffffffffff
");

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,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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 = '

  1. Aaaaaaaaa
    1. Fghj
    2. Mjfj
    3. fdh
  2. Dddddddd
  3. Ffffffffffff
'

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

1. Fghj

2. Mjfj

3. fdh

2. Dddddddd

3. 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.


<span lang=“EN-GB” style=“font-size:10.0pt;font-family:“Courier New”;color:#2B91AF;mso-font-kerning:
0pt;mso-no-proof:yes”>Document<span lang=“EN-GB” style=“font-size:10.0pt;
font-family:“Courier New”;mso-font-kerning:0pt;mso-no-proof:yes”> doc = new Document(MyDir

  • “in.doc”);<o:p></o:p>

// 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();

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />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:
http://www.aspose.com/docs/display/wordsnet/Extract+Content+Between+Paragraphs

Please read following documentation link for the extraction of contents from document:
http://www.aspose.com/docs/display/wordsnet/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”);<o:p></o:p>

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

'

  1. Aaaaaaaaa
    1. Fghj
    2. Mjfj
    3. fdh
  2. Dddddddd
  3. Ffffffffffff
'

and assign to

System.Web.UI.HtmlControls.HtmlTextArea ss =

'

  1. Aaaaaaaaa
    1. Fghj
    2. Mjfj
    3. fdh
  2. Dddddddd
  3. Ffffffffffff
'

Is it possible?

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />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:


<span lang=“EN-GB” style=“font-size:10.0pt;font-family:“Courier New”;color:green;mso-font-kerning:
0pt;mso-no-proof:yes”>// Load in the document<o:p></o:p>

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'
  1. Aaaaaaaaa
    1. Fghj
    2. Mjfj
    3. fdh
  2. Dddddddd
  3. Ffffffffffff
'

Unfortunately, there is no direct way to extract specific section of document as html. However, you can extract contents from document as described here:
http://www.aspose.com/docs/display/wordsnet/Extract+Content+Overview+and+Code
http://www.aspose.com/docs/display/wordsnet/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.