You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Power Query批量提取多发票工作簿指定单元格数据

Alright, let's solve this batch extraction task with Power Query—you've got 700+ workbooks, but this is straightforward once you know the steps. Here's a step-by-step solution tailored to your needs:

Power Query Batch Extraction for Specific Cells Across Multiple Workbooks

Step 1: Connect to the Folder Containing Your Workbooks

  • Open a blank Excel workbook, go to the Data tab
  • Select Get Data > From File > From Folder
  • Navigate to the folder holding all your 700+ invoice workbooks, then click OK

Step 2: Add a Custom Column to Extract Target Cells

In the Folder Content query editor:

  1. First, you can clean up the view by removing unnecessary columns (like "Content Type" or "Folder Path") if you want—keep at least "Name" (to track which workbook each row comes from) and "Content".
  2. Go to Add Column > Custom Column, paste this M code into the formula box:
let
    // Load the workbook content
    WorkbookSource = Excel.Workbook([Content], null, true),
    // Target the "Sheet 1" worksheet
    Sheet1Data = WorkbookSource{[Item="Sheet 1", Kind="Sheet"]}[Data],
    // Extract cells: note Power Query uses 0-based indexing
    HoursValue = Sheet1Data{32}[Column4], // D33 = row 33 (index 32), column D (index 4)
    TravelTimeValue = Sheet1Data{34}[Column4], // D35 = row 35 (index 34)
    MileageValue = Sheet1Data{36}[Column4] // D37 = row 37 (index 36)
in
    [工时 = HoursValue, 旅行时长 = TravelTimeValue, 里程数 = MileageValue]

Quick note on indexing: Power Query counts rows/columns starting at 0, so row 33 is index 32, column D is index 4. This matches your cell references perfectly.

Step 3: Expand the Custom Column

  • Click the expand icon (⊕) on the right side of your new custom column header
  • Check all three fields (工时, 旅行时长, 里程数) in the dropdown, then click OK

Step 4: Finalize and Load the Data

  • You’ll now see a table with the filename and all three extracted values for each workbook
  • Double-check a few rows to confirm the data matches the source workbooks
  • Click Close & Load to bring the consolidated data into a new Excel worksheet

Bonus Tips

  • If some workbooks might have missing "Sheet 1" or invalid cells, add error handling to the M code using try...otherwise (e.g., try Sheet1Data{32}[Column4] otherwise null) to avoid query failures.
  • Processing 700 files might take a minute or two—let Power Query finish running before making changes.

内容的提问来源于stack exchange,提问作者DougB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:19:27