在C#中使用7zip提取.xlsx文件

我正在寻找一种方法来解压缩或解压缩.xls和.xlsx文件以编程方式在C#中。 如果我使用7zip来提取一个.xlsx文件,那么所有组成.xlsx的.xml文件都会有一个很好的突破。 我真的不知道从哪里开始尝试,Google-foo迄今为止失败了。 有什么build议?

谢谢

尝试执行以下操作:

using System; using System.IO; using System.IO.Compression; namespace ConsoleApplication { class Program { static void Main(string[] args) { string xlsPath = @"c:\example\YourFile.xlsx"; string extractPath = @"c:\example\extract"; string zipPath = Path.ChangeExtension(xlsPath, "zip"); if (File.Exists(zipPath)) { File.Delete(zipPath); } File.Copy(xlsPath, zipPath); ZipFile.ExtractToDirectory(zipPath, extractPath); } } } 

上面的控制台应用程序将文件复制到指定的位置,然后可以将其内容解压缩到任何您想要执行的操作。

你不应该需要7Zip这个。

正如Hack在他的评论中所说,如果你想修改/读取excel数据,那么有更好的方法去做这件事。

这里有几个可以使用excel文件的库:

  1. http://npoi.codeplex.com
  2. http://code.google.com/archive/p/excellibrary