在 Microsoft PowerApps 中扫描条形码Scan a barcode in Microsoft PowerApps

通过创建应用并在具有摄像头的设备(如手机)上运行应用,可扫描多种类型的条形码。Scan several types of barcodes by creating an app and running it on a device, such as a phone, that has a camera. 条形码的等效数字显示在“标签”控件中,可以将此数据上载到各种数据源中。The numerical equivalent of the barcode appears in a Label control, and you can upload that data to a variety of data sources.

如果不熟悉 PowerApps,请参阅入门If you're unfamiliar with PowerApps, see Get started.

已知的限制Known limitations

  • 条形码应至少 1 英寸(2.5 厘米)高、1.5 英寸(4 厘米)宽。Barcodes should be at least 1" (2.5cm) high and 1.5" (4cm) wide.
  • 若要使用手机扫描条形码,请纵向拿着手机,慢慢将手机移动到距离条形码 7 英寸(18 厘米)到 10 英寸(25 厘米)的位置。To scan barcodes by using a phone, hold it in portrait orientation, and slowly move it from 7" (18cm) to 10" (25cm) away from the barcode.
  • 长条形码类型(如包含 15 个或更多字符的 I2of5)可能会提供截断或其他不正确的结果,尤其是在条形码打印不清晰的情况下。Long barcode types (such as I2of5, which can have 15 or more characters) can give truncated or otherwise incorrect results, especially if the barcode isn't printed clearly.
  • 对于 iPhone 和 Android 设备,可指定条形码控件的 Height 属性,但固定的纵横比决定其宽度。For iPhones and Android devices, you can specify the Height property of the Barcode control, but a fixed aspect ratio determines its width.
  • 可能需要将条形码控件的 Scanrate 属性设置为 35 或更低。You might need to set the Scanrate property of the Barcode control to 35 or less.
  • 若要延迟耗尽运行 iOS 的设备上的内存,请将条形码控件的 Height 属性设置为 700(或更低),将 Scanrate 属性设置为 30To delay running out of memory on devices that are running iOS, set the Height property of the Barcode control to 700 (or lower) and the Scanrate property to 30.
  • 如果设备耗尽内存且应用冻结,请重启应用。If the device runs out of memory and the app freezes, restart the app.

创建空白应用Create a blank app

  1. 注册 PowerApps,然后执行下列操作之一Sign up for PowerApps, and then do either of the following:

    • 在具有摄像头的设备上的浏览器中打开 PowerAppsOpen PowerApps in a browser on a device that has a camera.
    • 在具有摄像头的设备上从 Windows 应用商店安装 PowerAppsInstall PowerApps from the Windows Store on a device that has a camera. 打开 PowerApps、登录,然后单击或点击“文件”菜单(沿左边缘)上的“新建”。Open PowerApps, sign in, and then click or tap New on the File menu (along the left edge).
  2. 在“从空白画布或模板开始”下方,单击或点击“空白应用”磁贴中的“手机布局”。Under Start with a blank canvas or template, click or tap Phone layout in the Blank app tile.

    从头开始创建应用

  3. 如果尚未使用过 PowerApps,可通过查看简介教程来熟悉此应用的关键部分(也可以单击或点击“跳过”)。If you haven't used PowerApps before, get familiar with key areas of the app by taking the intro tour (or click or tap Skip).

    打开快速教程屏幕

    注意:稍后可以通过单击或点击右上角附近的问号图标,然后单击或点击“获取简介教程”,随时获取此教程。Note: You can always take the tour later by clicking or tapping the question-mark icon near the upper-right corner and then clicking or tapping Take the intro tour.

添加条形码控件Add a Barcode control

  1. 在“插入”选项卡上,单击或点击“媒体”,然后单击或点击“条形码”。On the Insert tab, click or tap Media, and then click or tap Barcode.

    添加条形码扫描器

  2. 确保选中条形码控件,方法是确认选择框(具有调整控件大小的图柄)将其环绕。Ensure that the Barcode control is selected by confirming that a selection box (with handles to resize the control) surrounds it.

    选择框

  3. 在“开始”选项卡上,单击或点击 Barcode1,然后在“重命名”下键入或粘贴 MyScannerOn the Home tab, click or tap Barcode1, and then type or paste MyScanner under Rename.

    提示:添加的第一个条形码控件默认命名为 Barcode1Tip: The first Barcode control that you add is named Barcode1 by default. 如果将其删除并添加另一个条形码控件,此控件默认命名为 Barcode2If you delete that control and add another Barcode control, it will be named Barcode2 by default. 通过手动重命名控件,可确保公式通过正确的名称引用该控件。By manually renaming a control, you ensure that formulas will refer to the control by its correct name.

    重命名条形码控件

添加文本输入控件Add a Text input control

  1. 在“插入”选项卡上,单击或点击“文本”,然后单击或点击“文本输入”。On the Insert tab, click or tap Text, and then click or tap Text input.

    如果“插入”选项卡未显示,请最大化 PowerApps 窗口。If the Insert tab doesn't appear, maximize your PowerApps window.

    添加文本输入控件

  2. 向下拖动文本输入控件周围的选择框(而非调整图柄大小),直到它在 MyScanner 下显示。Drag the selection box (not the resize handles) around the Text input control down until it appears below MyScanner.

    带有选择框的标签

  3. 使文本输入控件仍处于选中状态,确保 Default 出现在属性列表中,然后在编辑栏中键入或粘贴 MyScanner.TextWith the Text input control still selected, ensure that Default appears in the properties list, and then type or paste MyScanner.Text in the formula bar.

    “标签”控件的“Text”属性

更改条形码类型Change the barcode type

  1. 在“插入”选项卡上,单击或点击“控件”,然后单击或点击“下拉列表”。On the Insert tab, click or tap Controls, and then click or tap Drop down.

    添加下拉列表

  2. 移动下拉列表控件,使其显示在屏幕上其他控件的下方。Move the Drop down control so that it appears below the other controls on the screen.

    移动下拉列表

  3. 使下拉列表控件仍处于选中状态,确保属性列表显示 Items,然后在编辑栏中键入或粘贴此文本字符串:With the Drop down control still selected, ensure that the properties list shows Items, and then type or paste this string of text in the formula bar:
    [Codabar, Code128, Code39, Ean, I2of5, Upc][Codabar, Code128, Code39, Ean, I2of5, Upc]

    设置下拉列表的 Items 属性

  4. 在“开始”选项卡上,将下拉列表控件重命名为 ChooseTypeOn the Home tab, rename the Drop down control to ChooseType.

    重命名下拉列表

  5. 单击或点击 MyScanner 将其选中,确保属性列表显示 BarcodeType,然后在编辑栏中键入或粘贴此文本字符串:Click or tap MyScanner to select it, ensure that the properties list shows BarcodeType, and then type or paste this string of text in the formula bar:
    ChooseType.Selected.ValueChooseType.Selected.Value

测试应用程序Test the app

  1. 按 F5(或者单击或点击靠近右上角的播放按钮)即可打开预览模式。Open Preview mode by pressing F5 (or by clicking or tapping the play button near the upper-right corner).

    打开预览模式

  2. 将条形码靠近设备上的摄像头,直至条形码的数字部分显示在“标签”控件中。Hold a barcode up to the camera on the device until the numerical component of the barcode appears in the Label control.

    如果未显示数字部分,请尝试使用 BarcodeType 列表中的其他选项。If the numerical component doesn't appear, try a different option in the BarcodeType list. 如果仍未显示正确的数据,请在输入文本控件中键入正确的数字。If the correct data still doesn't appear, type the correct number in the Input text control.

后续步骤Next steps

  • 将应用连接到数据源并配置 Patch 函数,使用户可以保存结果。Connect the app to a data source and configure the Patch function so that users can save results.
  • 添加下拉列表控件并进行配置,使用户可以选择想要扫描的条形码类型。Add a Drop down control, and configure it so that users can choose which type of barcode they want to scan.
  • 添加滑块控件并进行配置,使用户可调整扫描速率或条形码控件的高度。Add a Slider control, and configure it so that users can adjust the scan rate or the height of the Barcode control.