原創|其它|編輯:郝浩|2012-10-30 12:02:04.000|閱讀 2318 次
概述:具體描述了運用Edraw Office Viewer Component為WPF應用長須嵌入MS Word,Excel以及Power Point的方法。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
具體描述了運用Edraw Office Viewer Component為WPF應用長須嵌入MS Word,Excel以及Power Point的方法。
打開Visual Studio,并創建一個新的WPF應用程序。
右鍵單擊WpfApplication1 Solution。 然后單擊Add添加菜單,并點擊User Control…
wpf的項目中將會出現一個新窗口。在Solution面板雙擊UserControl1.CS。
打開Toolbox面板,然后單擊Choose Items…。
在彈出的Choose Toolbox Items選擇工具箱項目對話框中,選擇Edraw Office Viewer Component組件然后單擊Ok。
Edraw Office Viewer Component組件就已經被添加到Toolbox工具箱中添加工具箱的General選項卡中。之后將它拖放到UserControl窗口。
這個AxEDofficeLib和EDOfficeLib將通過Visual Studio向導被添加到解決方案中。
鍵入以下的c#代碼,打開一個word文檔,并保護該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(); } } }
最后,您需要為UserControl編寫一個主機窗口。切換到Windows1.xaml文件然后加入開放、保護、打印和關閉按鈕,如下圖所示:
添加如下代碼:
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(); } } }
打開Configuration Manager配置管理器。改變 Active解決方案平臺為x86選項。然后構建并運行。
Office Viewer Component組件支持所有版本MS Word。嵌入MS Excel或PowerPoint,Visio、項目到一個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"); }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:翻譯