使用Interop名称空间删除优秀的行输出

时间:2022-09-28 17:18:29

I am searching a C# way to delete (empty) Excel-rows in a worksheet without using the Microsoft.Office.Interop.Excel namespace.

我正在搜索一个c#方法,在工作表中删除(空的)excelrows,而不使用Microsoft.Office.Interop。Excel名称空间。

Found many examples with the Interop namespace like C# and excel deleting rows . But is there a way to do it without third-party-tools - only with the .NET?

找到了许多使用Interop名称空间(如c#和excel删除行)的示例。但是,有没有一种方法可以在没有第三方工具的情况下做到这一点?

Thank you for your help!

谢谢你的帮助!

2 个解决方案

#1


1  

The options for working with Excel files relying only on standard .NET Framework namespaces is limited. Two possibilities come to mind. The first is "simplest", but only applicable if your main interest is in working with the content as a database. The second allows you to do pretty much "anything" with the Excel workbook, but the learning curve will be steep.

使用Excel文件的选项只依赖于标准的。net框架名称空间是有限的。我想到了两种可能性。第一个是“最简单的”,但只有当您的主要兴趣是将内容作为数据库使用时才适用。第二种方法允许您使用Excel工作簿做几乎所有的事情,但是学习曲线会非常陡峭。

Both of these approaches are suited for working in a server environment (unlike those that require presence of the Excel application) and do not require any licenses.

这两种方法都适合在服务器环境中工作(不像那些需要出现Excel应用程序的环境),并且不需要任何许可证。

  1. You can use an OLE DB connection (ACE OLE DB provider) to communicate with the contents of an Excel workbook. It allows connecting to individual worksheets as well as named ranges. Basic SQL functionality is supported.
  2. 您可以使用OLE DB连接(ACE OLE DB提供程序)与Excel工作簿的内容进行通信。它允许连接到各个工作表以及命名范围。支持基本的SQL功能。
  3. The file format of Excel 2007 and later versions is Office Open XML (OOXML). These files are "zip packages" containing the files (xml for the most part) that make up a workbook. So any standard tools that can work with Zip packages and XML can be used to open up an Excel workbook, edit the content, then close the workbook back up. In the .NET Framework, these would be the System.IO.Packaging (in WindowsBase.dll, usually needs to be referenced specifically) and System.XML namespaces.

    Excel 2007和以后版本的文件格式是Office Open XML (OOXML)。这些文件是“zip包”,包含构成工作簿的文件(大部分为xml)。因此,任何可以使用Zip包和XML的标准工具都可以用来打开Excel工作簿,编辑内容,然后关闭工作簿。在。net框架中,这些是System.IO。包装(WindowsBase。dll,通常需要特别引用)和系统。XML名称空间。

    The documentation for the file formats is the ECMA-376 standard (http://www.ecma-international.org/publications/standards/Ecma-376.htm). A useful on-line resource is openxmldeveloper.org.

    文件格式的文档是ECMA-376标准(http://www.ecma-international.org/publications/standards/Ecma-376.htm)。一个有用的在线资源是openxmldeveloper.org。

    Note that Microsoft also provides the Open XML SDK, a free download which can be distributed license-free with your solution. The Open XML SDK reduces the "learning curve" as it reduces the amount of knowledge you need about the OOXML file formats. I mention this for the sake of completeness, because I know how challenging trying to work directly with the file format is. Also, since the DLL is freely distributable and can be copied as part of your solution it might meet your requirements.

    注意,Microsoft还提供了Open XML SDK,这是一个免费下载,可以与您的解决方案一起免费分发。开放XML SDK减少了“学习曲线”,因为它减少了您需要的关于OOXML文件格式的知识。为了完整起见,我提到这一点,因为我知道直接使用文件格式是多么困难。而且,由于DLL是可*分发的,并且可以作为解决方案的一部分复制,所以它可能满足您的需求。

#2


0  

This * post may help - it discusses some libraries that can manipulate excel without needing Office installed. The question regards VB.NET but I believe the options discussed would work with C# too...

这篇*文章可能会有所帮助——它讨论了一些可以在不需要安装Office的情况下操作excel的库。这个问题关于VB。但我相信我们讨论的选项也适用于c#…

How to process excel file in vb.net without office installed

如何在vb.net中处理没有安装office的excel文件

#1


1  

The options for working with Excel files relying only on standard .NET Framework namespaces is limited. Two possibilities come to mind. The first is "simplest", but only applicable if your main interest is in working with the content as a database. The second allows you to do pretty much "anything" with the Excel workbook, but the learning curve will be steep.

使用Excel文件的选项只依赖于标准的。net框架名称空间是有限的。我想到了两种可能性。第一个是“最简单的”,但只有当您的主要兴趣是将内容作为数据库使用时才适用。第二种方法允许您使用Excel工作簿做几乎所有的事情,但是学习曲线会非常陡峭。

Both of these approaches are suited for working in a server environment (unlike those that require presence of the Excel application) and do not require any licenses.

这两种方法都适合在服务器环境中工作(不像那些需要出现Excel应用程序的环境),并且不需要任何许可证。

  1. You can use an OLE DB connection (ACE OLE DB provider) to communicate with the contents of an Excel workbook. It allows connecting to individual worksheets as well as named ranges. Basic SQL functionality is supported.
  2. 您可以使用OLE DB连接(ACE OLE DB提供程序)与Excel工作簿的内容进行通信。它允许连接到各个工作表以及命名范围。支持基本的SQL功能。
  3. The file format of Excel 2007 and later versions is Office Open XML (OOXML). These files are "zip packages" containing the files (xml for the most part) that make up a workbook. So any standard tools that can work with Zip packages and XML can be used to open up an Excel workbook, edit the content, then close the workbook back up. In the .NET Framework, these would be the System.IO.Packaging (in WindowsBase.dll, usually needs to be referenced specifically) and System.XML namespaces.

    Excel 2007和以后版本的文件格式是Office Open XML (OOXML)。这些文件是“zip包”,包含构成工作簿的文件(大部分为xml)。因此,任何可以使用Zip包和XML的标准工具都可以用来打开Excel工作簿,编辑内容,然后关闭工作簿。在。net框架中,这些是System.IO。包装(WindowsBase。dll,通常需要特别引用)和系统。XML名称空间。

    The documentation for the file formats is the ECMA-376 standard (http://www.ecma-international.org/publications/standards/Ecma-376.htm). A useful on-line resource is openxmldeveloper.org.

    文件格式的文档是ECMA-376标准(http://www.ecma-international.org/publications/standards/Ecma-376.htm)。一个有用的在线资源是openxmldeveloper.org。

    Note that Microsoft also provides the Open XML SDK, a free download which can be distributed license-free with your solution. The Open XML SDK reduces the "learning curve" as it reduces the amount of knowledge you need about the OOXML file formats. I mention this for the sake of completeness, because I know how challenging trying to work directly with the file format is. Also, since the DLL is freely distributable and can be copied as part of your solution it might meet your requirements.

    注意,Microsoft还提供了Open XML SDK,这是一个免费下载,可以与您的解决方案一起免费分发。开放XML SDK减少了“学习曲线”,因为它减少了您需要的关于OOXML文件格式的知识。为了完整起见,我提到这一点,因为我知道直接使用文件格式是多么困难。而且,由于DLL是可*分发的,并且可以作为解决方案的一部分复制,所以它可能满足您的需求。

#2


0  

This * post may help - it discusses some libraries that can manipulate excel without needing Office installed. The question regards VB.NET but I believe the options discussed would work with C# too...

这篇*文章可能会有所帮助——它讨论了一些可以在不需要安装Office的情况下操作excel的库。这个问题关于VB。但我相信我们讨论的选项也适用于c#…

How to process excel file in vb.net without office installed

如何在vb.net中处理没有安装office的excel文件