Home > Net >  Inserted the rich text in the HTML in the word
Inserted the rich text in the HTML in the word

Time:10-08

The HTML is inserted into the word in the rich text,

Masters, specific implementation way or demo, not grateful,

CodePudding user response:

 public void ToWord (string HTML) 
{

String htmlSaveText="& lt; html> <body> ";
HtmlSaveText +=HTML;
HtmlSaveText +="& lt;/body> ";
//build HTML file
String path=System. Web. HttpContext. Current. Server MapPath ("/UploadFiles/Export/") + DateTime. Now. The ToString (" yyyy - MM - dd - HH - MM - ss ") + "HTML".
Using (FileStream fs=File. The Create (path))
{
Byte [] info=new UTF8Encoding (true). And GetBytes (htmlSaveText);
Fs. Write (info, 0, info. Length);
}
//File. AppendAllText (path, htmlSaveText, Encoding. The Default);
The object Nothing=Missing. The Value;
WDoc. Paragraphs. Last. Range. InsertFile (path, ref Nothing, ref Nothing,
Ref ref Nothing, Nothing);
}

Now this way, can the word paragraph, then add HTML content, how to add in the specified place?

CodePudding user response:

Document doc=new Document (for Server MapPath tempFile as expected ());
DocumentBuilder builder=new DocumentBuilder (doc);

Foreach (var key in dic. Keys)
{
Var repStr=the string. Format (" {0} ", key);

If (key=="$$" contract content)
{
Doc. Range. The Replace (repStr, "", false, false);
Bookmark a Bookmark=doc. Range. Bookmarks [0];
Builder. MoveToBookmark (bookmark. Name);
Builder. InsertHtml (dic [key]);

}
Else if (key=="$$" attachment content)
{
Doc. Range. The Replace (repStr, "", false, false);
Bookmark a Bookmark=doc. Range. Bookmarks [0];
Builder. MoveToBookmark (bookmark. Name);
Builder. InsertHtml (dic [key]);
}
The else
{
Doc. Range. The Replace (repStr, dic [key], false, false);
}
} now meet a problem, two positioning, doc. Range. The Bookmarks [1] is definitely wrong, how to correctly locate respectively

CodePudding user response:

Which tall person to give directions
  •  Tags:  
  • C#
  • Related