轻松接入DeepSeek:Word用户必备的详细教程与技巧

今天我们来聊聊如何将 DeepSeek 接入 Word,打造一个超级有用的自动化小工具!🛠️

那么,DeepSeek 如何与 Word 融合?其实过程一点都不复杂,跟着我的步骤走,保证你能顺利在 Word 中使用 DeepSeek,就像拥有一个智能写作助手一样!✨

第一步:获取 API Key

要在 Word 上使用 DeepSeek,首要任务是获得一个 API Key。这就像是 DeepSeek 给你的“入场券”,没有它,DeepSeek 就无法顺利运行于你的 Word 中。

但是由于 DeepSeek 官网服务器资源紧张,现在 API 服务已经暂停充值了。不过别担心,你可以通过 腾讯云: https://curl.qcloud.com/T3M5yBHp 来申请 API Key。

目前能正常使用,推荐申请!

记得把 Key 复制并妥善保存,最好在记事本中备份一下,以防万一哦!📝

第二步:配置 Word

获取好 API Key 后,就可以把 DeepSeek 集成到 Word 中。接下来的步骤主要是设置和连接,逐步走起来就好!

1. 启用开发者工具

首先打开 Word,依次点击“文件” -> “选项” -> “自定义功能区”。在功能区选项中,勾选“开发者工具”,然后点击“确定”。

启用开发者工具

这样,Word 菜单栏中会新增一个“开发者工具”选项卡,感觉就像进入了开发者模式一样!🎨

2. 调整信任设置

接下来,依次点击“文件” -> “选项” -> “信任中心” -> “信任中心设置”,在弹出的窗口里选择“启用所有宏”和“信任对 VBA 工程对象模型的访问”。这些设置会确保 Word 可以正常运行脚本代码哦。别忘了点击“确定”保存!

信任设置

3. 添加脚本代码

现在最激动人心的环节来了:添加脚本代码!🤖

  • 打开“开发者工具”选项卡,点击左上角的“Visual Basic”按钮,进入编辑器窗口。

Visual Basic

  • 在编辑器中,点击“插入” -> “模块”,然后会弹出一个新的代码窗口。

插入模块

  • 将以下代码复制粘贴到代码窗口中(记得替换 API Key):

代码示例

以下是DeepSeek-R1代码(官方apikey)的完整代码示例,请替换为你的 API Key:


Function CallDeepSeekAPI(api_key As String, inputText As String) As String
    Dim API As String
    Dim SendTxt As String
    Dim Http As Object
    Dim status_code As Integer
    Dim response As String
    
    API = "https://api.deepseek.com/chat/completions"
    SendTxt = "{" & """model"": ""deepseek-reasoner"", ""messages"": [{""role"":""system"", ""content"":""You are a Word assistant""}, {""role"":""user"", ""content"":""" & inputText & """}], ""stream"": false}"
    
    Set Http = CreateObject("MSXML2.XMLHTTP")
    With Http
        .Open "POST", API, False
        .setRequestHeader "Content-Type", "application/json"
        .setRequestHeader "Authorization", "Bearer " & api_key
        .send SendTxt
        status_code = .Status
        response = .responseText
    End With
    
    If status_code = 200 Then
        CallDeepSeekAPI = response
    Else
        CallDeepSeekAPI = "Error: " & status_code & " - " & response
    End If
    
    Set Http = Nothing
End Function

Sub DeepSeekR1()
    Dim api_key As String
    Dim inputText As String
    Dim response As String
    Dim regex As Object
    Dim reasoningRegex As Object
    Dim contentRegex As Object
    Dim matches As Object
    Dim reasoningMatches As Object
    Dim originalSelection As Object
    Dim reasoningContent As String
    Dim finalContent As String
    
    api_key = "替换为你的api key"
    If api_key = "" Then
        MsgBox "Please enter the API key."
        Exit Sub
    ElseIf Selection.Type <> wdSelectionNormal Then
        MsgBox "Please select text."
        Exit Sub
    End If
    
    Set originalSelection = Selection.Range.Duplicate

    inputText = Replace(Replace(Replace(Replace(Replace(Selection.text, "\", "\\"), vbCrLf, ""), vbCr, ""), vbLf, ""), Chr(34), "\""")
    response = CallDeepSeekAPI(api_key, inputText)

    If Left(response, 5) <> "Error" Then
        Dim reasoningRegex As Object
        Set reasoningRegex = CreateObject("VBScript.RegExp")
        With reasoningRegex
            .Global = True
            .MultiLine = True
            .IgnoreCase = False
            .Pattern = """reasoning_content"":""(.*?)"""
        End With
        
        Dim contentRegex As Object
        Set contentRegex = CreateObject("VBScript.RegExp")
        With contentRegex
            .Global = True
            .MultiLine = True
            .IgnoreCase = False
            .Pattern = """content"":""(.*?)"""
        End With
        
        Set reasoningMatches = reasoningRegex.Execute(response)
        If reasoningMatches.Count > 0 Then
            reasoningContent = reasoningMatches(0).SubMatches(0)
            reasoningContent = Replace(reasoningContent, "\n\n", vbNewLine)
            reasoningContent = Replace(reasoningContent, "\n", vbNewLine)
            reasoningContent = Replace(Replace(reasoningContent, """", Chr(34)), """", Chr(34))
        End If

        Set matches = contentRegex.Execute(response)
        If matches.Count > 0 Then
            finalContent = matches(0).SubMatches(0)
            finalContent = Replace(finalContent, "\n\n", vbNewLine)
            finalContent = Replace(finalContent, "\n", vbNewLine)
            finalContent = Replace(Replace(finalContent, """", Chr(34)), """", Chr(34))

            Selection.Collapse Direction:=wdCollapseEnd
            If Len(reasoningContent) > 0 Then
                Selection.TypeParagraph
                Selection.TypeText "推理过程:"
                Selection.TypeParagraph
                Selection.TypeText reasoningContent
                Selection.TypeParagraph
                Selection.TypeText "最终回答:"
                Selection.TypeParagraph
            End If
            Selection.TypeText finalContent

            originalSelection.Select
        Else
            MsgBox "Failed to parse API response."
        End If
    Else
        MsgBox response, vbCritical
    End If
End Sub

        

(这段代码可以通过 DeepSeek API 操作选中的文字,并将结果自动插入到文档中)

4. 自定义按钮

代码添加完成后,我们需要回到 Word 主界面,给它加个自定义按钮,方便调用 DeepSeek 的功能:

  • 点击“文件” -> “选项” -> “自定义功能区”,然后右键点击“开发工具”,选择“添加新组”。

添加新组

  • 选择新建的组,右键重命名为“DeepSeek”,并选择你喜欢的图标,尽量用个好看的(毕竟是自己的工具嘛)。

重命名

  • 在左侧选择“宏”,找到刚刚添加的“DeepSeekV3”,点击“添加”到右侧的新组中。

添加宏

  • 再次右键重命名为“开始对话”,并选择合适的图标。

开始对话

就这样,你已经完成了 DeepSeek 功能的接入!每次打开 Word,只需点击“开发工具”中的“开始对话”按钮,就能享受 DeepSeek 带来的便捷服务。

第三步:测试 DeepSeek 功能

配置完成后,让我们来测试一下 DeepSeek 是否成功接入 Word。

  1. 打开一个 Word 文档,输入一段文字,比如:“将上面的文本翻译成英文”。

  2. 选中这段文字,然后点击菜单栏中的“开始对话”按钮。

  3. 如果设置正确,DeepSeek 会自动处理你的文字,并将处理结果(例如翻译成英文的内容)插入到选中的文字下方。

测试效果

结果展示

是不是超简单?虽然过程看似繁琐,但只需一步步按照做就可以。不再需要切换窗口、复制粘贴,直接在 Word 内高效使用 DeepSeek!


通过这种方式,不仅能提升工作效率,还能让写作和文档处理变得更加智能和方便。如果你常常需要生成内容、翻译或者智能处理,这个 DeepSeek 接入 Word 的小技巧绝对是个非常实用的工具!💼

最后,我为大家准备了一份从入门到精通的 DeepSeek 教程,完全免费:https://www.songshuhezi.com/deepseek

欢迎加入下方交流群,一起研究 DeepSeek 的最新玩法!

图片

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注