在 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.
  • 長型條碼 (例如 I2of5,會有 15 個以上的字元) 可能會產生截斷或不正確的結果,尤其是條碼列印不清楚時。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).

    快速導覽的開啟畫面

    注意︰您日後可以隨時按一下或點選右上角附近的問號圖示,然後按一下或點選 Take the intro tour (簡介導覽),即可觀看導覽。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.