Import Excel data to Database using AngularJS in ASP.Net MVC

Last Reply 10 months ago By dharmendr

Posted 10 months ago

Hi,

How to import excel data to sql in Angularjs in asp.net mvc

For import excel data to sql i am using below code.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Index</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.8/angular.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/danialfarid-angular-file-upload/12.2.13/ng-file-upload.min.js"></script>
    <script type="text/javascript">
        var app = angular.module("myApp", ['ngFileUpload']);
        app.controller("myCntrl", ['$scope', '$http', 'myService', function ($scope, $http, myService) {
            $scope.UploadFiles = function (files) {
                $scope.SelectedFiles = files;
            };
 
            $scope.AddUpdateEmployee = function () {
                var formData = new FormData();
                var files = $scope.SelectedFiles;
                if (files != undefined) {
                    for (var i = 0; i < files.length; i++) {
                        formData.append(files[i].name, files[i]);
                    }
                }
                var details = {};
                details.Name = $scope.Name;
                formData.append("details", JSON.stringify(details));
                var getData = myService.AddSt(formData);
                getData.then(function (tc) {
                    alert(tc);
                });
            }
        } ]);
        app.service("myService", function ($http) {
            this.AddSt = function (employee) {
                var response = $.ajax({
                    url: '/Home/AddState',
                    type: "POST",
                    contentType: false,
                    processData: false,
                    data: employee
                });
                return response;
            }
        });
    </script>
</head>
<body ng-app="myApp" ng-controller="myCntrl">
    <div class="container">
        <div>
            <div id="wrapper" class="clearfix">
                <form name="userForm">
                <div class="form-horizontal">
                    <div class="form-row">
                        <div class="col-md-4">
                            <label for="COI_Name">
                                Upload a file
                            </label>
                            <input type="file" ngf-select="UploadFiles($files)" />
                        </div>
                    </div>
                    <div>
                    </div>
                    <div class="form-group">
                    </div>
                    <div class="form-group" style="width: 120%; text-align: center; padding: 10px;">
                        <div class="col-md-offset-2 col-md-5">
                            <p>
                                <button ng-model="IsVisible" ng-click="AddUpdateEmployee()">
                                    <span class="glyphicon glyphicon-ok"></span>Submitt
                                </button>
                            </p>
                        </div>
                    </div>
                </div>
                </form>
            </div>
        </div>
    </div>
</body>
</html>

I don't know what to do to save excel records to sql

could you please help me

 

This question does not have replies that have been liked.