Excel онлайн Javascript Плагин - вызов удаленного сервера err :: ERR_CERT_AUTHORITY_INVALID - PullRequest
0 голосов
/ 25 апреля 2020

Я создал API отдыха в python следующий код:

app = Flask(__name__)


@app.route('/classifyCells', methods=['POST', 'OPTIONS'])
def index():

print(request.method)
print(request.data)

if request.method == 'OPTIONS':
    headers = {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
        'Access-Control-Max-Age': 1000,
        'Access-Control-Allow-Headers': 'origin, x-csrftoken, content-type, accept',
    }
    return '', 200, headers

print(json.loads(request.data)['excel_file_path'])

data = requests.get("http://localhost:8080/FRITZ-WEBAPI/rest/getSmells/getSmells", data=json.loads(request.data)['excel_file_path'])
data = data.json()
print(len(data['cellSmells'].keys()))
print(len(data['cellComplexities'].keys()))
return data

#return "Hello from python."

if __name__ == '__main__':

    context = ('cert.pem', 'key.pem')
    app.run(host='0.0.0.0', debug=True, ssl_context=context)

Теперь мне нужно позвонить на этот сервер из онлайн-плагина Excel, javascript код плагина следующим образом:

Office.onReady(info => {
  if (info.host === Office.HostType.Excel) {
    document.getElementById("sideload-msg").style.display = "none";
    document.getElementById("app-body").style.display = "flex";
    document.getElementById("run").onclick = run;
  }
});

export async function run() {
    try {
        await Excel.run(async context => {



            var xmlhttp = new XMLHttpRequest();   // new HttpRequest instance
            var theUrl = "https://myPublicIp:5000/classifyCells";

            xmlhttp.open("POST", theUrl);

            xmlhttp.setRequestHeader('Access-Control-Allow-Headers', '*');
            xmlhttp.setRequestHeader('Access-Control-Allow-Origin', '*');
            xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");

            xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
                if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    console.log("Call successful.");
                }else{
                    console.log("Call unsuccessful.");
                }
            }
            xmlhttp.send(JSON.stringify({"excel_file_path":"/TU Graz - PhD/Metric-based-Fault-Prediction-for-Spreadsheets-master/datasets/raw/Enron Errors Corpus/1/2_HPLN0601.xls"}));


            //const range = context.workbook.getSelectedRange();
            var sheet = context.workbook.worksheets.getItem("TestSheet");

            const range = sheet.getRange("A1:E4");
            const conditionalFormat = range.conditionalFormats.add(
                Excel.ConditionalFormatType.custom
            );
            console.log(range)
            // if a cell has a higher value than the one to its left, set that cell's font to green
            conditionalFormat.custom.rule.formula = '=IF(A1:E4<=15,TRUE)';
            conditionalFormat.custom.format.fill.color = "red";
            var rangeAddress = sheet.getUsedRange();
            rangeAddress.load("address");

            //rangeAddress.format.fill.color = "red";

            var rangeFormValues = sheet.getUsedRange();
            rangeFormValues.load("formulas");



            await context.sync();
            console.log(`The selected range address was ${rangeAddress.address}.`);
            console.log(JSON.stringify(rangeFormValues.formulas, null, 4));
            console.log(window.location.pathname);
            //location.replace('/localizedtaskpane.html')


        });
    } catch (error) {
    console.error(error);
    }
}

Мой манифест. xml плагина выглядит следующим образом, я добавил IP своего сервера в AppDomain:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="TaskPaneApp">
  <Id>2646612f-327c-43e2-a8f1-7b5add6052ed</Id>
  <Version>1.0.0.0</Version>
  <ProviderName>Contoso</ProviderName>
  <DefaultLocale>en-US</DefaultLocale>
  <DisplayName DefaultValue="Addin"/>
  <Description DefaultValue="A template to get started."/>
  <IconUrl DefaultValue="https://localhost:3000/assets/icon-32.png"/>
  <HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/icon-80.png"/>
  <SupportUrl DefaultValue="https://www.contoso.com/help"/>
  <AppDomains>
    <AppDomain>https://myPublicIp</AppDomain>
  </AppDomains>
  <Hosts>
    <Host Name="Workbook"/>
  </Hosts>
  <DefaultSettings>
    <SourceLocation DefaultValue="https://localhost:3000/taskpane.html"/>
  </DefaultSettings>
  <Permissions>ReadWriteDocument</Permissions>
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
    <Hosts>
      <Host xsi:type="Workbook">
        <DesktopFormFactor>
          <GetStarted>
            <Title resid="GetStarted.Title"/>
            <Description resid="GetStarted.Description"/>
            <LearnMoreUrl resid="GetStarted.LearnMoreUrl"/>
          </GetStarted>
          <FunctionFile resid="Commands.Url"/>
          <ExtensionPoint xsi:type="PrimaryCommandSurface">
            <OfficeTab id="TabHome">
              <Group id="CommandsGroup">
                <Label resid="CommandsGroup.Label"/>
                <Icon>
                  <bt:Image size="16" resid="Icon.16x16"/>
                  <bt:Image size="32" resid="Icon.32x32"/>
                  <bt:Image size="80" resid="Icon.80x80"/>
                </Icon>
                <Control xsi:type="Button" id="TaskpaneButton">
                  <Label resid="TaskpaneButton.Label"/>
                  <Supertip>
                    <Title resid="TaskpaneButton.Label"/>
                    <Description resid="TaskpaneButton.Tooltip"/>
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="Icon.16x16"/>
                    <bt:Image size="32" resid="Icon.32x32"/>
                    <bt:Image size="80" resid="Icon.80x80"/>
                  </Icon>
                  <Action xsi:type="ShowTaskpane">
                    <TaskpaneId>ButtonId1</TaskpaneId>
                    <SourceLocation resid="Taskpane.Url"/>
                  </Action>
                </Control>
              </Group>
            </OfficeTab>
          </ExtensionPoint>
        </DesktopFormFactor>
      </Host>
    </Hosts>
    <Resources>
      <bt:Images>
        <bt:Image id="Icon.16x16" DefaultValue="https://localhost:3000/assets/icon-16.png"/>
        <bt:Image id="Icon.32x32" DefaultValue="https://localhost:3000/assets/icon-32.png"/>
        <bt:Image id="Icon.80x80" DefaultValue="https://localhost:3000/assets/icon-80.png"/>
      </bt:Images>
      <bt:Urls>
        <bt:Url id="GetStarted.LearnMoreUrl" DefaultValue="https://go.microsoft.com/fwlink/?LinkId=276812"/>

        <bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html"/>
        <bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3000/taskpane.html"/>

      </bt:Urls>
      <bt:ShortStrings>
        <bt:String id="GetStarted.Title" DefaultValue="Get started with your sample add-in!"/>
        <bt:String id="CommandsGroup.Label" DefaultValue="Commands Group"/>
        <bt:String id="TaskpaneButton.Label" DefaultValue="EXQUISITE"/>
      </bt:ShortStrings>
      <bt:LongStrings>
        <bt:String id="GetStarted.Description" DefaultValue="Your sample add-in loaded succesfully. Go to the HOME tab and click the 'Show Taskpane' button to get started."/>
        <bt:String id="TaskpaneButton.Tooltip" DefaultValue="Click to Show a Taskpane"/>
      </bt:LongStrings>
    </Resources>
  </VersionOverrides>
</OfficeApp>

Каждый раз, когда я звоню через Интернет Excel после загрузки файла xml в Excel, я получаю ошибку net :: ERR_CERT_AUTHORITY_INVALID в консоли. Дайте мне знать, что я делаю не так.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...