1

I have report created in MS Access 2013, which contains controls like labels, textboxes.
I want to access this controls in C# .net to check the width ,color properties of those controls.
I managed to find the report but I cannot find controls in that report.
How can I do that?
The code commented is the one which I have tried but does not got the result.

public bool CheckReport(AccessEntity acEntity, ACCESS.Application app) 
{ 
     try 
     { 
    ACCESS.AllReports report =(ACCESS.AllReports)app.CurrentProject.AllReports; 
    ACCESS.Controls objcntrls=null; 
    ACCESS.Section DetailSec; string strval;


    //ACCESS.Report r = (ACCESS.Report)app.CurrentProject.AllReports[acEntity.Data];
                //string strCap = (string)((dynamic)app.Reports[0]).Controls[acEntity.Rows].Caption;
                //ACCESS.Report r = (ACCESS.Report)app.CurrentProject.AllReports[0];
                //DetailSec = (ACCESS.Section)app.Reports[acEntity.Data].Section[0];
                //objcntrls = (ACCESS.Controls)app.Reports[acEntity.Data].Controls;

    string strwidth = objcntrls[acEntity.Field].Width.ToString();
                strval = RemoveSpace(acEntity.PropertyValue);
                    if (strwidth == strval)
                    {
                           return true;
                    }
      } 
             catch (System.Exception ex)
     { }
   return false;
        }
4

1 に答える 1

1

私の Access データベースには、幅が として定義されReport1ている という名前のラベルを持つ という名前のレポートが含まれています。次の C# コードを実行すると、表示されますLabel01"

レポート "Report1" のコントロール "Label0" の .Width 値は 1440 です

コードは

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AccessOleAuto
{
    class Program
    {
        static void Main(string[] args)
        {
            string reportName = "Report1";
            string controlName = "Label0";
            //
            // Note: This project has the following COM reference defined:
            //
            // Microsoft Access 14.0 Object Library
            //
            var accessApp = new Microsoft.Office.Interop.Access.Application();
            accessApp.OpenCurrentDatabase(@"C:\__tmp\testData.accdb");
            accessApp.DoCmd.OpenReport(reportName, Microsoft.Office.Interop.Access.AcView.acViewDesign);
            Microsoft.Office.Interop.Access.Report rpt = accessApp.Reports[reportName];

            int ctlWidth = rpt.Controls[controlName].Width;
            Console.WriteLine("control \"" + controlName + "\" in report \"" + reportName + "\" has a .Width value of " + ctlWidth);

            accessApp.DoCmd.Close(Microsoft.Office.Interop.Access.AcObjectType.acReport, reportName, Microsoft.Office.Interop.Access.AcCloseSave.acSaveNo);
            accessApp.Quit();

            // wait for a keypress before terminating
            Console.ReadKey();
        }
    }
}
于 2013-09-13T02:13:48.580 に答える