本文整理汇总了TypeScript中xlsx.utils类的典型用法代码示例。如果您正苦于以下问题:TypeScript utils类的具体用法?TypeScript utils怎么用?TypeScript utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了utils类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: exportReport
///export report 3 sheets
public exportReport(json, excelFileName: string): void {
let worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json[0]);
let worksheet1: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json[1]);
let worksheet2: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json[2]);
// tslint:disable-next-line:max-line-length
let workbook: XLSX.WorkBook = { Sheets: { 'report1': worksheet, 'report2': worksheet1 , 'report3': worksheet2}, SheetNames: ['report1','report2', 'report3'] };
let excelBuffer: any = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
this.saveAsExcelFile(excelBuffer, excelFileName);
}
开发者ID:Sysarksteam,项目名称:RecipeManagementUI,代码行数:12,代码来源:excel.service.ts
示例2: parseRegister
/**
* Save all clients from the register to the database.
* @param {Object} register - Register worksheet to save to database.
*/
function parseRegister(worksheet: xlxs.IWorkSheet): db.Client[] {
const register: ExcelClient[] = xlxs.utils.sheet_to_json(worksheet) as any
register.sort((a, b) => {
if (a.nimi < b.nimi) return -1
if (a.nimi > b.nimi) return 1
return 0
})
let clients: db.Client[] = []
let clientName = ''
for (const client of register) {
if (client.nimi === clientName) {
// Add listed share number to clients shares
clients[clients.length-1].shares.push(client.numero)
} else if (client.nimi) {
clientName = client.nimi
clients.push({
name: client.nimi,
address: client.lähiosoite,
postOffice: client.postitoimipaikka,
shares: [client.numero]
})
}
}
return clients
}
开发者ID:ilmaria,项目名称:laskutus-electron,代码行数:33,代码来源:invoice-page.ts
示例3: constructor
constructor(row_index: number, column_index: number, reason: Error) {
const address = XLSX.utils.encode_cell({c: column_index, r: row_index});
super(`Version Compare Error at ${address} cell.\nreason:\n---\n${reason.stack}---\n`);
this.row_index = row_index;
this.column_index = column_index;
this.reason = reason;
this.address = address;
}
开发者ID:Narazaka,项目名称:xlsx2seed.js,代码行数:8,代码来源:xlsx2seed.ts
示例4: _set_column_info
_set_column_info() {
const column_names = [];
const column_indexes = [];
for (let column_index = 0; column_index <= this.max_column_index; ++column_index) {
const address = XLSX.utils.encode_cell({c: column_index, r: this.column_names_row});
const cell = this.sheet[address];
const value = XLSX.utils.format_cell(cell);
if (!value.length) break;
if (this.version_column && value === this.version_column) {
this._version_column_index = column_index;
} else if (this.ignore_columns.indexOf(value) === -1) {
column_names.push(value);
column_indexes.push(column_index);
}
}
this._column_names = column_names;
this._column_indexes = column_indexes;
}
开发者ID:Narazaka,项目名称:xlsx2seed.js,代码行数:18,代码来源:xlsx2seed.ts
示例5: exportAsExcelFile
public exportAsExcelFile(json: any[], excelFileName: string): void {
const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json);
console.log('worksheet',worksheet);
const workbook: XLSX.WorkBook = { Sheets: { 'data': worksheet }, SheetNames: ['data'] };
const excelBuffer: any = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
//const excelBuffer: any = XLSX.write(workbook, { bookType: 'xlsx', type: 'buffer' });
this.saveAsExcelFile(excelBuffer, excelFileName);
}
开发者ID:abuabbas1991365,项目名称:cashgift,代码行数:9,代码来源:excel.service.ts
示例6: _get_data
_get_data(require_version = '') {
const row_indexes = this._row_indexes[require_version] = [] as number[];
const rows = [];
const version_column_index = this.version_column_index;
const require_version_range = `>= ${require_version}`;
for (let row_index = this.data_start_row; row_index <= this.max_row_index; ++row_index) {
if (version_column_index && require_version) { // version check
const address = XLSX.utils.encode_cell({c: version_column_index, r: row_index});
const cell = this.sheet[address];
const value = XLSX.utils.format_cell(cell);
try {
if (value && !semver.satisfies(value, require_version_range)) {
continue;
}
} catch (error) {
throw new Xlsx2SeedVersionError(row_index, version_column_index, error);
}
}
const row: Value[] = [];
rows.push(row);
row_indexes.push(row_index);
for (const column_index of this.column_indexes) {
const address = XLSX.utils.encode_cell({c: column_index, r: row_index});
const cell = this.sheet[address];
const value = XLSX.utils.format_cell(cell);
const use_value =
// tslint:disable-next-line no-null-keyword
value == null || !value.length ? null : // empty cell -> null
// tslint:disable-next-line max-line-length
cell.t === 'n' && value.match(/E\+\d+$/) && !isNaN(value as any) ? Number(cell.v) : // 1.00+E12 -> use raw value
cell.t === 'n' && value.match(/,/) && !isNaN(cell.v) ? Number(cell.v) : // 1,000 -> use raw value
isNaN(value as any) ? value.replace(/\\n/g, '\n').replace(/\r/g, '') : // "\\n" -> "\n" / delete "\r"
Number(value);
row.push(use_value);
}
}
this._data[require_version] = new Xlsx2SeedData(this.sheet_name, this.column_names, rows);
}
开发者ID:Narazaka,项目名称:xlsx2seed.js,代码行数:38,代码来源:xlsx2seed.ts
示例7:
workbook.SheetNames.forEach((sheetName) => {
let worksheet = workbook.Sheets[sheetName];
let worksheetAsJson = xlsx.utils.sheet_to_json(worksheet);
input[sheetName] = [];
worksheetAsJson.forEach((item) => {
let row = {};
for(var k in item) {
row[k] = item[k];
}
input[sheetName].push(row);
});
});
开发者ID:sebischair,项目名称:syncpipes-server,代码行数:14,代码来源:service.ts
示例8:
const wb2 = XLSX.read("1,2,3\n4,5,6", read_opts);
write_opts.type = "binary";
const out2 = XLSX.write(wb2, write_opts);
read_opts.type = "buffer";
const wb3 = XLSX.read(fs.readFileSync("sheetjs.xlsx"), read_opts);
write_opts.type = "base64";
const out3 = XLSX.write(wb3, write_opts);
write_opts.type = "array";
const out4 = XLSX.write(wb3, write_opts);
const ws1 = XLSX.utils.aoa_to_sheet([
"SheetJS".split(""),
[1,2,3,4,5,6,7],
[2,3,4,5,6,7,8]
], {
dateNF: "yyyy-mm-dd",
cellDates: true,
sheetStubs: false
});
const ws1b = XLSX.utils.aoa_to_sheet([ "SheetJS".split("") ]);
XLSX.utils.sheet_add_aoa(ws1b, [[1,2], [2,3], [3,4]], {origin: "A2"});
XLSX.utils.sheet_add_aoa(ws1b, [[5,6,7], [6,7,8], [7,8,9]], {origin:{r:1, c:4}});
XLSX.utils.sheet_add_aoa(ws1b, [[4,5,6,7,8,9,0]], {origin: -1});
const ws2 = XLSX.utils.json_to_sheet([
{S:1,h:2,e:3,e_1:4,t:5,J:6,S_1:7},
{S:2,h:3,e:4,e_1:5,t:6,J:7,S_1:8}
], {
header:["S","h","e","e_1","t","J","S_1"],
开发者ID:CareerFairPlus,项目名称:js-xlsx,代码行数:31,代码来源:doc.ts
示例9: getSheetFromData
getSheetFromData(COLUMNS: any[], data: any[], opts: any = {}) {
const ws = {};
const range = {s: {c: COLUMNS.length, r: 10000000}, e: {c: 0, r: 0 }};
for (let R = 0; R !== (data.length + 1); ++R) {
const dataRow = R > 0 ? (R - 1) : R;
const dataToPrint = data[dataRow];
for (let C = 0; C !== COLUMNS.length; ++C) {
if (range.s.r > R) {
range.s.r = R;
}
if (range.s.c > C) {
range.s.c = C;
}
if (range.e.r < R) {
range.e.r = R;
}
if (range.e.c < C) {
range.e.c = C;
}
let currentValue: any;
if (R === 0) {
currentValue = COLUMNS[C].title;
} else {
currentValue = ObjectUtil.clone(dataToPrint);
for (let value in COLUMNS[C].att) {
const prop = COLUMNS[C].att[value];
if (ObjectUtil.isPresent(prop)) {
if (ObjectUtil.isPresent(currentValue[prop])) {
currentValue = ObjectUtil.clone(currentValue[prop]);
} else {
currentValue = null;
}
} else {
break;
}
}
}
if (ObjectUtil.isBlank(currentValue)) {
continue;
}
const cell = {};
//To Do, fix date recognition in excel
if (ObjectUtil.isPresent(COLUMNS[C]['date']) && R !== 0) {
const thisDate = new Date(currentValue.toString());
cell['v'] = thisDate;
} else {
cell['v'] = currentValue;
}
const cell_ref = XLSX.utils.encode_cell( {c: C, r: R});
if (typeof cell['v'] === 'number') {
cell['t'] = 'n';
} else if (typeof cell['v'] === 'boolean') {
cell['t'] = 'b';
} else if (cell['v'] instanceof Date) {
cell['t'] = 'n';
cell['z'] = XLSX.SSF._table[14];
cell['s'] = { numFmt: 'm/dd/yy'};
cell['v'] = this.datenum(cell['v']);
} else {
cell['t'] = 's';
}
ws[cell_ref] = cell;
}
}
if (range.s.c < 10000000) {
ws['!ref'] = XLSX.utils.encode_range(range);
}
return ws;
}
开发者ID:australdev,项目名称:app,代码行数:77,代码来源:xlsx_service.ts
注:本文中的xlsx.utils类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论