question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

['!cols'] is undefined

See original GitHub issue

I am trying to modify XLS files and keeping the visibility values for columns.

I am using ^0.14.3 inside a web worker with Angular ^8.0.0.

However, whenever I read an XLS file, ['!cols'] is not defined in the worksheet object, even though there are hidden columns in the file. So it is impossible for me to retrieve the ‘hidden’ values for the columns.

Am I missing something? !ref and !margins are there.

Here’s the web worker code:

/// <reference lib="webworker" />

declare function importScripts(...urls: string[]): void;

declare function postMessage(message: any): any;

declare const XLSX: any;

addEventListener('message', ({ data }) => {

    let str = `${data.window.protocol}//path/to/xlsx.full.min.js`;

    importScripts(str);

    const xls = XLSX.read(data.file, { type: 'array' });

    const sheet = xls.Sheets[xls.SheetNames[0]];

    console.log(sheet['!cols']);    // returns undefined

    // (...)

    postMessage(xls);

});

Below function sits in a service and spins up a Worker for every file from a FileList

loadXLS(files: FileList, values: {}, loc: string) {
        Array.from(files).forEach(file => {
            const worker = new Worker('../excel.worker.ts', {
                type: 'module'
            });
            const reader: FileReader = new FileReader();
            reader.readAsArrayBuffer(file);
            reader.onloadend = (e: any) => {
                worker.onmessage = ({ data }) => {
                    XLSX.writeFile(data, file.name);
                };
                worker.postMessage({ file: new Uint8Array(e.target.result), locale: loc, val: values, window: this.inputWindow });
            };
        });
    }

Here’s a branch that provides an implementation example: https://github.com/fripso/kupshred/tree/missingcols

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
SheetJSDevcommented, Dec 27, 2019

@fripso for XLSX format, cellStyles: true must be set to extract column metadata.

@cjl-df “range is wrong” is almost always an issue in the file. XLS has a Dimension record and XLSX also has a way of specifying range, so the reader will set the range based on what that file reports (even if cells exist outside). We’d be glad to take a look at a sample file if you can share one

0reactions
cjl-dfcommented, Dec 30, 2019

image

but how to decide the font style

Read more comments on GitHub >

github_iconTop Results From Across the Web

['!cols'] is undefined · Issue #1560 · SheetJS ...
I am trying to modify XLS files and keeping the visibility values for columns. I am using ^0.14.3 inside a web worker with...
Read more >
Sheetjs `!rows` (and `!cols`) property not existing on newly ...
it returns undefined . Inspecting ws shows it also doesn't hold that property. How would I access the row properties (and set for...
Read more >
How to Handle "undefined columns selected" in R
undefined columns selected. This error occurs when you try to select a subset of a data frame and forget to add a comma....
Read more >
How to deal with error “undefined columns selected when ...
The error “undefined columns selected when subsetting data frame” means that R does not understand the column that you want to use while ......
Read more >
Export to Excel - 'Cols' is null or undefined
Hi, I'm hoping someone out there can help me... I've got a radgrid and in the <CommandItemTemplate> I have a button with CommandName="E......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found