├── .gitignore ├── Copy From Excel- Example -GIF.gif ├── README.md └── WebContent ├── Component.js ├── control └── CopyPasteTable.js ├── index.html └── view ├── CopyPaste.controller.js └── CopyPaste.view.xml /.gitignore: -------------------------------------------------------------------------------- 1 | /WebContent/META-INF/** 2 | /WebContent/WEB-INF/** -------------------------------------------------------------------------------- /Copy From Excel- Example -GIF.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bhardwaj-rahul/Copy-ctrl-c-From-Excel-To-Table-SAPUI5/49e5675229ab0578484fbabd95aa0a0cbc4ee9e9/Copy From Excel- Example -GIF.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Copy-ctrl-c-From-Excel-To-Table-SAPUI5 2 | Copy (Ctrl +C) from Excel into SAPUI5 Table 3 | 4 | 1. Allows user to Copy data from Excel to SAPUI5 Table. 5 | 2. User can copy the desired result and paste. 6 | 3. User can later add the missing data by selecting the data and pasting into the selected Columns 7 | 4. Data inserted into SAPUI5 table is fetched from clipboard. 8 | 5. Operations can be done by Ctrl+C(copy) and Ctrl+v(Paste) into SAPUI5 table. 9 | 10 | 11 | Please check the Example-GIF file for Demo. 12 | 13 | Note: It is a complete working Project. 14 | 15 | # Custom Control: CopyPasteTable 16 | 17 | New Custom Control CopyPasteTable is created which listens to the paste events on the table. 18 | 19 | Here is the Demo: 20 | 21 | ![alt text](https://github.com/bhardwaj-rahul/Copy-ctrl-c-From-Excel-To-Table-SAPUI5/blob/master/Copy%20From%20Excel-%20Example%20-GIF.gif "Demo Example") 22 | -------------------------------------------------------------------------------- /WebContent/Component.js: -------------------------------------------------------------------------------- 1 | sap.ui.define([ 2 | 'sap/ui/core/UIComponent' 3 | ], function (UIComponent) { 4 | "use strict"; 5 | 6 | return UIComponent.extend("sap.cc.Component", { 7 | metadata: { 8 | rootView: "sap.cc.view.CopyPaste", 9 | dependencies: { 10 | libs: [ 11 | "sap.ui.unified", 12 | "sap.m" 13 | ] 14 | }, 15 | includes : [], 16 | 17 | config: { 18 | sample: { 19 | stretch: true, 20 | files: [ 21 | 22 | ] 23 | } 24 | } 25 | }, 26 | 27 | init: function () { 28 | 29 | UIComponent.prototype.init.apply(this, arguments); 30 | 31 | }, 32 | }); 33 | 34 | }); 35 | -------------------------------------------------------------------------------- /WebContent/control/CopyPasteTable.js: -------------------------------------------------------------------------------- 1 | sap.ui.define([ 2 | "sap/m/Table" 3 | ], function(Table) { 4 | return Table.extend("sap.cc.control.CopyPasteTable", { 5 | onInit: function() { 6 | 7 | }, 8 | insertRows:function(value,table,model,startRowIndex,startProperty){ 9 | 10 | var that = this; 11 | var rows = value.split(/\n/); 12 | var cells = table.getBindingInfo('items').template.getCells(); 13 | var templateItem = []; 14 | var itemsPath = table.getBindingPath('items'); 15 | var itemsArray = table.getModel(model).getProperty(itemsPath); 16 | var startPropertyIndex = 0; 17 | var model = table.getModel(model); 18 | if(startRowIndex === undefined){ 19 | startRowIndex = 0; 20 | } 21 | for (var int = 0; int < cells.length; int++) { 22 | var cell_element = cells[int]; 23 | var path = cell_element.getBindingPath('value'); 24 | templateItem.push(path); 25 | if(path === startProperty){ 26 | startPropertyIndex = int; 27 | } 28 | 29 | } 30 | 31 | for (var int = 0; int < rows.length-1; int++) { 32 | var rows_element = rows[int]; 33 | var cells = rows_element.split(/\t/); 34 | 35 | 36 | var originalObject = model.getProperty(itemsPath+"/"+startRowIndex++); 37 | if(originalObject === undefined){ 38 | originalObject = {}; 39 | for(var k =0; k < templateItem.length; k++){ 40 | originalObject[templateItem[k]] =undefined; 41 | } 42 | itemsArray.push(originalObject); 43 | } 44 | 45 | var lesserLength = Math.min(templateItem.length,(cells.length + startPropertyIndex)); 46 | for(int2 = startPropertyIndex,intValue=0; int2 < lesserLength; int2++,intValue++){ 47 | var name = templateItem[int2]; 48 | originalObject[name] =cells[intValue]; 49 | 50 | } 51 | 52 | } 53 | model.refresh(); 54 | 55 | 56 | 57 | }, 58 | onAfterRendering: function () { 59 | var that = this; 60 | sap.m.Table.prototype.onAfterRendering.apply(this,arguments); 61 | this.attachBrowserEvent('paste', function(e){ 62 | e.preventDefault(); 63 | var text = (e.originalEvent || e).clipboardData.getData('text/plain'); 64 | console.log(text); 65 | that.insertRows(text,this,undefined); 66 | }); 67 | this.getAggregation('items').forEach(function(row) { 68 | row.getCells().forEach(function(cell) { 69 | cell.attachBrowserEvent('paste',function(e){ 70 | e.stopPropagation(); 71 | 72 | e.preventDefault(); 73 | var text = (e.originalEvent || e).clipboardData.getData('text/plain') ; 74 | console.log(text); 75 | var domCell = jQuery.sap.domById(e.currentTarget.id) 76 | var insertCell = jQuery('#'+domCell.id).control()[0]; 77 | var itemsPath = that.getBindingPath('items'); 78 | var pathRow = insertCell.getBindingContext().sPath; 79 | var startRowIndex = pathRow.split(itemsPath+"/")[1]; 80 | var startProperty = insertCell.getBindingPath('value'); 81 | that.insertRows(text,that,undefined,startRowIndex,startProperty); 82 | }); 83 | }); 84 | }); 85 | 86 | 87 | }, 88 | renderer: sap.m.Table.prototype.getRenderer() 89 | 90 | 91 | }); 92 | }); -------------------------------------------------------------------------------- /WebContent/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 18 | 19 | 22 | 30 | 31 | 32 | 33 |
34 | 35 | -------------------------------------------------------------------------------- /WebContent/view/CopyPaste.controller.js: -------------------------------------------------------------------------------- 1 | sap.ui.controller("sap.cc.view.CopyPaste", { 2 | 3 | /** 4 | * Called when a controller is instantiated and its View controls (if available) are already created. 5 | * Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization. 6 | * @memberOf testbed.CopyPaste 7 | */ 8 | onInit: function() { 9 | var model = new sap.ui.model.json.JSONModel({items:[]}); 10 | this.getView().setModel(model); 11 | 12 | 13 | }, 14 | 15 | /** 16 | * Similar to onAfterRendering, but this hook is invoked before the controller's View is re-rendered 17 | * (NOT before the first rendering! onInit() is used for that one!). 18 | * @memberOf testbed.CopyPaste 19 | */ 20 | // onBeforeRendering: function() { 21 | // 22 | // }, 23 | 24 | /** 25 | * Called when the View has been rendered (so its HTML is part of the document). Post-rendering manipulations of the HTML could be done here. 26 | * This hook is the same one that SAPUI5 controls get after being rendered. 27 | * @memberOf testbed.CopyPaste 28 | */ 29 | onAfterRendering: function() { 30 | 31 | }, 32 | 33 | /** 34 | * Called when the Controller is destroyed. Use this one to free resources and finalize activities. 35 | * @memberOf testbed.CopyPaste 36 | */ 37 | // onExit: function() { 38 | // 39 | // } 40 | onChange:function(oEvent){ 41 | 42 | // 43 | 44 | }, 45 | 46 | 47 | }); 48 | 49 | -------------------------------------------------------------------------------- /WebContent/view/CopyPaste.view.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
39 | 40 | 41 | 42 | 43 |
44 |
45 | 46 |
47 | 48 | 49 | 50 | 51 |
52 |
53 | 54 |
55 | 56 | 57 |
58 |
59 | 60 |
61 | 62 | 63 | 64 | 65 |
66 |
67 | 68 |
69 | 70 | 71 | 72 | 73 |
74 |
75 | 76 |
77 | 78 | 79 | 80 | 81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 | 89 |
--------------------------------------------------------------------------------