Excel js, не могу позвонить - PullRequest
       12

Excel js, не могу позвонить

0 голосов
/ 23 октября 2018

Мы разрабатываем плагин Excel с использованием Excel JS.Код сервера, написанный на Java и развернутый на сервере wildfy.

Через плагин Excel я не могу сделать остальной вызов для получения пользовательских данных.Цель состоит в том, чтобы выполнить вход в систему и получить байт-формат excel, сохраненный на сервере, и отобразить его в excel.

Есть предложения?Ниже приведен пример кода, который мы до сих пор пробовали.

index.html

<body class="ms-font-m ms-welcome">
<div id="content-header">
    <div class="padding">
        <h1>Welcome</h1>
    </div>
</div>
<div id="content-main">
    <button id="ping-server3" onclick="pingServer2()">Ping server2</button>
    <p id="demo"></p>
    <p id="demo1"></p>
    <button id="ping-server">Ping server</button>
    <p></p> 
    <div class="padding">
        <form>  
        <div class="container">
        <label for="uname"><b>Username</b></label>
        <input id="uname" type="text" placeholder="Enter Username" 
             name="uname" required>

        <label for="psw"><b>Password</b></label>
        <input type="password" placeholder="Enter Password" name="psw" 
             required>

        <button id="login-button" onclick="pingServer2()">Login</button>
        </div>
        <div class="container" style="background-color:#f1f1f1">
            <span class="psw"><a href="#">Need password help?</a></span>
        </div>
        </form>
    </div>
</div>

<script type="text/javascript" src="node_modules/core-js/client/core.js"> 
</script>
<script type="text/javascript" src="node_modules/jquery/dist/jquery.js"> 
</script>
<script type="text/javascript" src="node_modules/office-ui-fabric- 
       js/dist/js/fabric.js"></script>
<script type="text/javascript" src="app.js" ></script>
 <script type="text/javascript" src="utility.js" ></script>
</body>

app.js

(function () { Office.initialize = function (reason) { $ (документ) .ready (function (function () {

      if (!Office.context.requirements.isSetSupported('ExcelApi', 1.7)) {
        alert("ERROR");
        console.log('Sorry. The tutorial add-in uses Excel.js APIs that are 
 not available in your version of Office.');
      }
      $('#login-button').click(createTable);
    });
  };


  function createTable() {
      axios({
        method: 'post',
        url: 'http://localhost:8183/x/operation.do?&operationId=LOGIN_USER',
        data: {emailAddress : 'x@xyz.com,password : '123@asdA'}
    })
    .then(response => {
        $('#demo').innerHTML = response.data; 
        content=response.data.uiUser.createdBy;
        $('#demo1').innerHTML = content;
    })
    .catch(error => {
        $('#demo').innerHTML = response.status;
    });

    Excel.run(function (context) {

      const currentWorksheet = 
      context.workbook.worksheets.getActiveWorksheet();
      const expensesTable = currentWorksheet.tables.add("A1:D1", true 
     /*hasHeaders*/);
      expensesTable.name = "ExpensesTable";

      expensesTable.getHeaderRowRange().values = [["Date", "Merchant", 
        "Category", "Amount"]];

      expensesTable.rows.add(null /*add at the end*/, [["1/1/2017", "The 
   Phone Company", "Communications", "120"], ["1/2/2017", "Northwind 
    Electric Cars", "Transportation", "142.33"], ["1/5/2017", "Best For You 
    Organics Company", "Groceries", "27.9"], ["1/10/2017", "Coho Vineyard", 
     "Restaurant", "33"], ["1/11/2017", "Bellows College", "Education", 
     "350.1"], ["1/15/2017", "Trey Research", "Other", "135"], ["1/15/2017", 
     "Best For You Organics Company", "Groceries", "97.88"]]);

      expensesTable.columns.getItemAt(3).getRange().numberFormat = 
     [['€#,##0.00']];
      expensesTable.getRange().format.autofitColumns();
      expensesTable.getRange().format.autofitRows();

      return context.sync();
    }).catch(function (error) {
      console.log("Error: " + error);
      if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
      }
    });
  }
})

1 Ответ

0 голосов
/ 20 ноября 2018

URL-адрес, который вы пытаетесь отправить, находится в http формате:

http://localhost:8183/x/operation.do?&operationId=LOGIN_USER

Надстройка Excel развернута с использованием * 1011 HTTPS *.Если вы осмотрите AddIn, используя F12 Debugger Tools, вы увидите ошибку Mixed Content .

Смешанный контент: страница в 'https://Your_AddIn_Url' была загружена через HTTPS, но запросил небезопасный ресурс' http://localhost:8183/x/operation.do?&operationId=LOGIN_USER'. Этот запрос был заблокирован;контент должен обслуживаться по HTTPS.

Использование конечной точки https должно решить вашу проблему.

...