【问题标题】:Excel Interop Manipulate ScrollBar on WorksheetExcel 互操作操作工作表上的滚动条
【发布时间】:2010-06-22 16:39:02
【问题描述】:

我正在使用 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;
}

不过,一旦我获得了形状对象,我就无法确定正确的演员阵容,以便我可以调整它的属性。

有什么想法吗?

谢谢。

【问题讨论】:

    标签: c# excel com interop


    【解决方案1】:

    想通了。我应该迭代 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];
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2010-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-25
      • 2015-08-29
      相关资源
      最近更新 更多