-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Cannot set column order for sheets with empty, right-side columns #1471
Comments
Thank you for contacting us. This is a correct behavior as this error is being thrown when:
As mentioned in the documentation, this is because the |
Thanks for the reply @adrianszymanski89. I have two follow-ups.
|
It isn't stated directly in the documentation, but as the |
Thanks for clarifying @adrianszymanski89.
This seems to only be true if the For example: const engine = HyperFormula.buildFromSheets({
MySheet: [[null, "First", "=B1"]],
});
// { width: 3, height: 1 }
console.log(engine.getSheetDimensions(0)); This exact case appears in this unit test. What is unintuitive to me is that if you start with the case defined in the unit test and move the const engine = HyperFormula.buildFromSheets({
MySheet: [[null, "First", "Second"]],
});
// [ [ null, 'First', 'Second' ] ]
// { width: 3, height: 1 }
console.log(
engine.getSheetSerialized(0),
engine.getSheetDimensions(0)
);
// Move null value to right side of sheet
engine.setColumnOrder(0, [2, 0, 1]);
// [ [ 'First', 'Second' ] ]
// { width: 3, height: 1 }
console.log(
engine.getSheetSerialized(0),
engine.getSheetDimensions(0)
);
// Move null value from right side of sheet
// Same as original example but no error!
engine.setColumnOrder(0, [0, 2, 1]);
// [ [ 'First', null, 'Second' ] ]
// { width: 3, height: 1 }
console.log(
engine.getSheetSerialized(0),
engine.getSheetDimensions(0)
); Sorry for the lengthy response. These results were unintuitive to me and I can't tell if this is a bug or expected behavior. I'd be happy to contribute to the documentation to explain this if I could get a better understanding of the expected behavior. |
Thank you for your thorough investigation of this problem. At this point, I think our developer responsible for Hyperformula can better answer your question. @sequba Can I please ask you to look at this issue? Thank you. |
Hi @JohannCooper, Your observation about the I can understand the confusion, as this mechanism causes sheet dimensions to change seemingly unpredictably.
As you already discovered, you can write a non-empty value (e.g., const sheetName = "MySheet";
const engine = HyperFormula.buildFromSheets({
[sheetName]: [["First", "=A1"]],
});
const sheetId = engine.getSheetId(sheetName);
engine.setColumnOrder(sheetId, [0, 1]);
engine.addColumns(sheetId, [1, 1]);
console.log(engine.getSheetSerialized(sheetId)); |
Personally, I wouldn't consider it a bug, but the documentation about setColumnOrder and setRowOrder could be improved to make it clear, that the length of the permutation array must match the current sheet dimension. |
Thanks for explaining the reasoning behind the current API. Based your description, I agree that this isn't necessarily a bug. In addition to your suggestion, it would be great to see this clarified in the documentation for No further questions from my end! Thanks for all the thorough replies and for building an awesome package. Happy holidays! ✨ |
Ok. I'm closing this issue. The docs changes will be made in #1476 |
Description
HyperFormula.setColumnOrder
does not work when the right-side columns are empty.Based on this discussion, it seems like
HyperFormula.getSheetDimensions
is behaving as expected. What then is the recommend way to set the column order such that the empty column is between the two non-empty columns?The only workaround I've found is to initialize my sheet using
""
instead ofnull
.Video or screenshots
No response
Demo
https://codesandbox.io/p/sandbox/beautiful-hermann-pyz8z5
HyperFormula version
2.7.1
Your framework
No response
Your environment
Ubuntu 23.10
The text was updated successfully, but these errors were encountered: