The getAllContentAsync method is used to return the entire document in the form of text or Base64 encoded form. This function contains some parameters which are described below:
Let's have a look at the following steps to use this function:
<!DOCTYPE html><html> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=Edge"/> <title>Document</title> <link rel="stylesheet" type="text/css" href="../Content/Office.css" /> <link rel="stylesheet" type="text/css" href="../Content/App.css" /> <script src="../Scripts/jquery-1.6.2.js"></script> <script src="../Scripts/Office/MicrosoftAjax.js"></script> <script src="../Scripts/Office/Office.js"></script> <!-- Add your JavaScript to the following file --> <script src="../Scripts/Document.js"></script> </head> <body> <button onclick="getWholeDocument()">get document</button> <span>outputs:</span><div id="message"></div> </body></html>
// Add any initialization logic to this function.
Office.initialize = function (reason) { // Checks for the DOM to load. $(document).ready(function () { $("#getDatabtn").click(function () { getData("selectedData"); }); // Checks if setSelectedDataAsync is supported and adds appropriate click handler if (Office.context.document.setSelectedDataAsync) { $("#setDatabtn").click(function () { setData("Sample data"); }); } else { $("#setDatabtn").remove(); } });}// Writes data to current selection.function setData(dataToInsert) { Office.context.document.setSelectedDataAsync(dataToInsert);}// Reads data from current selection.function getData(elementIdToUpdate) { Office.context.document.getSelectedDataAsync(Office.CoercionType.Text, function (result) { if (result.status == "succeeded") { document.getElementById(elementIdToUpdate).value = result.value; } });}function getWholeDocument() { Office.context.document.getAllContentAsync( "text", function (result) { if (result.status == "failed") { write(result.error.name + ": " + result.error.message); } else { write(result.value); } });}// Function that writes to a div with id='message' on the page.function write(message) { document.getElementById('message').innerText += message;}
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: