简体   繁体   English

Excel Interop在工作表上操作ScrollBar

[英]Excel Interop Manipulate ScrollBar on Worksheet

I'm opening an excel worksheet using the Microsoft.Office.Interop.Excel COM interface. 我正在使用Microsoft.Office.Interop.Excel COM界面打开excel工作表。 I'm trying to adjust the "maximum" value of a scroll bar embedded into a worksheet. 我正在尝试调整嵌入到工作表中的滚动条的“最大值”值。 I can find the scroll bar with the following: 我可以找到以下滚动条:

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;
}

Once I get the shape object though, I can not figure out the proper cast so that I can adjust it's properties. 但是,一旦获得了形状对象,便无法确定正确的投射,因此无法调整其属性。

Any ideas? 有任何想法吗?

Thanks. 谢谢。

Figured it out. 弄清楚了。 I should be iterating the OLEObjects and casting to Microsoft.Vbe.Interop.Forms 我应该迭代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];
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM