代码之家  ›  专栏  ›  技术社区  ›  Mark

Excel Interop操作工作表上的滚动条

  •  0
  • Mark  · 技术社区  · 15 年前

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

    但是,一旦我得到了形状对象,我就无法找到合适的强制转换,因此我无法调整它的属性。

    有什么想法吗?

    谢谢。

    1 回复  |  直到 15 年前
        1
  •  0
  •   Mark    15 年前

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