Open and Read an Excel file in UWP application

匆匆过客 提交于 2019-12-13 03:41:58

问题


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!


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/53085479/open-and-read-an-excel-file-in-uwp-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!