gpt4 book ai didi

c# - 有没有一种格式可以存储比 Excel 更小的表格数据?

转载 作者:行者123 更新时间:2023-12-02 02:18:22 24 4
gpt4 key购买 nike

我已经尝试过保存在文本文件中(显然它需要更多空间,因为它没有像 Excel 那样定制为保存表格)。我还尝试保留序列化数据(c#,仅供引用)。这两种情况都没有任何好处。

最佳答案

由于大多数“表格”数据都是文本,因此在保存之前对其进行压缩将获得巨大 yield (以 GZip 和 BsonWriter 为例):

public static byte[] Compress(object entity)
{
using (var stream = new MemoryStream())
{
using (var zipStream = new GZipStream(stream, CompressionLevel.Optimal))
{
using (var writer = new BsonWriter(zipStream))
{
var serializer = new JsonSerializer();
serializer.Serialize(writer, entity);
}
}

return stream.ToArray();
}
}

** 更新 **

Protobuf 是 far superior to both XmlSerializerBinaryFormatter就序列化实体的大小和速度而言。尝试在压缩之前使用它来序列化您的实体:

public static byte[] Compress(object entity)
{
using (var stream = new MemoryStream())
{
using (var zipStream = new GZipStream(stream, CompressionLevel.Optimal))
{
Serializer.Serialize(stream, entity);
}

return stream.ToArray();
}
}

关于c# - 有没有一种格式可以存储比 Excel 更小的表格数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12840215/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com