Michael McCauley
Michael McCauley

Reputation: 933

Create Excel File in NetSuite's SuiteScript

I'm currently trying to generate an Excel file for an e-mail attachment using NetSuite's JavaScript-based SuiteScript APIs. Now, I have no problem generating a CSV file. That's easy. But an Excel file is what is requested and I'm having nothing but trouble with it. The line of code that always gives me trouble is the following:

var dataFile = nlapiCreateFile(dataFilename, "EXCEL", fileData);

It always causes the script to crash. So far I've tried simple CSV style data formatting and I've also tried to utilize an XML format to the data, but neither method works. In the meantime, we're going to just kick out a CSV file and have them convert it to XLS, but if anyone knows the NetSuite stuff well enough to help, it would be greatly appreciated. If anyone would like to see the code for the XML generation, I can add that.

EDIT: Here's a sample of the XML generated for the test file...

<?xml version="1.0"?>
<ss:Workbook xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
    <ss:Worksheet ss:Name="Sheet1">
        <ss:Table>
            <ss:Row>
                <ss:Cell>
                    <ss:Data ss:Type="String">Booth Number</ss:Data>
                </ss:Cell>
                <ss:Cell>
                    <ss:Data ss:Type="String">Company</ss:Data>
                </ss:Cell>
                <ss:Cell>
                    <ss:Data ss:Type="String">Address</ss:Data>
                </ss:Cell>
                <ss:Cell>
                    <ss:Data ss:Type="String">City</ss:Data>
                </ss:Cell>
                <ss:Cell>
                    <ss:Data ss:Type="String">State</ss:Data>
                </ss:Cell>
                <ss:Cell>
                    <ss:Data ss:Type="String">Zip</ss:Data>
                </ss:Cell>
                <ss:Cell>
                    <ss:Data ss:Type="String">Country</ss:Data>
                </ss:Cell>
                <ss:Cell>
                    <ss:Data ss:Type="String">Telephone</ss:Data>
                </ss:Cell>
                <ss:Cell>
                    <ss:Data ss:Type="String">Fax</ss:Data>
                </ss:Cell>
                <ss:Cell>
                    <ss:Data ss:Type="String">Contact Name</ss:Data>
                </ss:Cell>
                <ss:Cell>
                    <ss:Data ss:Type="String">Email</ss:Data>
                </ss:Cell>
                <ss:Cell>
                    <ss:Data ss:Type="String">Booth Length</ss:Data>
                </ss:Cell>
                <ss:Cell>
                    <ss:Data ss:Type="String">Booth Width</ss:Data>
                </ss:Cell>
            </ss:Row>
        </ss:Table>
    </ss:Worksheet>
</ss:Workbook>

Upvotes: 0

Views: 7112

Answers (2)

user3389842
user3389842

Reputation: 21

Try this:

var xlsFile = nlapiCreateFile('filename.xls', 'EXCEL', nlapiEncrypt(xmlString, 'base64'));
xlsFile.setFolder(folderID);

var fileID = nlapiSubmitFile(xlsFile);  

Upvotes: 2

Saqib
Saqib

Reputation: 2480

If the file type is set to EXCEL than base64 encode your data before passing it to nlapiCreateFile.

Other option is that provide plain text CSV data and pass the type as CSV. CSV files can be opened by MS Excel

Upvotes: 0

Related Questions