-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem
When a pivot table source data contains hyperlink objects (from URL type columns), ExcelJS throws an error:
Error: {"text":"Edit...","hyperlink":"https://v4.protobi.com/profile/physician/1821262676"} not in sharedItems [{"text":"Edit...","hyperlink":"https://v4.protobi.com/profile/physician/1821262676"}, ...]
The error shows the exact same object appearing on both sides - in the "not found" part AND in the sharedItems array. This indicates a JavaScript object comparison problem.
Root Cause
When checking if a value exists in sharedItems using indexOf() or ===, JavaScript compares object references, not object content. Two objects with identical properties ({text: "Edit...", hyperlink: "..."}) are not considered equal unless they're the exact same object reference.
const obj1 = {text: "Edit...", hyperlink: "https://..."};
const obj2 = {text: "Edit...", hyperlink: "https://..."};
obj1 === obj2 // false! Different references
[obj1].indexOf(obj2) // -1 (not found)Location
The issue is likely in the code that searches for values in sharedItems, probably in:
lib/xlsx/xform/pivot-table/pivot-cache-records-xform.jslib/doc/pivot-table.js
Proposed Solution
For hyperlink objects (and any other object types), need to use deep equality comparison instead of reference comparison:
function findInSharedItems(value, sharedItems) {
if (typeof value !== 'object' || value === null) {
return sharedItems.indexOf(value);
}
// For objects, do deep comparison
return sharedItems.findIndex(item => {
if (typeof item !== 'object' || item === null) return false;
// Compare hyperlink objects
if (value.hyperlink && item.hyperlink) {
return value.text === item.text && value.hyperlink === item.hyperlink;
}
// Add other object type comparisons as needed
return JSON.stringify(value) === JSON.stringify(item);
});
}Workaround
For now, avoid using URL/hyperlink type columns in pivot table source data.
Impact
This makes it impossible to create pivot tables when the source data contains hyperlink columns, which is common for linking to detailed records or external resources.