Я использую старый элемент управления DsoFramer для встраивания экземпляра Excel в мою форму.Это прекрасно работает с Excel 2000, 2003 и 2007.
Come 2010, однако я думаю, что он ведет себя немного по-другому.Теперь я получаю подсказку о макросах, которая блокирует мой пользовательский интерфейс до тех пор, пока пользователь не переключит фокус на экземпляр Excel в фоновом режиме и не нажмет ОК.

Я знаю, что Microsoft неМы больше не поддерживаем использование этого элемента управления, но, к сожалению, мы пока не можем его заменить.Так что я ищу наши способы попробовать и отключить этот диалог.Я пытался использовать перечисление MsoAutomationSecurity.msoAutomationSecurityForceDisable , но это, похоже, не имеет значения.Если я открываю файл напрямую через код, то он в порядке и не запрашивает, но вызов axFramer.Open () всегда вызывает запрос.Кто-нибудь знает способ обойти это?
Код для воспроизведения этой проблемы в простом приложении WinForm (вам нужно заменить путь к файлу, содержащему макросы).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Excel;
using System.Diagnostics;
namespace WindowsFormsApplication1
{
public partial class Form1 : System.Windows.Forms.Form
{
private AxDSOFramer.AxFramerControl axFramer;
public Form1()
{
// Kill any Excel processes first so they don't interfere with our tests
KillExcelProcesses();
InitializeComponent();
try
{
CreateAndAddFramer();
string file = @"c:\temp\date_6490.xls";
// Create a new Excel Application. For the purpose of the test lets ensure it's visible too.
Application excelApp = new Application() { Visible = true, DisplayAlerts = false };
// Set the Excel security to Forcefully disable all macros.
excelApp.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable;
// Open the file. This is because it needs to be open before trying with the DsoFramer
// control. It also demonstrates that excel opens fine without prompting for any
// macro support.
Workbook selectedBook = excelApp.Workbooks.Open(file);
// Open the file in the framer. This will now prompt to enable macros.
axFramer.Open(file, true, null, null, null);
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.ToString());
KillExcelProcesses();
}
}
/// <summary>
/// Creates a DsoFramer and adds to the form.
/// </summary>
private void CreateAndAddFramer()
{
// Create an axFramer control
this.axFramer = new AxDSOFramer.AxFramerControl();
// Initialize the axFamer
((System.ComponentModel.ISupportInitialize)(this.axFramer)).BeginInit();
// Update the name of the framer (bug in framer)
this.axFramer.Name = "framer_" + Guid.NewGuid().ToString();
this.axFramer.ResetText();
// Dock the framer and add to the form
this.axFramer.Dock = System.Windows.Forms.DockStyle.Fill;
this.Controls.Add(axFramer);
((System.ComponentModel.ISupportInitialize)(this.axFramer)).EndInit();
}
/// <summary>
/// Kills all excel processes.
/// </summary>
private static void KillExcelProcesses()
{
// Kill all instances of Excel
foreach (Process p in Process.GetProcessesByName("excel"))
{
p.Kill();
}
}
}
}