Open and Read an Excel file in UWP application

2019-08-28 21:31发布

I'm starting to learn application development trying to implement an application in UWP (Universal Windows Platform) that opens an Excel file to show its data to the user, since I have an idea that would require this feature.

However, following a WPF (Windows Presentation Foundation) tutorial to do the same thing I've run into an exception when I try to open the Excel application through code, probably due to some devices on the UWP set not supporting Excel (?).

I'm wondering if there is some way of fixing this problem by specifying that my application will be deployed only to a PC device or a tablet. If there is no way of doing this, UWP is a bad option to create programs that deal with Excel files at the moment?

Should I migrate to WPF, or is there another solution in UWP?

Thank you for the help!

2条回答
孤傲高冷的网名
2楼-- · 2019-08-28 21:53

You can use EPPlus package which support UWP Nuget Package. It is super Excel spreadsheet helper for UWP Application

查看更多
趁早两清
3楼-- · 2019-08-28 21:57

You should not switch to WPF. You should forget about interop and use Open XML SDK.

Disadvantages of interop:

  • Slow, since it uses COM objects;
  • Works only on windows;
  • Requires excel to be installed on the PC;
  • Largely depends on excel and if excel app fails you will have problems. And it's not excel problem anymore, but your own problem. And you will have to deal with your customer's issues since your app cannot work properly because of broken excel.

Advantages of OpenXML sdk:

  • Fast, since it works directly with xlsx file;
  • Works on UWP, WPF, Winforms, Mono, .net Core, Xamarin Mac, Xamarin android, xamarin ios;
  • Does not require Excel app to be installed;
  • Has nice reverse engineering tool (Open XML SDK Tools) which allows to turn any xlsx into C#.

OpenXML sdk documentation can be found here.

查看更多
登录 后发表回答