C# 嵌入Excel、winform 嵌入Ecxel 、.net 嵌入 Excel、winform 打开 Excel、webBrowser打开Excel
最近开发 Winform 应用程序,涉及到 嵌入Excel 文件。技术验证也快结束,需要整理一下帮助文档了。。
用webBrowser控件 打开Excel 。
/// <summary>
///
/// </summary>
public static Microsoft.Office.Interop.Excel.Range range = null;
/// <summary>
///
/// </summary>
public static Microsoft.Office.Interop.Excel.Workbook wbb = null;
/// <summary>
/// 打开Excel文件
/// </summary>
/// <param name="filePath">Excel文件路径</param>
public void OpenExcel(string filePath)
{
strFilePathAndFileName = filePath;
//Object refmissing = System.Reflection.Missing.Value;
this.webBrowser1.Navigate(strFilePathAndFileName);
//object axWebBrowser = this.webBrowser1.ActiveXInstance;
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
Object refmissing = System.Reflection.Missing.Value;object[] args = new object[4];
args[0] = SHDocVw.OLECMDID.OLECMDID_HIDETOOLBARS;
args[1] = SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER;
args[2] = refmissing;
args[3] = refmissing;
object axWebBrowser = this.webBrowser1.ActiveXInstance;
axWebBrowser.GetType().InvokeMember("ExecWB", BindingFlags.InvokeMethod, null, axWebBrowser, args);
object oApplication = axWebBrowser.GetType().InvokeMember("Document", BindingFlags.GetProperty, null, axWebBrowser, null);
wbb = (Microsoft.Office.Interop.Excel.Workbook)oApplication;
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步