Skip to main content

Connect Document

If a document has already been inserted into the page through an iframe element (not inserted through the ZOfficeSDK.mount method), and you want to use SDK API to operate the document, you can use the connect method to establish a connection with the document.

Syntax

ZOfficeSDK.connect(selector, bAsync)

Return Value

Application: Document type application object

  • Excel: Excel.Workbook
  • Word: Word.Document

Parameters

PropertyData TypeRequiredDescription
selectorstringYesSelector of the DOM node where the document is mounted (selector of the iframe's parent node)
bAsyncbooleanNotrue means return Application before the document is loaded, but you need to call the Application.ready() method to wait for the document to load before using advanced APIs (recommended to pass true, return available Application earlier before document content is loaded, avoiding long waiting time)

Example

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>zOffice SDK</title>
</head>
<body>
<div id="doc1" class="doc-container">
<iframe src="http://172.16.22.98/docs/app/thirdparty-rest/1347466381985058817/edit/content?zdocs_access_token=653b90d845a785e3c69aeba" frameborder="0"></iframe>
</div>
<script src="sdk address"></script>
<script>
window.onload = async function () {
const Application = await ZOfficeSDK.connect('#doc1', true);
await Application.ready();
const sheets = await Application.ActiveWorkbook.getSheets()
console.log(sheets);
}
</script>
</body>
</html>