XLSX.utils.table_to_book is not a function #618

Closed
opened 2017-03-31 21:33:37 +00:00 by Vercryger · 7 comments
Vercryger commented 2017-03-31 21:33:37 +00:00 (Migrated from github.com)

I'm using the cdnjs version of XLSX and I found the table_to_book function isn't even there inside of XLSX.utils.

Am I missing something here?

I'm using the [cdnjs version of XLSX](https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.9.7/jszip.js) and I found the `table_to_book` function isn't even there inside of `XLSX.utils`. Am I missing something here?
SheetJSDev commented 2017-03-31 21:39:03 +00:00 (Migrated from github.com)

table_to_book was added after the 0.9.7 release. We are in the middle of testing for 0.9.8 and expect to release within the hour

`table_to_book` was added after the 0.9.7 release. We are in the middle of testing for 0.9.8 and expect to release within the hour
Vercryger commented 2017-03-31 21:40:08 +00:00 (Migrated from github.com)

@SheetJSDev Perfect, thanks! 👍

@SheetJSDev Perfect, thanks! 👍
SheetJSDev commented 2017-03-31 22:21:34 +00:00 (Migrated from github.com)

@Vercryger we pushed 0.9.8 and it's live on NPM and http://oss.sheetjs.com/js-xlsx/ and on unpkg: https://unpkg.com/xlsx@0.9.8/dist/xlsx.core.min.js

I don't know how long it will take for cdnjs to update (and it's not in our control) but hopefully it's in the next few hours. Until then use unpkg.

@Vercryger we pushed 0.9.8 and it's live on NPM and http://oss.sheetjs.com/js-xlsx/ and on unpkg: https://unpkg.com/xlsx@0.9.8/dist/xlsx.core.min.js I don't know how long it will take for cdnjs to update (and it's not in our control) but hopefully it's in the next few hours. Until then use unpkg.
vinhboy commented 2017-06-09 23:48:26 +00:00 (Migrated from github.com)

I am using Angular 4 (TypeScript) and xlsx@^0.10.4. Everything seems to be working, except XLSX.utils only has the following properties

Object
MAX_VALUE_16BITS:65535
MAX_VALUE_32BITS:-1
arrayBuffer2Blob:function (buffer)
checkSupport:function (type)
findCompression:function (compressionMethod)
getTypeOf:function (input)
isRegExp:function (object)
pretty:function (str)
string2Blob:function (str)
string2Uint8Array:function (str)
string2binary:function (str)
transformTo:function (outputType,input)
uint8Array2String:function (array)
I am using Angular 4 (TypeScript) and xlsx@^0.10.4. Everything seems to be working, except `XLSX.utils` only has the following properties ``` Object MAX_VALUE_16BITS:65535 MAX_VALUE_32BITS:-1 arrayBuffer2Blob:function (buffer) checkSupport:function (type) findCompression:function (compressionMethod) getTypeOf:function (input) isRegExp:function (object) pretty:function (str) string2Blob:function (str) string2Uint8Array:function (str) string2binary:function (str) transformTo:function (outputType,input) uint8Array2String:function (array) ```
SheetJSDev commented 2017-06-10 00:27:58 +00:00 (Migrated from github.com)

@vinhboy It looks like the utils type is not resolving as expected in your context:

export const utils: Utils;
/* ... */
export interface Utils {
/* ... */

TSLint is perfectly happy with this but I'm guessing angular is doing something unexpected. We will rename the type to XLSX$Utils to avoid this issue.

@vinhboy It looks like the [utils type](https://github.com/SheetJS/js-xlsx/blob/master/types/index.d.ts#L16) is not resolving as expected in your context: ```typescript export const utils: Utils; /* ... */ export interface Utils { /* ... */ ``` TSLint is perfectly happy with this but I'm guessing angular is doing something unexpected. We will rename the type to `XLSX$Utils` to avoid this issue.
vinhboy commented 2017-06-13 21:23:06 +00:00 (Migrated from github.com)

@SheetJSDev thanks for the quick turnaround, however, that was not the problem. I dug around all your examples a bit and finally found something that worked for me

https://gist.github.com/vinhboy/78c7b2a8efd866ea36d2109bd33e93af

Two important things

  1. Expose XLSX using systemjs meta config
  2. Manually create buffer from workbook

Let me know if any of this make sense to you, because I still don't fully understand it.

It just seems like there are a lot of manual configurations here that could be autodetected.

Thanks

@SheetJSDev thanks for the quick turnaround, however, that was not the problem. I dug around all your examples a bit and finally found something that worked for me https://gist.github.com/vinhboy/78c7b2a8efd866ea36d2109bd33e93af Two important things 1) Expose `XLSX` using systemjs meta config 2) Manually create buffer from workbook Let me know if any of this make sense to you, because I still don't fully understand it. It just seems like there are a lot of manual configurations here that could be autodetected. Thanks
SheetJSDev commented 2017-06-13 23:08:10 +00:00 (Migrated from github.com)

@vinhboy there are 3 deployment scenarios:

  1. in the browser, using a direct script tag (e.g. <script src="xlsx.full.min.js"></script>)

  2. in node, using require('xlsx')

  3. with some hybrid module bundler/loader

The script is designed to work in the first two cases, and there are plenty of dynamic checks to ensure that node-specific code is only run when require is available. For example, the fs module is only required in node:

if (typeof exports !== 'undefined') {
	if (typeof module !== 'undefined' && module.exports) {
		_fs = require('fs');
	}
}

Now, module builders aren't clever enough to see the typeof guard and realize that the module can only be required in node, hence the need for the configuration.

I would hope that the browser field in package.json would suffice: https://github.com/SheetJS/js-xlsx/blob/master/package.json#L12

	"browser": {
		"node": false,
		"crypto": false,
		"stream": false,
		"process": false,
		"fs": false
	},

but systemjs doesn't seem to read it.

@vinhboy there are 3 deployment scenarios: 1) in the browser, using a direct script tag (e.g. `<script src="xlsx.full.min.js"></script>`) 2) in node, using `require('xlsx')` 3) with some hybrid module bundler/loader The script is designed to work in the first two cases, and there are plenty of dynamic checks to ensure that node-specific code is only run when require is available. For example, the `fs` module is only required in node: ```js if (typeof exports !== 'undefined') { if (typeof module !== 'undefined' && module.exports) { _fs = require('fs'); } } ``` Now, module builders aren't clever enough to see the typeof guard and realize that the module can only be required in node, hence the need for the configuration. I would hope that the `browser` field in `package.json` would suffice: https://github.com/SheetJS/js-xlsx/blob/master/package.json#L12 ```json "browser": { "node": false, "crypto": false, "stream": false, "process": false, "fs": false }, ``` but systemjs doesn't seem to read it.
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#618
No description provided.