Skip to content
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

angular2 app cpexcel not found #453

Closed
Adtiv opened this issue Aug 10, 2016 · 5 comments
Closed

angular2 app cpexcel not found #453

Adtiv opened this issue Aug 10, 2016 · 5 comments

Comments

@Adtiv
Copy link

Adtiv commented Aug 10, 2016

getting a 404 error for cpexcel.js and fs.js in my Anuglar2 app using the Angular2 cli. I can see cpexcel in my vendor folder but for some reason its not finding it. I downloaded the library through npm

@tonymk
Copy link

tonymk commented Sep 2, 2016

I got the same error, have not found a work around yet :/

@Adtiv
Copy link
Author

Adtiv commented Sep 2, 2016

I've been using the library by including the cdn files in index.html

@paustint
Copy link
Contributor

paustint commented Jan 5, 2017

I am having the same issue. I am using Typescript and I really liked having the typings available, but this is not possible to use because importing the typings will automatically import the library. Very annoying to jump through all these hoops when most libraries are very easy to include into a an A2 project.

Here is how I solved:

In angular-cli.json, I added the following:

      "scripts": [
        "../node_modules/xlsx/dist/xlsx.core.min.js"
      ],

Then I copied the typings index.ds.t (from @types/xlsx) file contents into my project.

From here, I was able to use by importing the following:

declare var XLSX: any;
import { ICell, IWorkBook, IWorkSheet, IWorkSheetCell, IRange } from './models/XLSX.models';

Then here is an example function from one of my Angular 2 services to create a worksheet:

  createSheetFromNestedArrays(header: any[], data: any[][], options?: {offsetRows?: number, offsetCols?: number}): IWorkSheet {
    let ws: IWorkSheet = {};
    const offsetRows = options && options.offsetRows ? options.offsetRows : 0;
    const offsetCols = options && options.offsetCols ? options.offsetCols : 0;
    let endRow = offsetRows;
    let endCol = 0;
    const startCol = offsetCols;
    let currRow = offsetRows;
    let currCol = startCol;
    var range: IRange = {s: {c:currCol, r:currRow}, e: {c:0, r:0 }};
    let maxCols: number[] = [];

    header.forEach(headerVal => {
      this.addCellToWs({c: currCol, r: currRow}, headerVal, ws);
      currCol ++;
    });
    // Increment row
    currRow ++;
    // reset column
    currCol = startCol;
    // Complete body
    data.forEach(rowArray => {
      rowArray.forEach(colData => {
        this.addCellToWs({c: currCol, r: currRow}, colData, ws);
        currCol ++;
        endRow ++;
      });
      currRow ++;
      maxCols.push(currCol);
      currCol = startCol;
    });
    range.e.r = endRow;
    range.e.c = Math.max(...maxCols);
    this.log.debug('ws', ws);
    this.log.debug('range', range);
    ws['!ref'] = XLSX.utils.encode_range(range);
    return ws;
  }

@SheetJSDev
Copy link
Contributor

The current recommendation is to use the minified files in the dist directory. We will be adding a demo shortly

@SheetJSDev
Copy link
Contributor

@paustint would it be easier to split off the definitions to something outside the module? I think there are DT defs but I cannot speak to the quality

saarCiklum pushed a commit to Folcon/js-xlsx that referenced this issue Aug 19, 2020
closes SheetJS#447 h/t @channara
closes SheetJS#453 h/t @Adtiv @paustint
closes SheetJS#538 h/t @hsbilgen
closes SheetJS#547 h/t @Mani2693
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants