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:
- read , write active selections in form of text, contiguous cells (matrices), or tables.
- tabular data (matrices or tables).
- bindings (created "add" methods of bindings object).
- custom xml parts (only word).
- settings or app state persisted per app on document.
also little below says
the document object supports 4 ways developers access document contents:
- selection-based access
- binding-based access
- custom xml part-based access (word only)
- entire document-based access (powerpoint , word only)
in yet documentation, ms explains selection critical part of apps workflow.
i believe routes be:
- ask user select whole document , click on button run replacement code using
setselecteddataasync
method. - get complete document using
document.getfileasync
method , replace <<..>> in code , create new document. see example getting whole content here.
Comments
Post a Comment