← 返回文档列表

WPS里装上deepseek,简直就是办公神器

文档路径: AI\AI应用场景\AI + 办公效率\WPS里装上deepseek,简直就是办公神器.md

WPS里装上deepseek,简直就是办公神器

不得不说,将DeepSeek-R1接入WPS真的惊呆我了!这意味着什么?简单来说,文档编辑从“手动挡”进化成了“自动挡”!不管是生成内容、优化表达,甚至是逻辑推理分析,AI都能直接帮你搞定,爽到飞起!

今天就来给大家聊聊,如何在WPS里接入 DeepSeek-R1,一步步带你从零配置到实战,让AI真正成为你的文档处理助手。

!img

为什么要在WPS里接入DeepSeek-R1?

讲道理,我以前用WPS,大多数时候就是敲敲字、插插图、改改排版,写完了还得自己检查语法、优化表达,甚至有时候绞尽脑汁想一段好文案,简直像掏空灵魂。

但现在,DeepSeek-R1 直接进驻 WPS,相当于在文档里藏了一个AI小助手,帮你:

这么一看,这不就是文档界的“外挂”吗?不装等啥呢?接下来就带你 一步步配置,让AI真正成为你的写作搭子。

第一步:获取DeepSeek-R1的API Key

要让DeepSeek-R1在WPS里跑起来,首先得有个 API Key,就像是进入AI世界的“通行证”。获取方式有两种:

方案一:DeepSeek官方API Key

可以去官网申请:https://www.deepseek.com

!img

方案二:腾讯云提供的DeepSeek-R1 API Key

这个方案更靠谱,可以去这里申请:https://curl.qcloud.com/T3M5yBHp相对稳定,推荐使用!

⚠️ 重要提醒:不管用哪个API Key,都得保证你的账户有余额,否则AI是不会搭理你的!

第二步:配置WPS开发工具

既然AI要接入WPS,那就得打开WPS的开发模式,整个流程其实很简单,跟着来就行。

1. 启用开发工具

!img

!img

2. 配置信任中心

!img

  1. 在 WPS 中,点击 文件选项信任中心
  2. 选择 “信任中心设置”“宏安全性”
  3. 将安全性设置为 “低”,这样才能运行 VBA 宏。

3. 添加宏模块

!img

!img

!img

!img

!img

保存代码,关闭 VB 编辑器。

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

``text Function CallDeepSeekAPI(apikey As String, inputText As String) As String Dim API As String Dim SendTxt As String Dim Http As Object Dim statuscode 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 " & apikey .send SendTxt statuscode = .Status response = .responseText End With

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

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

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

Set Http = Nothing End Function

Sub DeepSeekR1() Dim apikey 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

apikey = "替换为你的api key" If apikey = "" 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(apikey, inputText)

If Left(response, 5) <> "Error" Then ' 创建正则表达式对象来分别匹配推理内容和最终回答 Set reasoningRegex = CreateObject("VBScript.RegExp") With reasoningRegex .Global = True .MultiLine = True .IgnoreCase = False .Pattern = """reasoningcontent"":""(.?)""" 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 ``

第三步:自定义功能区(加个AI按钮!)

!img

!img

!img

现在,我们在WPS里加了一个专属按钮,点一下就能调用AI,牛不牛?

第四步:使用DeepSeek-R1生成内容(实战!)

!img

这体验,就像请了个贴身秘书,随时帮你写文案、润色表达,甚至还能帮你分析问题。

第五步:创建WPS模板(以后直接用!)

有了这个功能,我们可以保存成模板,省得每次都要重新配置:

!img

下次需要用的时候,直接打开这个模板文件就能用AI写文档,简直不要太方便!

这波操作下来,我真的感觉自己是个“AI增强人”了——文档写作变得超高效,润色优化信手拈来,甚至还能让AI帮忙分析问题,真香!

以前写报告、整理方案,最痛苦的就是改来改去,现在有了 DeepSeek-R1,直接在 WPS 里一句话搞定,省下来的时间都够我刷两集番了。

你们觉得这个功能 炸不炸?赶紧试试,把 AI 请进你的 WPS,享受这飞一般的文档编辑体验!

来源:https://www.cnblogs.com/shanren/p/18709648