Alternative alternative

I started using the Excel interconnect builds provided by Microsoft for one of my C # applications. Everything is going well, but there seems to be no strong typing, and to be honest, it looks like I'm writing VBA code. Are there any alternative ways to interact with Excel with C # that will give a better OO experience? By the way, I am using VS2010 and .Net 4.0.

+6
source share
6 answers

Take a look at the EPPlus project on Codeplex:

http://epplus.codeplex.com/

I used this recently and it worked very well. (VS2010 and .Net4)

EPPlus is a .net library that reads and writes Excel 2007/2010 files using the Open Office Xml (xlsx) format.

Good example page: http://epplus.codeplex.com/wikipage?title=ContentSheetExample

+8
source

Depending on what you are trying to do, such as creating an XLSX document, you may use the Open XML SDK .

This is good for creating office documents; especially because it does not require the installation of an office for use.

It's free; nice clean API and supported by Microsoft. For instance:

public static void CreateNewWordDocument(string document) { using (WordprocessingDocument wordDoc = WordprocessingDocument.Create(document, WordprocessingDocumentType.Document)) { // Set the content of the document so that Word can open it. MainDocumentPart mainPart = wordDoc.AddMainDocumentPart(); SetMainDocumentContent(mainPart); } } 

Example from: http://msdn.microsoft.com/en-us/library/bb497758.aspx . There are examples for working with tables here .

If you are trying to interact directly with Excel (for example, automation of the user interface); Do not create a document then KeithS answer is how I go.

+1
source

NetOffice libraries are an alternative to the Office Primary Interop Assemblers (PIAs). NetOffice provides a version-independent set of interop libraries, so you can support all versions of Office in your application and include IntelliSense to show which methods are available within Office versions.

NetOffice also helps keep track of COM links a bit, which can sometimes be a pain in .NET / COM communication.

+1
source

What kind of interaction are you looking for? Just write? reading? Full control over all aspects?

There are many third-party libraries for processing Excel documents, especially if you stay in xlsx format (2007 or newer). If you just write things, there are even open source options you can look at (for example, Sourceforge has an Excel Writer ).

0
source

ExcelLibrary is excellent. http://code.google.com/p/excellibrary/

0
source

Automation OLE is a standard way for Windows to communicate except for the clipboard. Since not all languages ​​that need OLE have generics (or even strong static typing), the interface is necessarily very general.

If you just refuse to use OLE, you can use the Windows script host to navigate the GUI itself and get your data this way, or to clear the screen using the WinAPI DLL. You can also write or scroll ETL for Excel files based on document standards for XLS and XLSX files. Be that as it may, you can slice it, I think that the disadvantages of working with OLE are mitigated by the fact that you do not need to try to interact with Excel in any other way.

-2
source

Source: https://habr.com/ru/post/894675/


All Articles