Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display html content in word document using VBscript

Status
Not open for further replies.

iis6newbie

Technical User
Nov 22, 2003
54
US
Hello all,
can someone help me how to display html content on word document using VBscript?


<html>
<body>
testing string
</body>
</html>


I just want to see "testing string" in the word document. don't want to see any extra html tag in the word document.

Thanks for any help


Here is my C# code:

string strjscript = "<SCRIPT LANGUAGE=vbscript>\n";
strjscript += "Dim objWordobject\n";
strjscript += "Dim objDocobject\n";
strjscript += "Dim strReturnValue\n";
strjscript += "Set objWordobject = CreateObject(\"word.Application\")\n";
strjscript += "objWordobject.Visible = True\n";
strjscript += "Set objDocobject = objWordobject.Documents.Add( , , 1, True)\n";
string report = completeReport.ToString().Replace("\"", "&qt;");
strjscript += "objDocobject.Content="+"\"" + report+"\""+"\n";
strjscript += "</SCRIPT>";
ltr1.Text = strjscript;


///report is string that contained html code
 
Hi!

Word automation can be done through scripting, but is it really the best way to implement your solution? If client web browsers will be running the script, then you'll have to deal with having MSWord installed and they will have to have lenient (and possibly dangerous) security settings to allow the script to execute in the associated internet security zone.

But if this is not a concern, it looks like you're on the right track to automate Word through your script. Here's an HMTL+Script example that prompts for text then launches Word and puts that text in a new Word document.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Word Automation Example</title>
</head>
<body>
<hr>
<center><h2>Word Automation Example</h2></center>
<b>Instructions:</b> Type some text in the following box, then press <strong>Generate</strong> 
</body>
<input type=text value="testing string" id="testId">
<input type=button value="Generate" onclick="DoWordAuto();">

<script language ="javascript">
function DoWordAuto()
{
   var WordApp = new ActiveXObject("Word.Application");
   WordApp.Visible = true;
   var WordDoc = WordApp.Documents.Add();
   WordDoc.Sections.First.Range.Text = testId.value;
   return true;

}
</script>
</html>

Of course, the page will error if -1- Word is not properly installed, -2- Word DCOM settings are not permissive to run in the context, or -3- Local security settings are not permissive enough in the target browser.
 
AmazingGrace,

Thanks for your help.

if the input string contain html tags like:

<html><body>testing string</body></html>

can we just display "testing string"?
What I have is a string that contained all the HTML tags.

when I sent my string report to word document, it displayed everything included HTML tags. But I want to see the content only, I don't want to see all the HTML tags + content


 
If the source text was formatted in XML and not HTML then it would be very easy to extract the text between the tags. But that is not the case, so I think you'll have to write a function that strips out the tags.

Question: How is the HTML generated? Is it from an application that you control? I'm asking because maybe another alternative can be found rather than parsing the HTML.
 
This HTML tags is what I have put in manually.

on server side, I throw out the whole report with HTML tags to the word document, it works ok. But it does not work on the client side.

like what you said, I probably, have to take out all the HTML tags before send to client browser.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top