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

Autohotkey脚本开发需求:输入编号自动粘贴对应HTML内容到Word

Hey there! No worries at all being an AutoHotkey newbie—we all start somewhere. Let’s build a script that dynamically creates those hotstrings for you, so you don’t have to write 6000+ lines manually. Here’s how to do it:

Step 1: The Full Script

Copy this into a new .ahk file, then adjust the folder path to where your HTML files are stored:

; Replace this path with the actual folder containing your HTML files
htmlFolder := "C:\Path\To\Your\HTML\Files"

; Loop through all HTML files in the folder
Loop, Files, %htmlFolder%\*.html, F
{
    ; Extract the filename without the .html extension (e.g., 001001 from 001001.html)
    fileName := SubStr(A_LoopFileName, 1, -5)
    
    ; Create a hotstring for this filename: when you type the number, it triggers the paste
    Hotstring(":*:" fileName "::", "PasteHTMLContent(""" fileName """)")
}

; Function to read the HTML file content and paste it into Word
PasteHTMLContent(fileName)
{
    global htmlFolder
    filePath := htmlFolder "\" fileName ".html"
    
    ; Read the content of the HTML file
    FileRead, fileContent, %filePath%
    
    ; If the file was read successfully, paste the content
    if (ErrorLevel = 0)
    {
        ; Copy content to clipboard (cleaner than direct send for Word)
        Clipboard := fileContent
        ; Wait for clipboard to update
        ClipWait, 1
        ; Paste in Word (Ctrl+V)
        Send ^v
        ; Clear clipboard after paste (optional but tidy)
        Clipboard := ""
    }
    else
    {
        ; Show a message if the file can't be found/read
        MsgBox, Error: Could not read file %filePath%
    }
}
Step 2: Key Details for Newbies
  • Folder Path: Make sure you replace C:\Path\To\Your\HTML\Files with the actual path to your folder (e.g., D:\MySentences\HTMLFiles). If the path has spaces, wrap it in quotes like "D:\My Sentences\HTML Files".
  • Hotstring Behavior: The :*: prefix means the hotstring triggers immediately after you finish typing the number—no need to press an extra key like Space or Enter. Perfect for your use case!
  • Reading Files: The FileRead command grabs the entire content of the HTML file (which you said is just one sentence, so this works perfectly).
  • Pasting to Word: Using the clipboard (Clipboard := fileContent) and then sending Ctrl+V is more reliable than directly sending the text, especially in Word where formatting might matter (though your files are plain text sentences, this is still a safe approach).
Step 3: Testing the Script
  1. Save the script as SentencePaster.ahk
  2. Double-click to run it (you’ll see a green H icon in your system tray)
  3. Open Word, type one of your file numbers (like 001001), and watch it automatically replace with the sentence from the corresponding HTML file!

If you run into any issues (like files not being found), double-check that the folder path is correct and that your filenames match exactly (no extra spaces or typos).

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:33:42