IInfoPathDataImporter.Import(IPropertyBag, IEnumUnknown) 方法

定义

将数据导入当前表单。

public:
 void Import(Microsoft::Office::Interop::InfoPath::IPropertyBag ^ pPrintSettings, mshtml::IEnumUnknown ^ punkViewControls);
public void Import (Microsoft.Office.Interop.InfoPath.IPropertyBag pPrintSettings, mshtml.IEnumUnknown punkViewControls);
abstract member Import : Microsoft.Office.Interop.InfoPath.IPropertyBag * mshtml.IEnumUnknown -> unit
Public Sub Import (pPrintSettings As IPropertyBag, punkViewControls As IEnumUnknown)

参数

pPrintSettings
IPropertyBag

打印设置的集合。

punkViewControls
mshtml.IEnumUnknown

mshtml。IEnumUnknown 视图中的控件集合。

示例

在以下示例中,接口的 IInfoPathDataImporterImport 方法用于循环访问 mshtml。活动窗体视图中控件的 IInfoPathViewControl IEnumUnknown 集合。

导入例程是用于生成自定义数据导入程序的解决方案的主要部分。 Visual Studio 项目需要对 Microsoft Office InfoPath 2.0 类型库和 System.Windows.Forms 的引用,以及针对每个项的 Imports 语句以及 mshtml。实现 语句需要为自定义数据导入程序接口提供的方法(包括 IInfoPathDataImporterIInfoPathDataImporterFieldsIInfoPathViewControlIPropertyBag)生成签名。

注意:若要使用 .NET 类库生成自定义数据导入程序,请选中类属性编辑器的“编译”选项卡上的“注册 COM 互操作”复选框。

注意:若要调试自定义数据导入程序,请在 Visual Studio 中将“启动操作”设置为“启动外部程序”,然后浏览到位于驱动器>:\Program Files\Microsoft Office\Office12\的<INFOPATH.EXE。 此选项在类属性编辑器的“调试”选项卡上可用。

Imports Microsoft.Office.Interop.InfoPath
Imports System.Windows.Forms
Imports mshtml

&lt;ComClass(Class1.ClassId, Class1.InterfaceId, Class1.EventsId)&gt; Public Class Class1
   Implements Microsoft.Office.Interop.InfoPath.IInfoPathDataImporter
   Implements Microsoft.Office.Interop.InfoPath.IInfoPathDataImporterFields
   Implements Microsoft.Office.Interop.InfoPath.IInfoPathViewControl
   Implements Microsoft.Office.Interop.InfoPath.IPropertyBag

   Public Const ClassId As String = _
      "1FEB0DF8-E7F1-4b21-A9EE-B06D5FECC572"
   Public Const InterfaceId As String = _
      "9F9F685C-71A0-46ec-A7F9-A86AF8CBC2A8"
   Public Const EventsId As String = _
      "ED7C0C49-3F89-40a2-A50E-C59E8F682B08" 

Public Sub Import( _
   ByVal pPrintSettings As Microsoft.Office.Interop.InfoPath.IPropertyBag, _
   ByVal punkViewControls As mshtml.IEnumUnknown) _
   Implements Microsoft.Office.Interop.InfoPath.IInfoPathDataImporter.Import

   Dim pControl As IInfoPathViewControl
   Dim pUnk As Object
   Dim pcelt As UInt16 = 1
   Dim pceltFetched As UInt16 = 0

   Try
      'Gets first control in the view
      punkViewControls.RemoteNext(pcelt, pUnk, pceltFetched)

      Do While pUnk.ToString() &lt;&gt; "Nothing"
         pControl = pUnk
         MessageBox.Show(pControl.ControlType)
         'Gets next control in the view
         punkViewControls.RemoteNext(pcelt, pUnk, pceltFetched)
      Loop
   Catch e As Exception
      If e.Message = _
         "Object reference not set to an instance of an object." Then
         'Signals the end of the enumeration/controls in the view
      Else
         MessageBox.Show("Error: " &amp; e.ToString &amp; " " &amp; e.Message)
      End If
   End Try
End Sub

注解

可通过 接口使用以下 IPropertyBag 打印设置。

PageSize当前页大小,例如 A4、B4、Letter。
TopMargin当前视图的上边距。
BottomMargin当前视图的下边距。
LeftMargin当前视图的左边距。
RightMargin当前视图的右边距。
MarginUnitsType边距度量单位。

有关以编程方式将数据导入 InfoPath 表单的详细信息,请参阅 InfoPath 开发人员门户Microsoft Office 开发人员中心。

适用于