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
688 stars 94 forks source link

Word AddIn based on react template - problem with paragraph spacing when loading insertFileFromBase64(byte[], InsertLocation, InsertFileOptions) #3580

Closed andregloeckner closed 5 months ago

andregloeckner commented 1 year ago

We want to load docx files from our cloud application and start to add login and load function in a react word add-in. Currently we fail because the loading of the file into the current Word window not map the correct paragraph.spaceAfter.

Different behavior loading a word file from byte[]. Try with the follow code blocks: response.data.content is our byte[]

When open a docx file as byte[] to new Word with that code block, the format is fine.

await Word.run(async (context) => {
    context.application.createDocument(response.data.content).open(); 
    await context.sync();
}).catch(function (error) {
    console.log('Error: ' + JSON.stringify(error));
    if (error instanceof OfficeExtension.Error) {
        console.log('Debug info: ' + JSON.stringify(error.debugInfo));
    }
});

When open a docx file as byte[] to current Word instance with that code block, it looks wrong.

await Word.run(async (context) => {
    context.document.insertFileFromBase64(response.data.content, Word.InsertLocation.replace, {
        importTheme: true,
        importStyles: true,
        importParagraphSpacing: true,
        importPageColor: true,
        importChangeTrackingMode: true
    });
    await context.sync();
}).catch(function (error) {
    console.log('Error: ' + JSON.stringify(error));
    if (error instanceof OfficeExtension.Error) {
        console.log('Debug info: ' + JSON.stringify(error.debugInfo));
    }
});

Provide required information needed to triage your issue

Your Environment

package.json "office-addin-cli": "^1.5.5", "office-addin-debugging": "^5.0.5", "office-addin-dev-certs": "^1.11.3", "office-addin-lint": "^2.2.5", "office-addin-manifest": "^1.12.3", "office-addin-prettier-config": "^1.2.0",

Expected behavior

Current behavior

When loading the byte[] with image

When loading the byte[] into an new instance of Word with open() image

Steps to reproduce

When open a docx file as byte[] to new Word with that code block, the format is fine.

await Word.run(async (context) => {
    context.application.createDocument(response.data.content).open(); 
    await context.sync();
}).catch(function (error) {
    console.log('Error: ' + JSON.stringify(error));
    if (error instanceof OfficeExtension.Error) {
        console.log('Debug info: ' + JSON.stringify(error.debugInfo));
    }
});

When open a docx file as byte[] to current Word instance with that code block, it looks wrong.

await Word.run(async (context) => {
    context.document.insertFileFromBase64(response.data.content, Word.InsertLocation.replace, {
        importTheme: true,
        importStyles: true,
        importParagraphSpacing: true,
        importPageColor: true,
        importChangeTrackingMode: true
    });
    await context.sync();
}).catch(function (error) {
    console.log('Error: ' + JSON.stringify(error));
    if (error instanceof OfficeExtension.Error) {
        console.log('Debug info: ' + JSON.stringify(error.debugInfo));
    }
});

When set the space manually after loading, it looks like more expected. But this is very slow and not fit a dynamic configuration of that.

await Word.run(async (context) => {

    const style = context.document.getStyles();
    style.load();
    await context.sync();

    style.items.map(p => {
        p.paragraphFormat.spaceAfter = 0;
        p.paragraphFormat.spaceBefore = 0;
    });

    await context.sync();
}).catch(function (error) {
    console.log('Error: ' + JSON.stringify(error));
    if (error instanceof OfficeExtension.Error) {
        console.log('Debug info: ' + JSON.stringify(error.debugInfo));
    }
});
ZYUN-MSFT commented 1 year ago

Hi @andregloeckner , thanks for reaching us.

We'd like to know that which plateform does the issue occurs? Win32 or Word Online?

Thanks.

andregloeckner commented 1 year ago

Hi @andregloeckner , thanks for reaching us.

We'd like to know that which plateform does the issue occurs? Win32 or Word Online?

Thanks.

Its the Microsoft Office 365 Professional Plus (32Bit) Windows installation.

JHJ-MS commented 1 year ago

@andregloeckner Currently, I cannot reproduce it on my side. Could you provide your Word build version(Word-account) and send your original Word document to my mailbox haijiajin@microsoft.com.

andregloeckner commented 1 year ago

@andregloeckner Currently, I cannot reproduce it on my side. Could you provide your Word build version(Word-account) and send your original Word document to my mailbox haijiajin@microsoft.com.

I send an email with the required details.

JHJ-MS commented 1 year ago

Thanks @andregloeckner. We have opened an internal bug #8274322 to track it. We'll back to you if there are any updates.

JHJ-MS commented 1 year ago

Hi @andregloeckner, After confirmation, we had a fix regarding this issue a month ago. It is rolling out. From your Office build number, it seems you are in the SAC channel which updates every six months. The fix will deployed to SAC production in Jan 2024 if everything goes as usual. Thanks.