在UWP应用程序中打开和读取Excel文件 [英] Open and Read an Excel file in UWP application
问题描述
我开始学习应用程序开发,试图在UWP(通用Windows平台)中实现一个应用程序,该应用程序打开一个Excel文件向用户显示其数据,因为我有一个想法,那就是需要此功能.
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.
但是,遵循WPF(Windows Presentation Foundation)教程做同样的事情时,当我尝试通过代码打开Excel应用程序时遇到了异常,这可能是由于UWP设置上的某些设备不支持Excel( ?).
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 (?).
我想知道是否可以通过指定将我的应用程序仅部署到PC设备或平板电脑来解决此问题.如果无法执行此操作,那么UWP是一个不好的选择,无法创建当前处理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?
我应该迁移到WPF,还是UWP中有其他解决方案?
Should I migrate to WPF, or is there another solution in UWP?
谢谢您的帮助!
推荐答案
您不应切换到WPF.您应该忘记互操作,并使用 Open XML SDK .
You should not switch to WPF. You should forget about interop and use Open XML SDK.
互操作的缺点:
- 慢,因为它使用COM对象;
- 仅在Windows上工作;
- 要求在PC上安装excel;
- 很大程度上取决于excel,如果excel应用程序失败,您将遇到问题.而且它不再是excel问题,而是您自己的问题.而且由于Excel损坏,您的应用程序无法正常运行,因此您将不得不处理客户的问题.
OpenXML sdk的优点:
Advantages of OpenXML sdk:
- 快速,因为它可以直接处理xlsx文件;
- 在UWP,WPF,Winforms,Mono,.net Core,Xamarin Mac,Xamarin android,xamarin ios上工作;
- 不需要安装Excel应用;
- 具有不错的逆向工程工具(打开XML SDK工具)允许将任何xlsx转换为C#.
- 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文档可在此处.
OpenXML sdk documentation can be found here.
这篇关于在UWP应用程序中打开和读取Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!