且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在uwp中打开office docs(word,power point,excel)。

更新时间:2023-01-29 22:53:46

嗨Arun Singh Rawat,


尝试第三个像
syncfusion
这样的派对图书馆可以完成一些任务但不是全部。


在通用Windows平台中,没有这样的API来读取/写入Microsoft文档。 


但是,您可以在其与指定文件关联的默认应用程序中打开任何文档文件。&nbsp ;使用下面的代码。

 private async void Button_Click(object sender,RoutedEventArgs e)
{
StorageFile file = null;

//要通过Picker打开文件,取消注释
// FileOpenPicker openPicker = new FileOpenPicker();
//openPicker.FileTypeFilter.Add(".docx");
// file = await openPicker.PickSingleFileAsync()

//从App的LocalFolder打开文件
var file = await ApplicationData.Current.LocalFolder.GetFileAsync(" Test。 DOCX&QUOT);

if(file!= null)
{
//启动检索到的文件
等待Windows.System.Launcher.LaunchFileAsync(file);
}
}


如果它解决了你的问题,请标记为答案。


谢谢。







Hi Want to create doc viewer in uwp but not get API for it. and not even getting third party sdk?

Any Suggestion?


Arun Singh Rawat | Mobility | UWP| WPF Skype: arun.rawat017 | Email:arun.rawat017@hotmail.com| arun.rawat017@gmail.com

Hi Arun Singh Rawat,

Try a third party library like syncfusion to do some of the tasks but not all.

In Universal Windows Platform there is no such API to read/write Microsoft documents. 

However you can open any document file in it's default app associated with the specified file. using the below code.

private async void Button_Click(object sender, RoutedEventArgs e)
{
    StorageFile file = null;

    //To Open file by Picker, Uncomment
    //FileOpenPicker openPicker = new FileOpenPicker();
    //openPicker.FileTypeFilter.Add(".docx");
    //file = await openPicker.PickSingleFileAsync()

    //To Open file from App's LocalFolder
    var file = await ApplicationData.Current.LocalFolder.GetFileAsync("Test.docx");

    if (file != null)
    {
        // Launch the retrieved file
        await Windows.System.Launcher.LaunchFileAsync(file);
    }
}

Mark as Answer if it solved your issue.

Thanks.