如何将表格导出为具有10000至40000行的Excel [英] how to export table as excel with 10000 to 40000 rows

查看:114
本文介绍了如何将表格导出为具有10000至40000行的Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用javascript(window.location.href= uri + base64(tableData))将html表导出为ex​​cel,这对于1500行工作正常.因为window.location.href具有一定的限制字符串长度.但是我需要导出40000行.

I am exporting html table as excel with javascript (window.location.href= uri + base64(tableData)) and this is working fine for 1500 rows. Because window.location.href has some limit string length. But i need to export 40000 number of rows.

我也尝试过使用 anchor标签href .但这也行不通.

And i have also tried with an anchor tag href. But it is also not working.

那么我们可以将数据部分分配给window.location.href还是有其他替代解决方案?

So can we assign the data partially to window.location.href or have any alternate solution?

推荐答案

我正在将编码后的字符串分配给window.location.href,那有大小限制.它适用于小数据.对于大数据,我们需要更改这种方式,我使用了Blob,谢谢@dandavis.在Blob中,数据没有限制,我们可以导出大量文件.我之前的代码是:

I was assigning the encoded string to window.location.href, thats has limitation of size. It works for small data. For large data, we need to change this way, and i used Blob's, Thanks @dandavis. In Blob's there is no limit of data and we can export large size of files. My previous code is :

var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
window.location.href = uri + base64(format(template, ctx))

现在通过传递的blob更新的代码是:

And now updated code with passing blob is:

var blob = b64toBlob(str, "application/vnd.ms-excel");
var blobUrl = URL.createObjectURL(blob);
window.location = blobUrl;

b64toBlob函数在这里:

And the b64toBlob function is here:

function b64toBlob(b64Data, contentType, sliceSize) {
    contentType = contentType || '';
    sliceSize = sliceSize || 512;

    var byteCharacters = atob(b64Data);
    var byteArrays = [];

    for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
        var slice = byteCharacters.slice(offset, offset + sliceSize);

        var byteNumbers = new Array(slice.length);
        for (var i = 0; i < slice.length; i++) {
            byteNumbers[i] = slice.charCodeAt(i);
        }

        var byteArray = new Uint8Array(byteNumbers);

        byteArrays.push(byteArray);
    }

    var blob = new Blob(byteArrays, {type: contentType});
    return blob;
}

它的工作非常好.我已经测试了55,000行.谢谢大家

And its working very fine. I have tested with 55,000 number of rows. Thanks all

这篇关于如何将表格导出为具有10000至40000行的Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆