Reputation: 2135
I was able to use this library in a Nodejs application https://github.com/SheetJS/j but I can't seem to get it working in a new project where I need to use amd modules.
With commonjs I was able to do:
///<reference path="../../node_modules/j/misc/j.d.ts"/>
var Excel = <J>require('J');
Latest attempt with AMD I am trying:
/// <amd-dependency path = "../../j/j" /> (the Library is in a different spot in this project)
private run(){
var Excel = require('../../j/j');
var array = Excel.readFile("D:\\file.xls");
}
error TS2095: Could not find symbol 'require'. This is based of watching this I think this J library knows about exports but I could be wrong? https://www.youtube.com/watch?v=4AGQpv0MKsA
EDIT:
///<reference path='misc/cfb.d.ts'/>
interface Cell {
v;
w;
t: string;
f: string;
ixfe: number;
}
interface CellAddress {
c: number;
r: number;
}
interface CellRange {
s: CellAddress;
e: CellAddress;
}
interface Worksheet {
[key: string]: Cell;
}
interface Worksheets {
[key: string]: Worksheet;
}
interface Workbook {
SheetNames: string[];
Sheets: Worksheets;
}
interface J {
parse_xlscfb(cfb:CFBContainer): Workbook;
read;
readFile(filename:string): any;
utils: {
encode_col(col:number): string;
encode_row(row:number): string;
encode_cell(cell:CellAddress): string;
encode_range;
decode_col(col:string): number;
decode_row(row:string): number;
split_cell(cell:string): string[];
decode_cell(cell:string): CellAddress;
decode_range(cell:string): CellRange;
sheet_to_csv(worksheet:Worksheet): string;
get_formulae(worksheet:Worksheet): string[];
make_csv(worksheet:Worksheet): string;
sheet_to_row_object_array(worksheet:Worksheet): Object[];
};
verbose: Number;
CFB: CFB;
main;
}
Edit Tried answer: Tried adding module to top of d.ts file
///<reference path='misc/cfb.d.ts'/>
declare module 'J'{
var j: J;
export = j;
}
Upvotes: 1
Views: 65
Reputation: 275917
Where are you getting j.d.ts
from? You should update it to include:
declare module 'J'{
var j:J;
export = j;
}
Then you can do :
import Excel = require('J');
Notice import instead of var. This way you can compile with --module commonjs
for node and --module amd
for requirejs.
More : https://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1
Upvotes: 1