office365 - Office task pane app: how to do search and replace in a Word document? -


we developing office task pane app search text , replace them values.

for example, have word document like:

total invoice of year <<thisyear>> <<totalinvoice>> 

in task pane app, when user clicks button, app should search text surrounding <<>>, , replace them real values data internet. result should like:

total invoice of year 2015 $2,000,078.34 

i'm new office task pane app, how should this?

============== updated =================

i have done nothing except running demo ms. demo shows how selected text word document. easy understand.

function getdatafromselection() {     office.context.document.getselecteddataasync(office.coerciontype.text,         function (result) {             if (result.status === office.asyncresultstatus.succeeded) {                 app.shownotification('the selected text is:', '"' + result.value + '"');             } else {                 app.shownotification('error:', result.error.message);             }         }     ); } 

however, didn't find find or replace api, this:

document api     document object         bindings property         customxmlparts property         mode property         settings property         url property         addhandlerasync method         getactiveviewasync method         getfileasync method         getfilepropertiesasync method         getselecteddataasync method         gotobyidasync method         removehandlerasync method         setselecteddataasync method         activeviewchanged event         selectionchanged event 

as per ms documentation, can following

applies to: content , task pane app types

to interact document data in excel, powerpoint, , word, api provides document object. can use document object members access data following ways:

  1. read , write active selections in form of text, contiguous cells (matrices), or tables.
  2. tabular data (matrices or tables).
  3. bindings (created "add" methods of bindings object).
  4. custom xml parts (only word).
  5. settings or app state persisted per app on document.

also little below says

the document object supports 4 ways developers access document contents:

  1. selection-based access
  2. binding-based access
  3. custom xml part-based access (word only)
  4. entire document-based access (powerpoint , word only)

in yet documentation, ms explains selection critical part of apps workflow. workflow

i believe routes be:

  1. ask user select whole document , click on button run replacement code using setselecteddataasync method.
  2. get complete document using document.getfileasync method , replace <<..>> in code , create new document. see example getting whole content here.

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -