Edraw Office Viewer component教程(三):将MS Word、Excel、PowerPoint嵌入到WPF应用程序中
来源:互联网 发布:2016年度网络热词 编辑:程序博客网 时间:2024/05/16 11:22
如何将Word、Excel、PowerPoint嵌入WPF应用程序?大部分人应该都记得可以将Excel图表嵌入到Word文档中的OLE技术,但该技术并不支持所有的Microsoft Office文档。它不支持表单中的多个MS Word实例。而Edraw office viewer component对于开发人员可以说是最简单的可以将Word文档、Excel工作表、PowerPoint演示文稿嵌入到WPF应用程序中的解决方案。
本文将演示如何逐步嵌入MS Word到wpf应用程序中。如果你没有officeviewer.ocx文件,请先安装。在组件安装文件夹中,你还可以找到wpf示例项目。
打开Visual Studio并创建一个新的WPF应用程序。
右键单击WpfApplication1解决方案。然后单击“Add”菜单并选择“User Control...”。
wpf项目中将会增加一个新的窗体。
选择“User Control”项。不是“User Control(WPF)”项。
双击解决方案面板中的UserControl1.CS。
打开“工具箱”面板,然后单击菜单中的“ Choose Items...”。
在弹出的“Choose Toolbox Items”对话框中,选择“Edraw Office Viewer Component”,然后单击“确定”。
现在,Edraw Office Viewer Component已添加到工具箱的“常规”选项卡中。在UserControl窗体中拖动它。
通过Visual Studio将AxEDofficeLib和EDOfficeLib添加到该解决方案中。
输入打开word文档的C#代码,并保护word文档的修改如下所示:
输入打开word文档的C#代码,并保护word文档的修改如下所示:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WpfApplication1
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public void Open()
{
axEDOffice1.OpenFileDialog();
}
public void Protect()
{
if (axEDOffice1.GetCurrentProgID() == "Word.Application")
{
axEDOffice1.ProtectDoc(2);
}
}
public void Print()
{
axEDOffice1.PrintPreview();
}
public void Close()
{
axEDOffice1.ExitOfficeApp();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WpfApplication1
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public void Open()
{
axEDOffice1.OpenFileDialog();
}
public void Protect()
{
if (axEDOffice1.GetCurrentProgID() == "Word.Application")
{
axEDOffice1.ProtectDoc(2);
}
}
public void Print()
{
axEDOffice1.PrintPreview();
}
public void Close()
{
axEDOffice1.ExitOfficeApp();
}
}
}
最后,你需要为UserControl编写主机窗口。切换到Windows1.xaml文件,然后添加打开、保护、打印和关闭的按钮,如图所示。
添加以下c#代码来关联office component。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Open_Click(object sender, RoutedEventArgs e)
{
_host.Open();
}
private void Protect_Click(object sender, RoutedEventArgs e)
{
_host.Protect();
}
private void Print_Click(object sender, RoutedEventArgs e)
{
_host.Print();
}
private void Close_Click(object sender, RoutedEventArgs e)
{
_host.Close();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Open_Click(object sender, RoutedEventArgs e)
{
_host.Open();
}
private void Protect_Click(object sender, RoutedEventArgs e)
{
_host.Protect();
}
private void Print_Click(object sender, RoutedEventArgs e)
{
_host.Print();
}
private void Close_Click(object sender, RoutedEventArgs e)
{
_host.Close();
}
}
}
打开配置管理器。将Active Solution平台更改为x86选项。然后建立并运行。
Office Viewer component支持所有版本的MS Word。要将MS Excel或PowerPoint Visio、Project嵌入到WPF应用程序中,你只需要调用Open方法,如下所示:
public void Open()
{
//axEDOffice1.OpenFileDialog();
axEDOffice1.Open(sPath, "Word.Application");
axEDOffice1.Open(sPath, "Excel.Application");
axEDOffice1.Open(sPath, "PowerPoint.Application");
axEDOffice1.Open(sPath, "Visio.Application");
axEDOffice1.Open(sPath, "MSProject.Application");
}
{
//axEDOffice1.OpenFileDialog();
axEDOffice1.Open(sPath, "Word.Application");
axEDOffice1.Open(sPath, "Excel.Application");
axEDOffice1.Open(sPath, "PowerPoint.Application");
axEDOffice1.Open(sPath, "Visio.Application");
axEDOffice1.Open(sPath, "MSProject.Application");
}
以上就是本次教程的全部内容,接下来会有更多相关教程,敬请关注!您也可以在评论者留下你的经验和建议。
0 0
- Edraw Office Viewer component教程(三):将MS Word、Excel、PowerPoint嵌入到WPF应用程序中
- Edraw Office Viewer component教程(二):将Excel嵌入VB 6并使之自动化
- Edraw Office Viewer component教程(一):将Microsoft Word嵌入VB.NET并使之自动化
- 将Edraw Office Viewer Component添加到基于应用程序的对话框中
- Edraw Office Viewer Component
- 运用Edraw为WPF应用程序嵌入Office文档的方法总结
- 运用Edraw为WPF应用程序嵌入Office文档的方法总结
- Winform 嵌入Word Excel Powerpoint
- 将office文档(word,excel,powerpoint)转换为pdf
- 将office文档(word,excel,powerpoint)转换为pdf
- MFC在应用程序中嵌入MS Word
- 将MS Word 嵌入C# Winform 中
- C# 将excel表格嵌入到Word中
- 运行word, excel,powerpoint应用程序
- WPF:将Office文档、任意类型文件嵌入到EXE可执行文件中
- vb教程:将Edraw Office ActiveX控件添加到Visual Basic 6.0项目
- 使用MFC在应用程序中嵌入MS Word
- Office宏 PowerPoint提取文字到Word
- gson解析json
- 移动app如何进行自动化和探索性测试
- PSVR开发小结
- GCD使用三部曲之:基本用法
- 排序算法-09-排序1 排序 (25分)-第一部分
- Edraw Office Viewer component教程(三):将MS Word、Excel、PowerPoint嵌入到WPF应用程序中
- linux syslog
- 基于神经网络的智能RC小车(Python+OpenCV)
- C#Label、CheckBox等背景色设为透明
- text-dependent speech emotion recognition 相关文献
- SQL Server 数据库IN子句和EXISTS子句转换
- HBase学习总结:HBase的工作原理
- eclipse项目导入IntelliJ IDEA :Error:(1, 1) java: 非法字符: '\ufeff'
- Promise对象的基本使用