Get Filename of imported File (Designer Components)

Posted by: m.holland-moritz on 10 February 2022, 12:34 am EST

    • Post Options:
    • Link

    Posted 10 February 2022, 12:34 am EST

    Hey guys.

    Is there a way to get the filename of imported files? No matter which import is used?

    I am using the file import from the designer ribbon. Can i add some lines of code to this functions?

    Best regards

    Maik

  • Posted 13 February 2022, 3:45 pm EST

    Hi,

    We are sorry but spreadJS does not provide the fileName information However you could override the importExcel_online method and write your own logic to import the file have total control on the file object. Please refer to the following code snippet and attached sample that explains the same.

    
    GC.Spread.Sheets.Designer.FileMenuHandler.importExcel_online = function(){
       let input = document.createElement('input');
      input.type = 'file';
      input.onchange = _ => {
    
                let files =   Array.from(input.files);
                console.log(files[0].name);
    /*import the excel file*/
                    var excelIo = new GC.Spread.Excel.IO();
                  excelIo.open(
        files[0],
        function (json) {
          var workbookObj = json;
          spread.fromJSON(workbookObj, {
            doNotRecalculateAfterLoad: true
          });
          designer.setData("FileMenu_show",false)
        },
        function (e) {
          /* process error*/
          alert(e.errorMessage);
        }
      );
    }
      input.click();
      
    }
    
    

    sample: https://jscodemine.grapecity.com/share/-j4zDlF6u0y7gI2G4J5sww/

    Regards,

    Avinash

  • Posted 24 February 2022, 10:07 pm EST

    Hey Avinash,

    Thanks! this helps for Excel files, but i also would need it for every kind of file like the ssjson or csv.

    Is there somewhere a documentation about the FileMenuHandler or something i am missing? I can’t find it on your page.

    Regards,

    Maik

  • Posted 27 February 2022, 7:29 pm EST

    Hi Maik,

    Currently, there is no documentation available for FileMenuHandler as it is used internally by SpreadJS. However, you can follow the similar steps as defined above to get the file names for every kind of import.

    Please refer to the sample that I have created for you and let us know if you face any further issues: https://jscodemine.grapecity.com/share/Y1TG-BitlEKp_igfp4pWtg/

    Regards

    Ankit

  • Posted 10 April 2022, 10:05 pm EST

    Hey Ankit,

    Thanks for the help! That worked totally fine for my case.

    Regards

    Maik

  • Posted 13 April 2022, 7:23 pm EST

    Hey,

    and sorry for reopen this post, but i investigated that i can’t use the options, which are provided by the Designer Components.

    Is there a way to check which options are active in the excel import and which separator the client has set for the csv?

    Regards

    Maik

  • Posted 18 April 2022, 4:52 pm EST

    Hi Maik,

    Sorry for the delayed response. We have tested at our end and it seems to be working fine at our end. Some designer options might be unavailable if the sheet is protected and it depends on the protection options applied. Try unlocking the sheet to access the Designer Component Options.

    You can check if the sheet is protected using sheet.options.isProtected and the protection options using sheet.options.protectionOptions.allowDeleteRow and so on.

    Protect WorkSheet and Lock Cells: https://www.grapecity.com/spreadjs/docs/latest/online/celllock.html

    If the issue still persists for you, please share a working sample so that we can investigate it at our end and assist you accordingly.

    Regards

    Ankit

    purejs.zip

  • Posted 1 May 2022, 8:10 pm EST - Updated 3 October 2022, 12:18 am EST

    Hey Ankit,

    i think you misunderstood me. The options i mean are in the attached pictures



    I can’t really use them since for example in csv the code is setting it to a fixed one:

    spread.getSheet(spread.getActiveSheetIndex()).setCsv(0, 0, res, "\r", ",");
    

    And i am investigating, that i can load xlsx first and load a csv afterwards they get mixed instead of creating a completly new workbook.

    How can i fix that?

    Regards

    Maik

  • Posted 3 May 2022, 9:19 pm EST

    Hi Maik,

    You need to get the status of checkboxes selected and the input parameters from the corresponding elements, and then set it to fromJSON/setCsv methods when importing the files.

    I have also fixed the issue when loading csv files after xlsx file and vice versa. It will no longer get mixed.

    Please refer to the following sample that I have created for you: https://jscodemine.grapecity.com/share/2J2jgAlL30_vGH5pvVHEAQ/

    Please let us know if you need further assistance on this query? We would be happy to help you.

    Regards

    Ankit

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels