运用Edraw为WPF应用程序嵌入Office文档的方法总结
2019獨角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
具體描述了運用Edraw Office Viewer Component為WPF應(yīng)用長須嵌入MS Word,Excel以及Power Point的方法。
打開Visual Studio,并創(chuàng)建一個新的WPF應(yīng)用程序。
右鍵單擊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應(yīng)用程序嵌入Word/Excel/PPT的方法總結(jié) src="http://image.evget.com/images/article/20121030021.jpg">
wpf的項目中將會出現(xiàn)一個新窗口。在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應(yīng)用程序嵌入Word/Excel/PPT的方法總結(jié) 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應(yīng)用程序嵌入Word/Excel/PPT的方法總結(jié) src="http://image.evget.com/images/article/20121030023.jpg">
Edraw Office Viewer Component組件就已經(jīng)被添加到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應(yīng)用程序嵌入Word/Excel/PPT的方法總結(jié) src="http://image.evget.com/images/article/20121030024.jpg">
這個AxEDofficeLib和EDOfficeLib將通過Visual Studio向?qū)П惶砑拥浇鉀Q方案中。
鍵入以下的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文件然后加入開放、保護、打印和關(guān)閉按鈕,如下圖所示:
<IMG style="BOX-SIZING: border-box; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; VERTICAL-ALIGN: middle; BORDER-TOP: 0px; BORDER-RIGHT: 0px" alt=運用Edraw為WPF應(yīng)用程序嵌入Word/Excel/PPT的方法總結(jié) 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選項。然后構(gòu)建并運行。
<IMG style="BOX-SIZING: border-box; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; VERTICAL-ALIGN: middle; BORDER-TOP: 0px; BORDER-RIGHT: 0px" alt=運用Edraw為WPF應(yīng)用程序嵌入Word/Excel/PPT的方法總結(jié) src="http://image.evget.com/images/article/20121030026.jpg">
Office Viewer Component組件支持所有版本MS Word。嵌入MS Excel或PowerPoint,Visio、項目到一個WPF應(yīng)用程序中,您不必改變?nèi)魏螙|西,只能調(diào)用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" ); } |
轉(zhuǎn)載于:https://my.oschina.net/u/1254945/blog/203179
總結(jié)
以上是生活随笔為你收集整理的运用Edraw为WPF应用程序嵌入Office文档的方法总结的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CRC-16校验C#代码
- 下一篇: RoboGuice入门