Is it possible to generate an XLSX file from NS Su...
# suitescript
l
Is it possible to generate an XLSX file from NS Suitelet? Our developer says NS supports XLS only. Is that really the case?
a
NetSuite does not even support XLS when using SuiteScript, export search results to XLS is only natively supported in the UI as far as I know. You could technically use something like this: • https://github.com/SheetJS/sheetjs But that is a third party library.
l
Another option is to create a XML file readable by Excel same is done by exporting a saved search
Copy code
var fileContent = '<?xml version="1.0"?>'
        fileContent += '<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"';
        fileContent += ' xmlns:o="urn:schemas-microsoft-com:office:office"';
        fileContent += ' xmlns:x="urn:schemas-microsoft-com:office:excel"';
        fileContent += ' xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"';
        fileContent += ' xmlns:html="<http://www.w3.org/TR/REC-html40>">';
        fileContent += '<Worksheet ss:Name="Orders">';
        fileContent += '<Table>';
        //Header
        fileContent += '<Row>';
        fileContent += '<Cell><Data ss:Type="String">Order #</Data></Cell>';        
        fileContent += '</Row>';

        //Lines
        search.load({id: 'customsearch_fs_f16_fr_ups'}).run().each(function(result){

            
            result = JSON.parse(JSON.stringify(result));
            fileContent += '<Row>';
            fileContent += '<Cell><Data ss:Type="String">' + result.values['GROUP(tranid)'] + '</Data></Cell>';
            fileContent += '</Row>';

            return true;
        });
        
        fileContent += '</Table></Worksheet></Workbook>';

        var base64EncodedString = encode.convert({
            string: fileContent, 
            inputEncoding: encode.Encoding.UTF_8,
            outputEncoding: encode.Encoding.BASE_64
        });
        
        var excelFile = file.create({name: createFileName(), fileType: 'EXCEL', contents: base64EncodedString});
        excelFile.folder = [FOLDER_ID];
        excelFile.save();
l
This is very helpful. Thanks.