1

So I'm writing a cross platform app that will run on Mac, Linux, and Windows. I need a library that can export to a .xlsx without having to have Excel installed on the host computer. Also, I will need to include simple formulas in the spreadsheet. I'm brand new to .NET so I don't know which version of .NET Core the library should be compatible with in order for the app to be cross platform capable. I've heard of ClosedXML which looks perfect for what I'm trying to do. But absolutely no where on the NuGet page nor on their GitHub page does it state whether it's compatible with .NET Core or cross-platform, etc. Please help! I've written whole programs before only to find out I've written it with the completely wrong tools.

4
  • 1
    "What's the best library for task ABC?" questions are on the list of "what questions really don't fit StackOverflow's Q&A model" (because SO doesn't like opinion-based questions). Be ready to have your question closed. Click the help link ((?) in the upper right of the page) and then the link about what kinds of question don't work on SO. To try something out, Write a minimalist program (that creates, for example, an empty, named spreadsheet) using a library and see if it works. Debug it on Windows and then try it on other platforms.
    – Flydog57
    Commented Dec 16, 2020 at 0:14
  • Have a look at this Article. The guy evaluated several libraries in the context of .NET core. There are probably also some that support writing excel files.
    – AdrAs
    Commented Dec 16, 2020 at 0:41
  • @Flydog57 Thanks for the tip! Although my question asks if anyone has suggestions for a good library, I'm also subtly asking if the library I found is functional in a cross-platform use-case. If someone can tell me a surefire way to check if a library is cross platform compatible, that would be ideal! Then I won't ever have to create a SO post like this again. There has to be a better way than simply randomly adding Nuget packages until I stumble upon one that is both cross platform and non-dependent on excel. Commented Dec 16, 2020 at 1:44
  • @AdrAs Thanks for the article! This is good, as I have done plenty of google searches but haven't found some of the libraries mentioned in the article. I'll check it out. Commented Dec 16, 2020 at 1:46

2 Answers 2

2

You can try my SwiftExcel library. Besides that it is cross platform (if you install it into your .NET Core application), this library is also very efficient as it writes directly to the file. For example you can write 100k rows in few seconds without any memory usage.

Here is a simple example of usage:

using (var ew = new ExcelWriter("C:\\temp\\test.xlsx"))
{
    for (var row = 1; row <= 10; row++)
    {
        for (var col = 1; col <= 5; col++)
        {
            ew.Write($"row:{row}-col:{col}", col, row);
        }
    }
}

You can also use some basic formulas like Count, Max, Sum or Average. Here is an example from the same GitHub page:

using (var ew = new ExcelWriter("C:\\temp\\test.xlsx"))
{
    for (var row = 1; row <= 20; row++)
    {
        ew.Write(row.ToString(), 1, row, DataType.Number);
    }

    ew.WriteFormula(FormulaType.Average, 1, 22, 1, 1, 20);
    ew.WriteFormula(FormulaType.Count, 1, 23, 1, 1, 20);
    ew.WriteFormula(FormulaType.Max, 1, 24, 1, 1, 20);
    ew.WriteFormula(FormulaType.Sum, 1, 25, 1, 1, 20);
}
0

When confronted with this, I start with a simple proof of concept application. In your case that would be: Create an .xls file with just a single entry. With such a simple project, it's easy to try out several libraries quickly.

Start by creating a .NET core project, then import a nuget package and see if it still compiles. If it does, great, try and let it run on android instead of windows. If it still runs, great. Now you can start writing the first lines of code where you use the library. Just try to create a .xls with a simple entry. Try it on windows, android. If that works test out if the library has all the functionality you need.

If all that passes you've got something that's probably going to work.

Divide and conquer, always go step by step.

Not the answer you're looking for? Browse other questions tagged or ask your own question.