mobileFX WebKitX ActiveX
WebKitX JavaScript Externs~-_namespace / WriteArrayToFile Method
Absolute path and file name to save.
UInt8Array containing the bytes to save.
In This Topic
    WriteArrayToFile Method
    In This Topic
    WriteArrayToFile saves a UInt8Array (byte array) to a file.

     

    Syntax
    var value; // Type: boolean
    
    // Parameters
    var FileName; // Type:  string
    var Array; // Type:  UInt8Array
    
    value = WriteArrayToFile(FileName, Array);
    function WriteArrayToFile( 
       FileName : string,
       Array : UInt8Array
    ) : boolean;

    Parameters

    FileName
    Absolute path and file name to save.
    Array
    UInt8Array containing the bytes to save.
    Example
    <html>
        <head>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.26.0/polyfill.js"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/exceljs/4.1.1/exceljs.js"></script>
            <head>
            <body></body>
            <script>
    
            window.onload = function()
            {
                // Create workbook & add worksheet
                        
                const workbook = new ExcelJS.Workbook();
                const worksheet = workbook.addWorksheet('ExampleSheet');
    
                // Add column headers
                        
                worksheet.columns = [{ header: 'Package', key: 'package_name' },
                                        { header: 'Author', key: 'author_name' }];
    
                // Add row using key mapping to columns
               
    
                worksheet.addRow({ package_name: "ABC", author_name: "Author 1" },
                                    { package_name: "XYZ", author_name: "Author 2" });
    
                // Add rows as Array values
    
    
                worksheet.addRow(["BCD", "Author Name 3"]);
    
                // Add rows using both the above of rows
    
    
                const rows = [["FGH", "Author Name 4"], { package_name: "PQR", author_name: "Author 5" }];
                worksheet.addRows(rows);
               
                // Save workbook to file
               
                workbook.xlsx.writeBuffer().then(data =>
                {
                    const blob = new Blob([data], { type: 'application/octet-stream' });
                    WriteBlobToFile("test1.xlsx", blob);
                });
               
                // Alternative - using WriteUint8ArrayToFile
                               
                workbook.xlsx.writeBuffer().then(data =>
                {
                    const blob = new Blob([data], { type: 'application/octet-stream' });
                    blob.arrayBuffer().then(arrayBuffer => 
                                            WriteUint8ArrayToFile("test2.xlsx", new Uint8Array(arrayBuffer)));          
                }); 
               
                // Loading
                               
                var bytes = ReadUint8ArrayFromFile("test.xlsx");
               
                var blob = ReadBlobFromFile("test.xlsx");
                               
            }
            </script>
    </html>
    Remarks

    Saves a UInt8Array (byte array) to a file. For more details please read Working with Blob and Uint8Array

    Browser Compatibility
    80