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

Excel freezeColumns doesn't work properly with hidden columns #4266

Open signax opened 4 months ago

signax commented 4 months ago

When using Excel.WorksheetFreezePanes.freezeColumns(count) on a sheet with hidden columns, the first time I invoke freezeColumns(1), the method doesn't freeze the first visible column.

The second time I invoke the method, it works correctly.

Environment

Expected behavior

freezeColumns(1) should always freeze the first visible column.

Current behavior

The first time the method is invoked, it doesn't freeze the first visible column. The second time it works correctly.

Steps to reproduce

  1. create an excel table with 5 columns
  2. hide the first 2 columns
  3. invoke freezeColumns(1)
penglongzhaochina commented 4 months ago

Hi @signax ,

I can't reproduce your issue in a new version excel which is "17425.20110". Could you please just update your excel and try again?

signax commented 4 months ago

Hi @penglongzhaochina ,

unfortunately I can't, it seems like I'm up to date on office 365.

Build "17328.20184" appears to be the latest release https://learn.microsoft.com/en-us/officeupdates/update-history-microsoft365-apps-by-date

zhenhuangMSFT commented 4 months ago

@penglongzhaochina, could you help check again? Thanks!

penglongzhaochina commented 3 months ago

hi @signax ,

 you can get that build now.

signax commented 3 months ago

hi @penglongzhaochina , I checked with build 17245.20176, but it doesn't work as expected.

The code is the following:

async function freezeColumn() {
  await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Sample");
    sheet.freezePanes.freezeColumns(1);
    await context.sync();
  });
}

The first time I invoke the method on a sheet with 2 hidden columns, it doesn't work as expected, the second time it does.

I tried to reproduce the problem with an higher number of frozen columns, e.g. 4.

penglongzhaochina commented 3 months ago

Hi , I still can't reproduce your case. This the screen shot. As you can see, I hided the 'C' and 'D' columns, and run your code, looks like all works well. You can see a line appear there between column 'B' and 'E'. image

signax commented 3 months ago

Hi @penglongzhaochina, in my repro steps I hid the first two columns, 'A' and 'B' and froze only one column.

You can see that the first time I call the function, nothing happens.

hideColumns

I expect the function to be idempotent.

penglongzhaochina commented 3 months ago

I can reproduce now. Thanks for reporting this issue.

It has been put on our backlog<Bug#8933901> for internal track. We will keep track of this issue and let you know if there are any updates.

penglongzhaochina commented 2 months ago

Hi @signax ,

After some internal investigation I think this is a by-design behavior. When the number of freecolumns <= the number of hidden columns the api will just show a separate line in the right of last hidden column, you can see the line if you unhide the columns. otherwise, you can see the separate line will be added.

signax commented 2 months ago

Hi @penglongzhaochina , my doubt is about the different behavior when I invoke the method multiple times.

As you can see in my gif:

I would expect an idempotent behavior, so I should not see the line on the second invoke, since the number of freecolumns <= the number of hidden columns.

penglongzhaochina commented 2 months ago

@signax ,

yes, you are right, I will do some more deep investigation.