Open-XML-SDK | Open XML SDK by Microsoft | SDK library
kandi X-RAY | Open-XML-SDK Summary
kandi X-RAY | Open-XML-SDK Summary
Open XML SDK by Microsoft
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Open-XML-SDK
Open-XML-SDK Key Features
Open-XML-SDK Examples and Code Snippets
Community Discussions
Trending Discussions on Open-XML-SDK
QUESTION
I'm trying to figure out, how to use F# to read data from an existing Excel file. I found this (rather old) question, but have problems running it: Reading cell contents in an Excel file with F# and Open XML SDK
It seems that either the compiler or the SDK (or both) changed with regard to this line:
...ANSWER
Answered 2020-May-13 at 13:44You could use EPPlus for that. Here is a very simple example in a script:
QUESTION
I'm trying to export a List
or IEnumerable
to an Excel file using the library Open XML of Microsoft.
Library: https://github.com/OfficeDev/Open-XML-SDK
Example of similar request: https://www.codeproject.com/Articles/692121/Csharp-Export-data-to-Excel-using-OpenXML-librarie
The example above works pretty fine but have a lot of code between (As far works neat, but I searching for an optimization)
But the documentation of this library does not extend (or hasn't many examples), and the examples that I saw around about how to export data to Excel it's using a DataTable
or Dataset
; so, they make the conversation from the List
to DataTable
to export the DataTable
. And that seems pretty complex way to something that other libraries resolve easier.
So, if someone has a sort of example of how to make the export quickly and generic, it will be appreciated.
...ANSWER
Answered 2020-May-07 at 21:53FYI, here is my implementation, using the code of @mikesknowledgebase (http://www.mikesknowledgebase.com -- The Webpage doesn't work... but to give the credits at least :D)
Post with all information here
So, I used it for .Net Core 2.2; and the intention is to use the method to export a List
to Excel
.
The final result (In the simplest example):
QUESTION
I'm currently using COM Interop in .NET to export the contents of a DataTable to Excel. It's a method I've been using for years, but the problem is that COM is sketchy and throws random, intermittent, untraceable exceptions. This hasn't been a huge issue, since it's always just been code on a machine dedicated for this purpose and the exceptions are pretty rare, but recently I wrote a front-end for a data warehouse and I've got 200+ users on it, and the problem has (as you would expect) grown exponentially.
The problem is finding a method that does what COM does without the problems that come with COM. Namely, creating an Excel file in-memory (no writing to disk) that is a new workbook, so that when the user hits "Save" for the first time, it will ask them where they want to save the file and what they want to call it.
I know I can export a DataTable to an Excel file using OpenXML: Export DataTable to Excel with Open Xml SDK in c#
And I know I can create an OpenXML Excel object in-memory without writing to a file on disk: How to create Excel file using OpenXML without creating a local file?
The problem is the last step: Opening that in-memory file in Excel (without using COM)
Getting this to work would be my ideal option.
Now, I would prefer not to write to a file, but that isn't a deal breaker if there are no other options, so as a backup option I've also considered using OpenXML to create an Excel Template, and opening the Template (using Process.Start).
The problem with that approach is that some users have reported that Templates sometimes open as xltx files in Edit mode by default, instead of opening as new xlsx files: https://answers.microsoft.com/en-us/office/forum/office_2007-customize/is-there-a-way-to-get-my-excel-template-xltx-file/ab36cd4d-f6b0-46e0-8f15-533a4acb357f?page=1
This would be an even bigger issue than the random errors I'm getting from using COM.
Any ideas are appreciated.
EDIT - These are the COM errors I get:
Cannot create ActiveX component.
COM target does not implement IDispatch.
Exception from HRESULT: 0x800AC472
Select method of Range class failed
Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))
The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))
The remote procedure call failed. (Exception from HRESULT: 0x800706BE)
Unable to cast COM object of type 'System.__ComObject' to interface type 'System.Collections.IEnumerable'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{496B0ABE-CDEE-11D3-88E8-00902754C43A}' failed due to the following error: 'The requested object does not exist. (Exception from HRESULT: 0x80010114)' and the COM component does not support IDispatch::Invoke calls for DISPID_NEWENUM.
Unable to get the Add property of the Workbooks class
Activate method of Workbook class failed
I've received 107 errors over the course of a few months, but I've gotten more lately since I updated the feature to attach to any existing instance of Excel that the user might already have open instead of creating a new one. Before, when I was always creating a new Excel instance each time, the errors were much more rare (and were largely solved by making Excel invisible while I did the work behind the scenes).
...ANSWER
Answered 2020-Apr-16 at 20:01This is a suggestion more than an answer. Consider trying to save the file to a temporary location and set it to Read-Only in the file system. The would force your users to do a SaveAs rather than a Save. Then use the Excel command line options (apparently /n
is best) to open the XLSX file as if it were a template.
Those command line options are located here:Excel Command Line Options
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Open-XML-SDK
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page