Posted 30 April 2025, 8:58 am EST
- Updated 30 April 2025, 9:03 am EST
Hi,
Based on our understanding, you are attempting to access the GC object; however, you do not have direct access to the source code. To work around this, you’ve correctly injected the necessary SpreadJS scripts, stylesheets, and license into the document. But still unable to get the Spread object.
This behaviour exists by design and reflects fundamental security, encapsulation, and lifecycle management principles—especially when working with complex JavaScript frameworks like React.
Why does GC.Spread.Sheets.findControl(hostElement) return undefined when GC is injected from the console?
- GC in the Global Scope ≠ Internal GC Used in App
Even if you inject the GC object via CDN from the console:
var script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/@grapecity/spread-sheets@14.2.1/dist/gc.spread.sheets.all.min.js';
document.head.appendChild(script);
This creates a separate, isolated GC context, different from what the app may have internally (if any). If the original app uses a different version or has no GC object at all, your injected GC cannot reference internal SpreadJS instances, as they were never created using your version of GC.
- findControl() works only for SpreadJS instances created by your GC context
GC.Spread.Sheets.findControl(hostElement)
works only if:
-
The SpreadJS instance was created using the same GC object (same memory reference).
-
The DOM element (hostElement) passed is the actual one linked to that GC context.
Hence, you can successfully get the spreadJS from the previous selectors you have used via the origina GC context like this below

but can not get from the GC object which was injected from the console.
When you inject GC via console, and the actual app used its own GC (or uses React encapsulation), there’s no shared reference, so findControl() returns undefined.
** Why Is This Behavior Important?**
-
Security and Encapsulation: Prevents exposing internal app state and objects to the public/global scope unintentionally.
-
Preventing Misuse and Incompatibility: Injecting a different GC version from the console might lead to version conflicts or runtime errors if the app is using another version internally.
Recommended Approach
If access is necessary:
- Modify the source code to expose the objects explicitly:
window.GC = GC;
window.workbook = workbook; // or spread instance
- This should be done only in development environments or under controlled conditions.
Please let us know if you need further guidance.
Best regards,
Ankit