本文整理汇总了TypeScript中xlsx.utils.encode_range方法的典型用法代码示例。如果您正苦于以下问题:TypeScript utils.encode_range方法的具体用法?TypeScript utils.encode_range怎么用?TypeScript utils.encode_range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xlsx.utils
的用法示例。
在下文中一共展示了utils.encode_range方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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;
}