日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

运用Edraw为WPF应用程序嵌入Office文档的方法总结

發布時間:2024/4/13 asp.net 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 运用Edraw为WPF应用程序嵌入Office文档的方法总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

具體描述了運用Edraw Office Viewer Component為WPF應用長須嵌入MS Word,Excel以及Power Point的方法。

打開Visual Studio,并創建一個新的WPF應用程序。

右鍵單擊WpfApplication1 Solution。 然后單擊Add添加菜單,并點擊User Control…

<IMG style="BOX-SIZING: border-box; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; VERTICAL-ALIGN: middle; BORDER-TOP: 0px; BORDER-RIGHT: 0px" alt=運用Edraw為WPF應用程序嵌入Word/Excel/PPT的方法總結 src="http://image.evget.com/images/article/20121030021.jpg">

wpf的項目中將會出現一個新窗口。在Solution面板雙擊UserControl1.CS。

打開Toolbox面板,然后單擊Choose Items…。

<IMG style="BOX-SIZING: border-box; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; VERTICAL-ALIGN: middle; BORDER-TOP: 0px; BORDER-RIGHT: 0px" alt=運用Edraw為WPF應用程序嵌入Word/Excel/PPT的方法總結 src="http://image.evget.com/images/article/20121030022.jpg">

在彈出的Choose Toolbox Items選擇工具箱項目對話框中,選擇Edraw Office Viewer Component組件然后單擊Ok。

<IMG style="BOX-SIZING: border-box; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; VERTICAL-ALIGN: middle; BORDER-TOP: 0px; BORDER-RIGHT: 0px" alt=運用Edraw為WPF應用程序嵌入Word/Excel/PPT的方法總結 src="http://image.evget.com/images/article/20121030023.jpg">

Edraw Office Viewer Component組件就已經被添加到Toolbox工具箱中添加工具箱的General選項卡中。之后將它拖放到UserControl窗口。

<IMG style="BOX-SIZING: border-box; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; VERTICAL-ALIGN: middle; BORDER-TOP: 0px; BORDER-RIGHT: 0px" alt=運用Edraw為WPF應用程序嵌入Word/Excel/PPT的方法總結 src="http://image.evget.com/images/article/20121030024.jpg">

這個AxEDofficeLib和EDOfficeLib將通過Visual Studio向導被添加到解決方案中。

鍵入以下的c#代碼,打開一個word文檔,并保護該Word文檔不被修改:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 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文件然后加入開放、保護、打印和關閉按鈕,如下圖所示:

<IMG style="BOX-SIZING: border-box; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; VERTICAL-ALIGN: middle; BORDER-TOP: 0px; BORDER-RIGHT: 0px" alt=運用Edraw為WPF應用程序嵌入Word/Excel/PPT的方法總結 src="http://image.evget.com/images/article/20121030025.jpg">

添加如下代碼:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 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選項。然后構建并運行。

<IMG style="BOX-SIZING: border-box; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; VERTICAL-ALIGN: middle; BORDER-TOP: 0px; BORDER-RIGHT: 0px" alt=運用Edraw為WPF應用程序嵌入Word/Excel/PPT的方法總結 src="http://image.evget.com/images/article/20121030026.jpg">

Office Viewer Component組件支持所有版本MS Word。嵌入MS Excel或PowerPoint,Visio、項目到一個WPF應用程序中,您不必改變任何東西,只能調用Open方法,如下所示:

1 2 3 4 5 6 7 8 9 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" ); }

轉載于:https://my.oschina.net/u/1254945/blog/203179

總結

以上是生活随笔為你收集整理的运用Edraw为WPF应用程序嵌入Office文档的方法总结的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。