如何使用.xla文件中的代码,GZip如何压缩Excel VBA中的文件? [英] How can I GZip compress a file from Excel VBA using code in an .xla file only?

查看:222
本文介绍了如何使用.xla文件中的代码,GZip如何压缩Excel VBA中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够在Excel VBA函数中压缩文件。具体来说,我需要使用'deflate'算法。

I need to be able to GZip compress a file in an Excel VBA function. Specifically I need to be able to use the 'deflate' algorithm.

有没有办法做到这一点,而不必执行命令行应用程序?不需要依赖于外部工具,代码将更加强大。

Is there a way to do this without having to exec a command line application? With no dependency on external tools the code will be more robust.

理想情况下,代码将使用预先安装的VBA或COM库函数 - 我不想必须自己实现这个逻辑或安装DLL等。

Ideally the code would make use of pre-installed VBA or COM library functions - I don't want to have to implement this logic myself or install DLLs etc.

如果可能,我希望安装的功能就像将.xla添加到可用的Excel Add-宏。不需要DLL,EXE,注册表项等。

If possible, I want installation of the function to be as simple as adding a .xla to the available Excel Add-Ins. No DLLs, EXEs, registry entries etc. required.

编辑可以使用.NET GZipStream来执行此操作吗? >

Edit Can I make use of the .NET GZipStream to do this?

推荐答案

VBA(这是VB6的一个方言)对于这些应用程序来说很慢。我记得我曾经在VB6上执行了Shannon-Fano算法,而在C上,C版本快了10倍,即使被变成一个DLLMain,并且从那里调用,而不是在一个命令行可执行文件上。

VBA (which is really a dialect of VB6) is slow for these kind of applications. I remember I once implemented Shannon-Fano algorithm on VB6 and on C, the C version was about 10 times faster, even after being turned into a DLLMain and called from there rather than on a command-line executable.

有许多COM DLL提供压缩服务,包括开源和共享软件,其中一些实现GZIP的放气算法。只要从VBA代码中的一个DLL中调用一个函数就可以很简单,代表您进行压缩。

There are lots of COM DLLs that provide compression services, both open source and shareware, and some of them implement GZIP's deflate algorithm. It'd be really simple to just call one function from such a DLL from your VBA code to do the compression on your behalf.

我明白你不愿意使用某些东西在您的应用程序外部,尽管在这种情况下,您可能必须为性能而应用异常。

I understand your being reluctant on using something external to your application, though in this case you might have to apply an exception for performance's sake.

为了完全破坏您的乐趣,请检查ZIPFLDR.DLL文件windows\system32。你可能还想看看这些链接:

In an effort to completely spoil your fun, examine file ZIPFLDR.DLL on windows\system32. you may also like to take a look at these links:

  • This has an example of how to do what you want (zipping using windows built-in ZIP capabilities) from VB.NET, it shouldn't be much different from VBA or VB6: Transparent ZIP with DLL call
  • This one has a sample application on VB6 using windows built-in capabilities to zip (in ZIP rather than GZIP format, of course): Using Windows XP "Compressed Folder" shell extension to work with .zip files

通过谷歌搜索,您应该可以找到更多/更好的例子。

Found both thru googling, you should be able to find more/better examples.

这篇关于如何使用.xla文件中的代码,GZip如何压缩Excel VBA中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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