Hi
All
I got a MS Word Document and I´d like to do Search and Replace on it with Javascript.
Is there any function javascript that do this, to send me?
[EDIT]
Thanks
17 11683 gits 5,390
Expert Mod 4TB
hi ...
welcome to TSDN ...
please DON'T post your email-address in the forums ... i've removed it for your own security ... i think you won't get spammed :) and at least it's against the posting rules ...
to your problem: why do you want to do that? word has its own search and replace method. btw. i think there is no possibility to do that with javascript since javascript is strictly bound to the browser and a webpage (html, xml) ...
kind regards
I think there is one way, but I'm not sure:
Look at this example:
In C:\\Java\\MyDocument.doc, I add " Add My Texto " in the beginning of file.
So i thought there is one way to replace in the variable docText and save again the file.
This javascript open word document get the docText and add that text : (" Add My Texto " in beginning of file. - <script>
-
var w=new ActiveXObject('Word.Application');
-
var obj;
-
if (w != null)
-
{
-
w.Visible = true;
-
obj=w.Documents.Open("C:\\Java\\MyDocument.doc");
-
var docText = new String(obj.Content);
-
w.Selection.TypeText(" Add My Texto ");
-
w.Documents.Save();
-
-
}
-
-
</script>
gits 5,390
Expert Mod 4TB
in this code you use an activeX-object ... it's IE specific stuff ... and therefore i cannot test it to help you :) ... but could you post what obj.Content is? is it plain text of the docs content?
Thanks for reply me.
It´s plain ms word document content, but I need to know how to replace text into my Ms Word document content, example replace 'A' for 'B'.
How can I do this?
Thsnks
gits 5,390
Expert Mod 4TB
you may use a regExp for that ... have a look at the following example: - var text = 'AB BBB BCA';
-
-
text = text.replace(/A/g, 'B');
-
-
alert(text);
-
kind regards
I have to do this into my MS Word Documento not variable javasript.
Thanks
gits 5,390
Expert Mod 4TB
the variable is an example ... put obj.Content here ...
Here is my content: - <script>
-
var w=new ActiveXObject('Word.Application');
-
var obj;
-
if (w != null)
-
{
-
w.Visible = true;
-
obj=w.Documents.Open("C:\\Java\\MyDocument.doc");
-
-
//===========here is my content coming from MyDocument.doc===
-
var docText = obj.Content;
-
-
-
-
//====here i save the content===================
-
w.Documents.Save();
-
-
}
-
-
</script>
gits 5,390
Expert Mod 4TB
:D so now try this: -
var w = new ActiveXObject('Word.Application');
-
var obj;
-
-
if (w != null) {
-
w.Visible = true;
-
obj = w.Documents.Open("C:\\Java\\MyDocument.doc");
-
-
//===========here is my content coming from MyDocument.doc===
-
var docText = obj.Content;
-
-
docText = docText.replace(/A/g, 'B');
-
-
//====here i save the content===================
-
w.Documents.Save();
-
}
-
kind regards
@gits
Hello All,
I tried the above code but its giving the following error:
"Object doesnot support this property or method" on the line where there is a replace code written.
Could anybody please look into it..
With Best Regards,
Rohit
gits 5,390
Expert Mod 4TB
Hello all,
I have attached the following code. Here i have a word doc by the name Qualification_Report.doc. I want to replace all 'p' occurances in that by B. But it gives the following error "Object doesnot support this property or method". Could anyone please look into it. - var oApplication=new ActiveXObject("Word.Application");
-
oApplication.Documents.Open("c:\\Qualification_Report.doc");
-
var oDocument= oApplication.ActiveDocument;
-
-
var docText = oDocument.Content;
-
-
docText = docText.replace(/p/g,'B');
Thanks in advance
Rohit
gits 5,390
Expert Mod 4TB
after assigning the docText variable what does the alert i showed you above tell you? is it 'string'?
It says that docText is an "object"
I converted it into string.. then the changes are applied on the javascript but are not reflected in the word document.
That is all the 'p' is getting converted and can be checked using alert statement. But 'p' remain as it is in the word document.(even after saving the file using the command .Documents.save())
gits 5,390
Expert Mod 4TB
may be that you need to save it to the word-document first through a method of the ActiveX control first? ... i would suggest to look/ask in the msdn forum ... unless anybody here could give you a better suggestion ...
kind regards
I think Content is a range, so you would need to use the .text property. If you set that to the replaced string, perhaps it will work.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Les Juby |
last post by:
A year or two back I needed a search script to scan thru HTML files
on a client site. Usual sorta thing. A quick search turned up a
neat script that provided great search results. It was fast,...
|
by: Jane Doe |
last post by:
Hi,
I need to search and replace patterns in web pages, but I
can't find a way even after reading the ad hoc chapter in New Rider's
"Inside JavaScript".
Here's what I want to do:
function...
|
by: vic |
last post by:
My manager wants me to develop a search program, that would work like they
have it at edorado.com.
She made up her requirements after having compared how search works at
different websites, like...
|
by: lucky |
last post by:
hi there!!
i'm looking for a code snipett wich help me to search some words into a
particular string and replace with a perticular word. i got a huge data
string in which searching traditional...
|
by: Anton |
last post by:
Hi All,
Is it possible to read through a word document, find a number of
strings (using wildcards) and prompt the user to enter values for them.
I have a document management database that builds...
|
by: Carstonio |
last post by:
I use ASP to display links to Word documents on an intranet. Is there a way
in ASP to do text searches on the documents' contents? I want the results to
have the link to the Word document plus two...
|
by: Ola K |
last post by:
Hi guys,
I wrote a script that works *almost* perfectly, and this lack of
perfection simply puzzles me.
I simply cannot point the whys, so any help on it will be appreciated.
I paste it all here,...
|
by: |
last post by:
I have a question about spawning and displaying subordinate list controls
within a list control. I'm also interested in feedback about the design of
my search application. Lots of code is at the...
|
by: silmana |
last post by:
Hi i have this script that i want to use as php or html but i cant find the problem, could anyone solve the problem, i dont know why i cannot use it in php or html file
// OBS! Några saker måste...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |