DeepSeek与word、wps、excel和PPT嵌套使用汇总

**

‍最近DeepSeek成功出圈,全网铺天盖地的文章和视频,但参考资料半成品居多,今天就简单分享下DeepSeek与word、wps、excel和ppt的汇总资料,仅限记录,笔记分享(来源于网上各种资料粘贴复制)。

**

1.DeepSeek+Word

1.1 获取API key

  • deepseek-r1模型API Key获取地址:https://www.deepseek.com/
  • qwen2.5模型API Key获取地址:https://bailian.console.aliyun.com/

1.2配置Word

1.2.1启用开发者工具

  • 新建Word,点击 文件 -> 选项 -> 自定义功能区
  • 勾选"开发者工具"
    在这里插入图片描述

1.2.2. 配置信任中心

  • 点击 信任中心 -> 信任中心设置
  • 选择"启用所有宏"与"信任对VBA…"
    在这里插入图片描述

1.2.3添加模块

  • 点击开发者工具,点击Visual Basic
  • 在新窗口中点击插入,选择模块
  • 将代码复制到编辑区中(注意替换你自己的API key

在这里插入图片描述
DeepSeekV3代码

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-chat"", ""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

    ' 弹出窗口显示 API 响应(调试用)

    ' MsgBox "API Response: " & response, vbInformation, "Debug Info"

    If status_code = 200 Then
        CallDeepSeekAPI = response
    Else
        CallDeepSeekAPI = "Error: " & status_code & " - " & response
    End If

    Set Http = Nothing
End Function

Sub DeepSeekV3()
    Dim api_key As String
    Dim inputText As String
    Dim response As String
    Dim regex As Object
    Dim matches As Object
    Dim originalSelection As Object

    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
        Set regex = CreateObject("VBScript.RegExp")
        With regex
            .Global = True
            .MultiLine = True
            .IgnoreCase = False
            .Pattern = """content"":""(.*?)"""
        End With
        Set matches = regex.Execute(response)
        If matches.Count > 0 Then
            response = matches(0).SubMatches(0)
            response = Replace(Replace(response, """", Chr(34)), """", Chr(34))

            ' 取消选中原始文本
            Selection.Collapse Direction:=wdCollapseEnd

            ' 将内容插入到选中文字的下一行
            Selection.TypeParagraph ' 插入新行
            Selection.TypeText text:=response

            ' 将光标移回原来选中文本的末尾
            originalSelection.Select
        Else
            MsgBox "Failed to parse API response.", vbExclamation
        End If
    Else
        MsgBox response, vbCritical
    End If
End Sub

deepseek-reasoner代码(即DeepSeek-R1模型)

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

    ' 弹出窗口显示 API 响应(调试用)

    ' MsgBox "API Response: " & response, vbInformation, "Debug Info"

    If status_code = 200 Then
        CallDeepSeekAPI = response
    Else
        CallDeepSeekAPI = "Error: " & status_code & " - " & response
    End If

    Set Http = Nothing
End Function

Sub DeepSeekV3()
    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
        ' 创建正则表达式对象来分别匹配推理内容和最终回答
        Set reasoningRegex = CreateObject("VBScript.RegExp")
        With reasoningRegex
            .Global = True
            .MultiLine = True
            .IgnoreCase = False
            .Pattern = """reasoning_content"":""(.*?)"""
        End With
        
        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.", vbExclamation
        End If
    Else
        MsgBox response, vbCritical
    End If
End Sub

qwen2.5-max代码

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://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions"
    SendTxt = "{""model"": ""qwen-max-0125"", ""messages"": [{""role"":""system"", ""content"":""You are a Word assistant""}, {""role"":""user"", ""content"":""" & inputText & """}]}"

    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

    ' 弹出窗口显示 API 响应(调试用)
    ' MsgBox "API Response: " & response, vbInformation, "Debug Info"

    If status_code = 200 Then
        CallDeepSeekAPI = response
    Else
        CallDeepSeekAPI = "Error: " & status_code & " - " & response
    End If

    Set Http = Nothing
End Function

Sub DeepSeekV3()
    Dim api_key As String
    Dim inputText As String
    Dim response As String
    Dim regex As Object
    Dim matches As Object
    Dim originalSelection As Object

    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
        Set regex = CreateObject("VBScript.RegExp")
        With regex
            .Global = True
            .MultiLine = True
            .IgnoreCase = False
            .Pattern = """content"":""(.*?)"""
        End With
        Set matches = regex.Execute(response)
        If matches.Count > 0 Then
            response = matches(0).SubMatches(0)
            ' 处理换行符和特殊字符
            response = Replace(response, "\n\n", vbNewLine)  ' 双换行替换为真实的单换行
            response = Replace(response, "\n", vbNewLine)  ' 单换行替换为真实的换行
            response = Replace(Replace(response, """", Chr(34)), """", Chr(34))

            ' 取消选中原始文本
            Selection.Collapse Direction:=wdCollapseEnd

            ' 将内容插入到选中文字的下一行
            Selection.TypeParagraph ' 插入新行
            Selection.TypeText text:=response

            ' 将光标移回原来选中文本的末尾
            originalSelection.Select
        Else
            MsgBox "Failed to parse API response.", vbExclamation
        End If
    Else
        MsgBox response, vbCritical
    End If
End Sub

1.2.4自定义功能区

  • 点击 文件 -> 选项 -> 自定义功能区
  • 右键开发工具,点击添加新组
  • 右键新建组,点击重命名
  • 将其命名为"DeepSeek",选择心仪的图标
  • 点击确定
    在这里插入图片描述

1.2.5使用方法

    1. 选中需要处理的文字
    1. 点击"生成"按钮
    1. 等待大模型响应
      在这里插入图片描述

1.2.6创建模板

  • 点击"文件" → “另存为”
  • 选择保存类型为"Word 启用宏的模板 (.dotm)"
  • 保存到 Word 的模板文件夹(通常是 C:\Users\用户名\AppData\Roaming\Microsoft\Word\STARTUP)
  • 这样每次打开 Word 时,宏就会自动可用

2.DeepSeek+wps

直接放链接,自己去了解吧,挺简单。。。DeepSeek+wps使用方法链接

3.DeepSeek+Excel

DeepSeek+Excel链接

4.DeepSeek+PPT使用方法(结合KIMI一起使用)

DeepSeek+PPT

### 将DeepSeek集成至WPS Excel #### 方法概述 为了使DeepSeek能够WPS Excel有效对接并发挥其功能,通常需要通过API接口来实现数据交互。这涉及到创建应用程序编程接口(API),以便于两个软件之间的通信[^1]。 #### 实现步骤说明 ##### API开发环境准备 确保拥有必要的开发工具技术栈支持RESTful服务调用。对于大多数现代应用来说,Python是一个不错的选择因为它有丰富的库用于处理HTTP请求以及解析JSON格式的数据交换。 ##### 获取DeepSeek API访问权限 联系DeepSeek官方获取合法的API密钥其他认证凭证,这些信息将是发起任何向DeepSeek服务器发送请求所必需的一部分。 ##### 编写中间件脚本 编写一段作为桥梁作用的小程序或函数,该程序负责接收来自Excel宏命令或其他形式触发事件的信息查询参数,并将其转换成适合传递给DeepSeek API的形式;同时也要能接受从DeepSeek返回的结果并将它们适配回Excel可理解的内容结构中去显示出来。 ```python import requests from wox import Wox, WoxAPI # 假设使用wox框架简化插件开发过程 class DeepSeekIntegration(Wox): def query(self, keyword): url = "https://api.deepseek.com/v1/search" headers = { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' } params = {'q': keyword} response = requests.get(url, headers=headers, json=params).json() items = [] for item in response['results']: title = item.get('title', '') description = item.get('description', '')[:100] items.append({ "Title": f"{title}", "SubTitle": f"{description}...", "IcoPath":"Images/app.png", "JsonRPCAction":{"method": "open_url", "parameters":[item["link"]], "dontHideAfterAction":False} }) return items if __name__ == "__main__": DeepSeekIntegration() ``` 请注意上述代码片段仅作为一个概念验证性质的例子展示如何构建这样一个连接器,并不是完整的解决方案。实际部署时还需要考虑安全性、错误处理机制等方面因素。 ##### 配置WPS Office VBA/宏指令集 利用VBA (Visual Basic for Applications) 或者其他由WPS提供的自动化特性,在工作表内部定义特定动作以激活之前编写的外部Python脚本运行,从而完成整个流程闭环操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值