我一直在网上搜索,但找不到将单元格变成组合框(或有时似乎被称为下拉菜单)的方法?我正在使用 Microsoft.Office.Interop.Excel 14.0 版(运行时版本 2.0.50727)。
问问题
5867 次
2 回答
5
这是我试图实现的解决方案:
Excel.Application App = null;
Excel.Workbook Book = null;
Excel.Worksheet Sheet = null;
object Missing = System.Reflection.Missing.Value;
try
{
App = new Excel.Application();
Book = App.Workbooks.Add();
Sheet = (Excel.Worksheet) Book.Worksheets[1];
Excel.Range Range = Sheet.get_Range("B2", "B2");
Range.Validation.Add(Excel.XlDVType.xlValidateList
, Excel.XlDVAlertStyle.xlValidAlertStop
, Excel.XlFormatConditionOperator.xlBetween
, "Item1,Item2,Item3"
, Type.Missing);
Range.Validation.InCellDropdown = true;
Range.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.FromArgb(255, 217, 217, 0));
App.Visible = true;
}
finally
{
Base.ReleaseObject(Sheet);
Base.ReleaseObject(Book);
Base.ReleaseObject(App);
}
于 2013-10-31T19:18:34.907 回答
1
好吧,肯定存在一个 Excel 可托管的 .Net 组合框。帖子中的示例代码有用吗?
http://msdn.microsoft.com/en-us/library/ee259140(v=vs.100).aspx
Private Sub ExcelRangeAddComboBox()
Dim ComboBox1 As Microsoft.Office.Tools.Excel. _
Controls.ComboBox = Me.Controls.AddComboBox( _
Me.Range("A1", "B1"), "ComboBox1")
ComboBox1.Items.Add("First Item")
ComboBox1.Items.Add("Second Item")
ComboBox1.SelectedIndex = 0
End Sub
如果您不熟悉开发加载项,以下内容可能有助于您入门: http: //msdn.microsoft.com/en-us/library/cc442981 (v=vs.100).aspx
这里的视频非常有帮助:http: //msdn.microsoft.com/en-US/office/hh133459
于 2013-10-21T21:58:03.547 回答