Sharepoint2013:获取由microsoft

时间:2017-04-03 14:16:55

标签: javascript sharepoint visio

我正在使用visio Web访问Web部件在SharePoint-2013中使用visio。在VWA中,我能够通过显示形状文本来读取所有形状。现在微软发布了新的JavaScript API。它将获取visio文件的URL,并在单击名为initEmbeddedframe的按钮时显示Visio。

他们还给了一个按钮,点击选中的形状文本应该显示。但是它会抓住getSelectedShapeText()方法的块。由于我是分享点和Visio的新手,我需要你们的帮助。

希望提供需要嵌入到sharepoint页面的脚本编辑器web aprt中的代码。



<script src='https://visioonlineapi.azurewebsites.net/visio.js' type='text/javascript'></script>

Enter Visio File Url:<br/>
<script language="javascript">
document.write("<input type='text' id='fileUrl' size='120'/>");
document.write("<input type='button' value='InitEmbeddedFrame' onclick='initEmbeddedFrame()' />");
document.write("<br />");
document.write("<input type='button' value='SelectedShapeText' onclick='getSelectedShapeText()' />");
document.write("<textarea id='ResultOutput' style='width:350px;height:60px'> </textarea>");
document.write("<div id='iframeHost' />");

var textArea;
// Loads the Visio application and Initializes communication between devloper frame and Visio online frame
function initEmbeddedFrame() {
        textArea = document.getElementById('ResultOutput');
	var url = document.getElementById('fileUrl').value;
	if (!url) {
	    window.alert("File URL should not be empty");
	}
	// APIs are enabled for EmbedView action only.   
	url = url.replace("action=view","action=embedview");
	url = url.replace("action=interactivepreview","action=embedview");
  
       var session = new OfficeExtension.EmbeddedSession(url, { id: "embed-iframe",container: document.getElementById("iframeHost") });
       return session.init().then(function () {
	    // Initilization is successful 
	    textArea.value  = "Initilization is successful";
	    OfficeExtension.ClientRequestContext._overrideSession = session;
	});
     }

// Code for getting selected Shape Text using the shapes collection object
function getSelectedShapeText() {

    Visio.run(function (ctx) { 	
	   var page = ctx.document.getActivePage();
 	   var shapes = page.shapes;
   	   shapes.load();
           return ctx.sync().then(function () {
     		   textArea.value = "Please select a Shape in the Diagram";
     		   for(var i=0; i<shapes.items.length;i++)
		    {
	 	      var shape = shapes.items[i];
         	      if ( shape.select == true)
	   	       {
	   	        textArea.value = shape.text;
	                return;
	               }
		    }
	  });
     }).catch(function(error) {
		textArea.value = "Error: ";
		if (error instanceof OfficeExtension.Error) {
			textArea.value += "Debug info: " + JSON.stringify(error.debugInfo);
		}
    });
}
</script>
&#13;
&#13;
&#13;

问题是错误我点击选定的形状文本按钮。

任何帮助都会非常感激。如果您不理解我的问题,请随时告诉我。

1 个答案:

答案 0 :(得分:0)

您输入了哪个网址?它应该看起来像这样:

... / _布局/ 15 / WopiFrame.aspx sourcedoc =%7BXXX-XXX-XX%7D&安培;文件= Drawing4.vsdx&安培;行动= embedView

表示您在SharePoint中打开Visio图表,从地址栏复制URL并将其粘贴到该字段中(将XXXX替换为您的值)。如果它不起作用,请将“default”替换为“embedView”。