我需要使用Microsoft.Office.Tools.Excel.Worksheet为工作表动态添加日期控件,可是我动态创建的worksheet是Microsoft.Office.Interop.Excel.Worksheet,无法实现我要的功能。网上找了下,发现有人把Microsoft.Office.Interop.Excel.Worksheet转化为Microsoft.Office.Tools.Excel.Worksheet,就可以了。代码如下:
1 // Gets the VSTO 2005 worksheet view for a worksheet.
2 // The Worksheet view is used to dynamically add controls to a worksheet.
3 private Microsoft.Office.Tools.Excel.Worksheet GetExtendedWorksheet(
4 ref Microsoft.Office.Interop.Excel.Worksheet nativeWorksheet)
5 {
6 // Get the IHostItemProvider instance.
7 Microsoft.VisualStudio.Tools.Applications.Runtime.IHostItemProvider hostItemProvider =
8 (Microsoft.VisualStudio.Tools.Applications.Runtime.IHostItemProvider)(
9 RuntimeCallback.GetService(typeof(Microsoft.VisualStudio.Tools.Applications.Runtime.IHostItemProvider)));
10
11 // Create the new worksheet and return it to calling function.
12 return new Microsoft.Office.Tools.Excel.Worksheet(hostItemProvider,
13 RuntimeCallback,
14 nativeWorksheet.CodeName,
15 Container,
16 nativeWorksheet.Name);
17 }
这段代码是在一个Microsoft.Office.Tools.Excel.Worksheet下的。可是贴到我这里用,就不好使了。
vsto 里头如何将Microsoft.Office.Interop.Excel.Worksheet转化为Microsoft.Office.Tools.Excel.Worksheet?