资源简介
使用 WebBrowser 控件,在 C# WINFORM 中嵌入EXCEL, (WORD 同理)。
注:此方法无法使用 OFFICE 菜单,但可以使用工具栏。

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Office=Microsoft.Office.Core;
using Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Runtime.InteropServices.ComTypes;
namespace embeddedExcel
{
public partial class ExcelWrapper : UserControl {
[DllImport(“ole32.dll“)]
static extern int GetRunningobjectTable(uint reservedout IRunningobjectTable pprot);
[DllImport(“ole32.dll“)]
static extern int CreateBindCtx(uint reservedout IBindCtx pctx);
#region Fields
private readonly Missing MISS=Missing.Value;
/// Contains a reference to the hosting application.
private Microsoft.Office.Interop.Excel.Application m_XlApplication=null;
/// Contains a reference to the active workbook.
private Workbook m_Workbook=null;
private bool m_ToolBarVisible=false;
private Office.CommandBar m_StandardCommandBar=null;
/// Contains the path to the workbook file.
private string m_ExcelFileName=string.Empty;
#endregion Fields
#region Construction
public ExcelWrapper() {
InitializeComponent();
}
#endregion Construction
#region Properties
[Browsable(false)]
public Workbook Workbook {
get { return m_Workbook; }
}
[Browsable(true)Category(“Appearance“)]
public bool ToolBarVisible {
get { return m_ToolBarVisible; }
set {
if(m_ToolBarVisible==value) return;
m_ToolBarVisible=value;
if(m_XlApplication!=null) OnToolBarVisibleChanged();
}
}
#endregion Properties
#region Events
private void OnToolBarVisibleChanged() {
try {
m_StandardCommandBar.Visible=m_ToolBarVisible;
} catch { }
}
private void OnWebBrowserExcelNavigated(object senderWebBrowserNavigatedEventArgs e) {
AttachApplication();
}
//private void OnOpenClick(Office.CommandBarButton Ctrlref bool Cancel) {
// if(this.OpenExcelFileDialog.ShowDialog()==DialogResult.OK) {
// OpenFile(OpenExcelFileDialog.FileName);
// }
//}
//void OnNewClick(Office.CommandBarButton Ctrlref bool Cancel) {
// throw new Exception(“The method or operation is not implemented.“);
//}
#endregion Events
#region Methods
public void OpenFile(string filename) {
// Check the file exists
if(!System.IO.File.Exists(filename)) throw new Exception();
m_ExcelFileName=filename;
// Load the workbook in the WebBrowser control
this.WebBrowserExcel.Navigate(filenamefalse);
}
public Workbook GetActiveWorkbook(string xlfile) {
IRunningobjectTable prot=null;
IEnumMoniker pmonkenum=null;
try {
IntPtr pfetched=IntPtr.Zero;
// Query the running object table (ROT)
if(GetRunningobjectTable(0out prot)!=0||prot==null) return null;
prot.EnumRunning(out pmonken
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2006-10-01 16:14 bin\
目录 0 2006-10-01 16:14 bin\Release\
文件 24576 2006-10-01 16:14 bin\Release\em
文件 28160 2006-10-01 16:14 bin\Release\em
文件 5632 2005-09-23 06:56 bin\Release\em
目录 0 2006-10-01 16:09 Properties\
文件 1286 2006-10-01 15:54 Properties\AssemblyInfo.cs
目录 0 2006-10-01 16:09 Properties\DataSources\
文件 601 2006-10-01 16:09 Properties\DataSources\ExcelWrapper.datasource
文件 2464 2006-10-01 15:54 Properties\Resources.Designer.cs
文件 5612 2006-10-01 15:54 Properties\Resources.resx
文件 1005 2006-10-01 15:54 Properties\Settings.Designer.cs
文件 249 2006-10-01 15:54 Properties\Settings.settings
文件 4602 2006-10-01 16:09 em
文件 914 2006-10-01 15:54 em
文件 5338 2006-10-01 16:11 ExcelWrapper.cs
文件 2566 2006-10-01 16:00 ExcelWrapper.designer.cs
文件 6021 2006-10-01 10:05 ExcelWrapper.resx
文件 642 2006-10-01 16:14 Form1.cs
文件 4014 2006-10-01 16:14 Form1.Designer.cs
文件 6017 2006-10-01 16:14 Form1.resx
文件 399 2006-10-01 15:54 Program.cs
相关资源
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
- 基于c#的实验室设备管理系统621530
- C# 使用ListView控件实现图片浏览器(源
- C#简单窗体聊天程序
- C#指纹识别系统程序 报告
- c# 高校档案信息管理系统
- c#向word文件插入图片
- C#左侧导航菜单(动态生成)
评论
共有 条评论