Skip to content

Commit

Permalink
change
Browse files Browse the repository at this point in the history
  • Loading branch information
ZengXiangJun committed Sep 22, 2020
1 parent c9ccb60 commit 174bc7a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Enhancer三方组件 xlsx-parser 使用说明
### 简介
- xlsx-parser是基于[Enhancer](https://enhancer.io)平台开发的组件, 能在此平台上良好运行
- xlsx-parser是基于[Enhancer](https://enhancer.io)平台开发的组件。
- xlsx-parser可将 数据 , Html 和 Excel 任意转换。

### 生成界面
Expand Down Expand Up @@ -32,7 +32,6 @@
- 将Excel导入并解析为多种格式数据
- 可通过页面简单修改Excel文件


### 可用事件说明
#### 加载Excel(On Excel Loaded)
- 【事件 ID】onExcelLoaded
Expand All @@ -46,7 +45,6 @@
- 【事件 ID】onSheetClick
- 【触发时机】单击页面上表格时。


#### 单元格获得焦点(On Cell Focus)
- 【事件 ID】onCellFocus
- 【触发时机】页面表格单元获得焦点时(编辑)。
Expand Down Expand Up @@ -121,7 +119,5 @@
- 【说明】当前单元格内容
- 【示例】"统计"


### 其它
- [Enhancer 教程](https://enhancer.io/tutorials)
- [Enhancer 社区](https://forum.enhancer.io/#p=1&t=5)
30 changes: 17 additions & 13 deletions src/widget/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
require('./index.less');
var locale = require('./i18n');
var tpl = require('./index.html');
var XLSX = require('xlsx');

Enhancer.registerWidget({
construct: function(profile, zContext) {
this.XLSX = require('xlsx');

profile = $.extend({
loadData: false,
editExcel: true,
outputExcel: true
}, profile);

var that = this;
var $container = this.getContainer();
this.profile = profile;
this.$container = $container;
var that = this;
this.workbook = {};
this.excelName = 'download.xlsx';
$container.html(tpl({
Expand All @@ -25,7 +28,7 @@ Enhancer.registerWidget({
function updateWb() {
var $table = $container.find('.sheetWindow table');
var name = $table.attr('id');
var data = XLSX.utils.table_to_sheet($table[0]);
var data = that.XLSX.utils.table_to_sheet($table[0]);
$container.find('.sheets a[name="' + name + '"]').data('sheet', data);
$container.find('.sheets a').map(function() {
var name = $(this).attr('name');
Expand Down Expand Up @@ -62,7 +65,7 @@ Enhancer.registerWidget({
}
}
})
var table = XLSX.utils.sheet_to_html(sheet, {
var table = that.XLSX.utils.sheet_to_html(sheet, {
id: name,
editable: true
});
Expand All @@ -79,7 +82,7 @@ Enhancer.registerWidget({
$container.find('#outputExcel').click(function() {
if (that.workbook.Sheets) {
updateWb();
XLSX.writeFile(that.workbook, that.excelName);
that.XLSX.writeFile(that.workbook, that.excelName);
that.trig('onExcelOutputed');
}
})
Expand Down Expand Up @@ -140,7 +143,7 @@ Enhancer.registerWidget({
if (CURR_SHEET_NAME) {
CURR_SHEET = this.workbook.Sheets[CURR_SHEET_NAME]
}
var CURR_SHEET_TO_JSON = XLSX.utils.sheet_to_json(CURR_SHEET);
var CURR_SHEET_TO_JSON = this.XLSX.utils.sheet_to_json(CURR_SHEET);
var CURR_SHEET_ROWS = CURR_SHEET_TO_JSON.length;
var CURR_SHEET_COLS = 0;
CURR_SHEET_TO_JSON.forEach(function(val) {
Expand All @@ -156,9 +159,9 @@ Enhancer.registerWidget({
CURR_CELL_CONTENT = CURR_SHEET[CURR_CELL_POS].v;
}
for (var key in this.workbook.Sheets) {
SHEETS_TO_CSV[key] = XLSX.utils.sheet_to_csv(this.workbook.Sheets[key]);
SHEETS_TO_JSON[key] = XLSX.utils.sheet_to_json(this.workbook.Sheets[key]);
SHEETS_TO_FORMULAE[key] = XLSX.utils.sheet_to_formulae(this.workbook.Sheets[key]);
SHEETS_TO_CSV[key] = this.XLSX.utils.sheet_to_csv(this.workbook.Sheets[key]);
SHEETS_TO_JSON[key] = this.XLSX.utils.sheet_to_json(this.workbook.Sheets[key]);
SHEETS_TO_FORMULAE[key] = this.XLSX.utils.sheet_to_formulae(this.workbook.Sheets[key]);
}
var data = {
'EXCEL_DATA': EXCEL_DATA,
Expand Down Expand Up @@ -186,12 +189,13 @@ Enhancer.registerWidget({
var that = this;
if (profile.loadData) {
this.getSourceData(profile.srcId, {}, function(data){
console.log(data);
if (data.rows) {
data = data.rows;
}
that.workbook = XLSX.utils.book_new();
var sheet = XLSX.utils.json_to_sheet(data);
XLSX.utils.book_append_sheet(that.workbook, sheet, 'Sheet1');
that.workbook = that.XLSX.utils.book_new();
var sheet = that.XLSX.utils.json_to_sheet(data);
that.XLSX.utils.book_append_sheet(that.workbook, sheet, 'Sheet1');
that.__initSheet();
that.trig('complete');
})
Expand Down Expand Up @@ -224,7 +228,7 @@ Enhancer.registerWidget({
that.excelName = f.name;
var reader = new FileReader();
reader.onload = function (e) {
that.workbook = XLSX.read(new Uint8Array(e.target.result), {
that.workbook = that.XLSX.read(new Uint8Array(e.target.result), {
type: 'array',
cellFormula: false,
cellHTML: true,
Expand Down

0 comments on commit 174bc7a

Please sign in to comment.