C# Dsoframer.ocx 如何在winform中嵌入Excel,内嵌Excel,word
2014-12-27 14:04
507 查看
如果你还不太清楚Dspframer.ocx怎么放到窗体上就看上一篇文章,里面详细介绍了是如何放到窗体上的。
链接:/article/6213064.html
第一步 创建新窗体
创建一个新窗体,放置一个panel容器控件,我们就是要将dsoframer.ocx放到panel里面。
第二步 下面是所有调用的方法,有步骤的。
m_axFramerControl.Titlebar = false;//是否显示excel标题栏
m_axFramerControl.Menubar = false;//是否显示excel的菜单栏
m_axFramerControl.Toolbars = false;//是否显示excel的工具栏
链接:/article/6213064.html
第一步 创建新窗体
创建一个新窗体,放置一个panel容器控件,我们就是要将dsoframer.ocx放到panel里面。
第二步 下面是所有调用的方法,有步骤的。
public partial class ExcelForm : DevExpress.XtraEditors.XtraForm { private AxDSOFramer.AxFramerControl m_axFramerControl = new AxDSOFramer.AxFramerControl(); public ExcelForm() { InitializeComponent(); } #region Excel 的加载 //总的加载Excel方法 private void Init(string _ExcelFilePath) { try { RegControl(); if (!File.Exists(_ExcelFilePath)) { XtraMessageBox.Show("文件不存在或未标识的文件格式!", "提示信息"); return; //throw new ApplicationException("文件不存在或未标识的文件格式!"); } AddAxFramerControl();//加载填充控件
m_axFramerControl.Titlebar = false;//是否显示excel标题栏
m_axFramerControl.Menubar = false;//是否显示excel的菜单栏
m_axFramerControl.Toolbars = false;//是否显示excel的工具栏
InitOfficeControl(_ExcelFilePath); } catch (Exception ex) { throw ex; } } //第二步:向panel填充AxFramerControl控件 private void AddAxFramerControl() { try { this.panelExcel.Controls.Add(m_axFramerControl); m_axFramerControl.Dock = DockStyle.Fill; } catch (Exception ex) { XtraMessageBox.Show(ex.Message); throw; } } //第一步:注册AxFramerControl public bool RegControl() { try { Assembly thisExe = Assembly.GetExecutingAssembly(); System.IO.Stream myS = thisExe.GetManifestResourceStream("NameSpaceName.dsoframer.ocx"); string sPath = System.AppDomain.CurrentDomain.BaseDirectory + @"\dsoframer.ocx"; ProcessStartInfo psi = new ProcessStartInfo("regsvr32", "/s " + sPath); Process.Start(psi); } catch (Exception ex) { MessageBox.Show(ex.Message); } return true; } //下面这个方法是dso打开文件时需要的一个参数,代表office文件类型 /// <summary> /// 根据后缀名得到打开方式 /// </summary> /// <param name="_sExten"></param> /// <returns></returns> private string LoadOpenFileType(string _sExten) { try { string sOpenType = ""; switch (_sExten.ToLower()) { case "xls": sOpenType = "Excel.Sheet"; break; case "doc": sOpenType = "Word.Document"; break; case "ppt": sOpenType = "PowerPoint.Show"; break; case "vsd": sOpenType = "Visio.Drawing"; break; default: sOpenType = "Word.Document"; break; } return sOpenType; } catch (Exception ex) { throw ex; } } /// <summary> /// 第三步:初始化office控件,加载Excel /// </summary> /// <param name="_sFilePath">本地文档路径</param> private void InitOfficeControl(string _sFilePath) { try { if (m_axFramerControl == null) { throw new ApplicationException("请先初始化office控件对象!"); } //this.m_axFramerControl.SetMenuDisplay(48); //这个方法很特别,一个组合菜单控制方法,我还没有找到参数的规律,有兴趣的朋友可以研究一下 string sExt = System.IO.Path.GetExtension(_sFilePath).Replace(".", ""); //this.m_axFramerControl.CreateNew(this.LoadOpenFileType(sExt));//创建新的文件 this.m_axFramerControl.Open(_sFilePath, false, this.LoadOpenFileType(sExt), "", "");//打开文件 //隐藏标题 this.m_axFramerControl.Titlebar = false; } catch (Exception ex) { throw ex; } } /// <summary> /// 关闭当前界面 /// </summary> public void Close() { try { if (this.m_axFramerControl != null) { this.m_axFramerControl.Close(); } } catch (Exception ex) { throw ex; } } //加载Excel 按钮 private void sbtnLoading_Click(object sender, EventArgs e) { Init(System.AppDomain.CurrentDomain.BaseDirectory + "excel\\项目汇总表.xls"); } //关闭 private void ExcelForm_FormClosing(object sender, FormClosingEventArgs e) { Close(); } #endregion }
相关文章推荐
- C# 如何在winform中嵌入Excel,内嵌Excel,word
- C# 如何在winform中嵌入Excel,内嵌Excel,word
- C#实现在Winform中嵌入Word和Excel
- C#实现在Winform中嵌入Word和Excel
- C#实现在Winform中嵌入Word和Excel
- Winform 嵌入Word Excel Powerpoint
- winform中嵌入Ppt、Word、Excel
- C#操作Word(二)——将Word文档嵌入到WinForm窗体中
- C#.net Winform 如何将窗体嵌入Panle中
- C# 使用嵌入显示Word,Excel,Pdf等
- C# dsoframer.ocx 控件注册
- C# dsoframer.ocx 控件注册
- C#中如何保存文本为Word文件或Excel文件 [Z]
- 将MS Word 嵌入C# Winform 中
- C# 如何将未安装字体从字体文件嵌入到Word文档
- c#使用DsoFramer实现word嵌入(winform版)
- C# 之 无法嵌入互操作类型(Word 或 Excel 操作)
- 在WinForm中嵌入Word和Excel
- 如何用C#提取Word、Excel等文件的文本(无需安装Office)
- C# 嵌入Excel、winform 嵌入Ecxel 、.net 嵌入 Excel、winform 打开 Excel、webBrowser打开Excel (转)