I'd like to add a file viewer web part to the home page of my online modern site via an SPFx Part. To try to make things easier, I have a fully configured file viewer part with an Excel file on a different page, and I'd like to use the properties of that part to configure the new part.

Following the procedure as documented here:

newPart["serverProcessedContent"] = templatePart["serverProcessedContent"];

Using the debugger, I can see that the serverProcessedContent and propertieJson are both populated correctly. The save() occurs with no error. But the end result after the save is a part that has the properties but not the serverProcessedContent, which is still null. The end result for the user is a file viewer web part that prompts the user to select a file, but the web part properties correctly display the properties from the template part (sheet name, starting cell, etc.)

Any suggestions on how to fully configure a client side file viewer web part via code?


Are you actually importing the info from the excel into the new page? Based on the documentation you followed, every code example there shows some variant of the command import while the code sample you have provided does not. It would seem that both are populating with their own info without the goodies from the excel being imported into the final resulting in the null...

Also, const page is not shown in your code... so is the page being built?

Additionally, PnPJS in not a standard install with SP... has it been properly installed and registered on the server?

(This would be a comment as I am asking for clarification assuming I had enough reputation... apologies)

  • Sorry, I didn't include the full code. I have the page object, pnpjs, and imports. I can successfully add a new fileviewer webpart to the page. The new web part has some properties set correctly, such as sheet name, starting cell, ending cell, and the checkboxes of whether or not to show gridlines or allow sorting. What's missing from my webpart is the path to the file that needs to be displayed. While I can't find any documentation on this part, the path seems to be saved in the serverProcessedContent object, which I can't seem to modify. – Mike2500 Sep 24 '18 at 23:05
  • Try building a few vars. var1: base path var2: add portion to path var3 = var1+var2. Then use var3 to populate with. If that works on a single iteration, build it as an array and iterate through the contents of the object populating var 2 with the sub-portions. – Chris Fells Sep 24 '18 at 23:13
  • In debug mode, I can see the paths being set properly. page.save() runs without issue. But after refreshing the actual page, those values are gone. Programatically, if I retrieve the same web part object, those path fields are back to being null. – Mike2500 Sep 24 '18 at 23:24
  • hmmm... so the webpart has no way to keep the info current and is nulling it out. Ok... what about populating the path info into a SP list identified by path and session id. kill the session id entries after x time to prevent the list from getting too large and causing issues. Load the webpart based off the info in the list and the user's session id. This will allow the info to still be dynamic and easily updatable. – Chris Fells Sep 24 '18 at 23:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.