我正在使用Microsoft.Office.Interop.Excel COM接口打开一个excel工作表。我正在尝试调整嵌入到工作表中的滚动条的“最大”值。我可以找到滚动条,其中包含以下内容:
app = new Excel.Application();
wb = app.Workbooks.Open(
Path.GetDirectoryName(Application.ExecutablePath)+@"\template.xls",
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
for (int sheetNum = 1; sheetNum < wb.Sheets.Count + 1; sheetNum++)
{
ws = (Excel.Worksheet)wb.Sheets[sheetNum];
if (ws.Name == "Graphic")
{
foreach (Excel.Shape ctrl in ws.Shapes)
{
if (ctrl.Name == "graphicScroll")
{
// how do a cast this??
break;
}
}
}
break;
}
一旦我得到了形状对象,我无法找出合适的角色,以便我可以调整它的属性。
有什么想法吗?
感谢。
答案 0 :(得分:0)
想出来。我应该迭代OLEObjects并转换为Microsoft.Vbe.Interop.Forms
Excel.OLEObjects objects = (Excel.OLEObjects) ws.OLEObjects(Type.Missing);
foreach (Excel.OLEObject ctrl in objects)
{
if (ctrl.Name == "graphicScroll")
{
((Microsoft.Vbe.Interop.Forms.ScrollBar) ctrl.Object).Max = readsAtDeltaMinKeys[readsAtDeltaMin.Count-1];
}
}