XLSX使用流式写入创建文件 [英] XLSX create file using streaming writes

查看:442
本文介绍了XLSX使用流式写入创建文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有特殊需要,我的执行环境受到内存限制的限制。

I have a specific need where my execution environment is limited by memory restrictions.

我需要从SQ服务器,写入和XLSX文件中读取大量行,然后将文件写入存储 - 所有内存分配大约512MB。

I need to read lots of rows from SQ server, write and XLSX file and then write the file to storage - all within around 512MB of memory allocation.

我的ORM允许我传输结果,我的存储系统允许我使用流保存。我的问题是,我似乎找不到使用流写入XLSX的方法,而没有将整个XLSX文件存储在内存中。

My ORM allows me to stream results, and my storage system allows me to save using a stream. My issue is that I cant seem to find a way to write to XLSX using a stream without having the whole XLSX file in memory.

我会假设像AWS这样的东西出现Azure这是一个常规要求。

I would have assume with the advent of things like AWS and Azure that this would be a regular requirement.

例如AWS Lambda的Azure功能 - 我想使用最低允许内存分配,例如128MB并且能够从SQL服务器读取一百万行,一次说1000行,然后构建XLSX文件,然后开始保存XLSX流,同时
读取下一行1000行,将新行写入XLSX流等。

For example Azure function of AWS Lambda - I would like to use the lowest allowable memory allocation e.g. 128MB and be able to read a million rows from SQL server say 1000 rows at a time and build the XLSX file and then starting saving the XLSX stream while reading the next 1000 rows, write the new rows to the XLSX stream etc.

重申一下 - 我可以从SQL服务器执行流,使用流保存到存储 - 只需写入XLSX即可。我现在正在使用EPPLus,因为除了编写原始xml之外,它似乎是最有效的库。

Just to reiterate - I can do the stream from SQL server, saving to storage using a stream - just the writing to XLSX is not there out the box. Im using EPPLus at the moment as this seems to be most efficient library other than writing raw xml.

我知道这是可能的,因为有一个节点包可以做到这一点,但我想坚持到c#!

I know this is possible as there is a node package that does this but I want to stick to c#!

谢谢!

推荐答案

嗨deanvanrooyen,

Hi deanvanrooyen,

我建议您参考以下文档。

I would suggest that you could refer the following document.

来自SQL Server的流媒体支持简化了编写应用程序的过程流数据,无需将数据完全加载到内存中,从而减少内存溢出异常。

https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sqlclient-streaming-support

祝你好运,

张龙


这篇关于XLSX使用流式写入创建文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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