OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
670 stars 96 forks source link

`InvalidArgument` Error on PowerPoint.run when there are grouped text boxes (PowerPoint AddIn) #3632

Open wjlee2020 opened 1 year ago

wjlee2020 commented 1 year ago

RichApi.Error - InvalidArgument Error when I run PowerPoint.run on a slide that has text boxes that are grouped.

Your Environment

Expected behavior

On a press of a button, I want to read all texts within the current slide and send it as JSON to my backend. I also want to mark certain texts with an underline with textRange.getSubstring().

Current behavior

It is not a problem when there are just text boxes or shapes with texts in them. The error mentioned above only seems to raise when there are grouped texts. Even 1 grouping will raise this error.

Steps to reproduce

  1. Run yo office and generate a new react addin
  2. Create a slide with texts (text boxes or shapes with texts) and group a pair of texts
  3. Create a button that runs PowerPoint.run(async (context)) and try to read all shape items and their textFrames.

    • sample code:

      click = async () => {
      try {
      await PowerPoint.run(async (context) => {
      const slides = context.presentation.getSelectedSlides();
      
      slides.load(["items", "shapes", "textFrame", "textRange", "text"]);
      await context.sync();
      const promises = [];
      
      const items = slides.items;
      items.forEach((slide) => {
        promises.push(slide.shapes.items.map(async (shape) => {
          const textRange = shape.textFrame.textRange;
      
          // every text that isn't grouped will change to `apples`, 
          // grouped texts will raise an error InvalidArgument.
          textRange.text = "apples";
        }));
      });
      
      await Promise.all(promises);
      await context.sync();
      
      });
      } catch (e) {
      console.log(e);
      }
      };

I even tried running the sample ScribLab for powerpoint using a grouped text and it also fails.

Link to live example(s)

  1. sample from scriptlab -- again, the button works with texts that are not grouped, but once grouped, it will error.

Provide additional details

  1. Please make sure to create two new texts and group them.
  2. Select the grouped texts and try running any of the methods for the texts in the above script lab

Context

The goal of my current add-in is to mark certain offset-length of text(s) inside a slide with a click of a button. Basically, it is to show where there could be grammar / nuance issues within the sentences / texts. Since I cannot control how users will create their texts (grouped or not), it is important that being able to read/write to shapes with texts can be done for grouped texts or non-grouped texts.

Useful logs

[WARNING]: You must select only one range of text for this action to work.

[ERROR]: Error:
{
    "message": "InvalidArgument",
    "name": "RichApi.Error",
    "code": "InvalidArgument",
    "traceMessages": [],
    "innerError": null,
    "debugInfo": {
        "code": "InvalidArgument",
        "message": "InvalidArgument",
        "errorLocation": "Shape.textFrame",
        "statement": "var textFrame = itemAt.textFrame;",
        "surroundingStatements": [
            "var root = context.root;",
            "var selectedShapes = root.getSelectedShapes();",
            "var itemAt = selectedShapes.getItemAt(...);",
            "// >>>>>",
            "var textFrame = itemAt.textFrame;",
            "// <<<<<",
            "textFrame.load([\"textRange\",\"hasText\"]);"
        ],
        "fullStatements": [
            "Please enable config.extendedErrorLogging to see full statements."
        ]
    },
    "httpStatusCode": 400,
    "line": 26,
    "column": 257501,
    "sourceURL": "https://appsforoffice.microsoft.com/lib/1/hosted/powerpoint-mac-16.00.js",
    "stack": "n@https://appsforoffice.microsoft.com/lib/1/hosted/powerpoint-mac-16.00.js:26:257501\n@https://appsforoffice.microsoft.com/lib/1/hosted/powerpoint-mac-16.00.js:26:322131\n@https://appsforoffice.microsoft.com/lib/1/hosted/powerpoint-mac-16.00.js:26:320212"
}

Screenshots

https://github.com/OfficeDev/office-js/assets/70941958/b512523a-4167-464b-99f1-8ec288fccf3a

wjlee2020 commented 1 year ago

@wangyun-microsoft (cc @Rick-Kirkham )

hey guys, I was curious on the progress for this issue? Not meaning to push, but my team and I are quite eager at the moment. If you need more details/info on what we're trying achieve with the add-in, please let me know!

EsterBergen commented 1 year ago

hi @wjlee2020 - Thanks for raising this issue! I created a bug (8349880) and we'll provide updates here once available. Thanks again

wjlee2020 commented 1 year ago

@EsterBergen curious, if we're able to get the type of the shape (such as "Group"), I assume there could be a way to get the contents of that Group type? shape.groups or something?

I feel like if we had this extra property, it would be quite easy solution for what we're trying to do.

EsterBergen commented 1 year ago

@wjlee2020 - thanks for sharing! I'll add it to the bug to see what's possible. Will keep you posted here.

yamapi-t commented 9 months ago

could you kindly update the current status of this issue? we would really like to be able to read grouped texts in our slides!

EsterBergen commented 9 months ago

@yamapi-t - Thanks for the follow-up. It's still in the backlog. We'll provide more details as they become available. Thank you for your patience.

yamapi-t commented 2 months ago

@EsterBergen This bug doesn't seem to be fixed yet, is there anything I can do to help, such as contribute? Also, if there is a discussion going on in the backlog, can I have the URL?

EsterBergen commented 2 months ago

Hi @yamapi-t - Thank you for the follow-up. We haven't expanded functionality to include grouped shapes. As mentioned before, we have this in our backlog.