Base solution for your next web application
Open Closed

Integrating SheetJs for Import Excel Data wihin JSON #1554


User avatar
0
jibbar created

For Import Excel Data using application tried to use <a class="postlink" href="https://github.com/SheetJS/js-xlsx">https://github.com/SheetJS/js-xlsx</a> What I did... First.... Added all necessary files in Web -> libs folder Second... Add ScriptPath public const string Sheetjs_xlsxcore = "~/libs/sheetjs/xlsx.core.min.js"; public const string Sheetjs_cpexcel = "~/libs/sheetjs/cpexcel.js"; public const string Sheetjs_ods = "~/libs/sheetjs/ods.js"; public const string Sheetjs_shim = "~/libs/sheetjs/shim.js"; public const string Sheetjs_xlsx = "~/libs/sheetjs/xlsx.js"; public const string Sheetjs_jszip = "~/libs/sheetjs/jszip.js"; Third.... Added in FrontEndBundleConfig ScriptPaths.Sheetjs_xlsxcore, ScriptPaths.Sheetjs_cpexcel, ScriptPaths.Sheetjs_ods, ScriptPaths.Sheetjs_xlsx, ScriptPaths.Sheetjs_shim, ScriptPaths.Sheetjs_jszip Forth... In CSHTML Modal add following code <div> <label>@L("SelectExcelFile")</label> <js-xlsx onread="vm.read()" onerror="vm.error()"></js-xlsx> <input type="file" accept=".xls,.xlsx" onchange="angular.element(this).scope().handleFile(this)"/> </div> Finally... In JS Controller add following function $scope.handleFile = function (e) { debugger var files = e.files; var i, f; for (i = 0, f = files[i]; i != files.length; ++i) { var reader = new FileReader(); var name = f.name; reader.onload = function (e) { var data = e.target.result;

                    var workbook = XLSX.read(data, { type: 'binary' });

                    /* DO SOMETHING WITH workbook HERE */
                };
                reader.readAsBinaryString(f);
            }
        };

Seeing error ReferenceError: XLSX is not defined var workbook = XLSX.read(data, { type: 'binary' });

Can you help to resolve this problem??

Why my added script are not loading??


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Is it possible that, you accidentally add it to FrondEndBundleConfig instead of AppBundleConfig or MpaBundleConfig ?

  • User Avatar
    0
    jibbar created

    Hi, Thanks A lot :)

    Now, From excel able to insert data in Grid. Will insert all the data in a table. Do I need to insert one by one? Is there any option to insert multiple rows in a Database Table?

    Thanks again.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    AspNet Zero does not have such a feature by default. You can try to use a library for that like EntityFramework.Extended but we didn't try that with AspNet Zero actually.

    This issue also might give you an idea <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/648">https://github.com/aspnetboilerplate/as ... issues/648</a>.