【最全教程】DeepSeek接入WPS,效率起飞!
说实话,接入它之后,我的文档处理速度简直能和闪电比肩,不信你看——我们一步步来,看看如何在WPS中加速自己的工作流。
为什么要将DeepSeek-R1接入WPS?
但有了DeepSeek-R1,基本上就是让AI来帮我一把,直接完成那些繁琐的文档编辑和内容生成。效率提升不说,文档也会变得更智能——完全解放了我那颗“打字快手”的心。
第一步:获取DeepSeek-R1的API Key
官网有个API Key可以申请(不过,提醒一句,目前申请已经暂停了)。但你还是可以去官网碰碰运气,或许稍后会有新机会。
官网地址:https://www.deepseek.com/
如果你不想等官方开通,腾讯云提供的API Key是一个稳定的替代方案,效果也很棒,推荐大家直接用。
地址:https://curl.qcloud.com/T3M5yBHp
第二步:配置WPS开发工具
1. 启用开发工具
打开WPS,新建个文档。
点击顶部菜单栏的“文件” → “选项” → “自定义功能区”。 在右侧的功能区列表里,勾选“工具”选项。
点“确定”,保存设置。
2. 配置信任中心
点击“文件” → “选项” → “信任中心”。 选择“信任中心设置” → “宏安全性”。 将宏安全性设置为“低”,这样就能运行VBA宏了。
3. 添加模块
在WPS中点击“工具” → “开发工具” → “切换到VB环境”。
重启后,回到文档,再点击VB编辑器。
在弹出的编辑器窗口中,点击“插入” → “模块”。
Function CallDeepSeekAPI(api_key As String, inputText As String) As StringDim API As StringDim SendTxt As StringDim Http As ObjectDim status_code As IntegerDim response As StringAPI = "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 SendTxtstatus_code = .Statusresponse = .responseTextEnd With' 弹出窗口显示 API 响应(调试用)' MsgBox "API Response: " & response, vbInformation, "Debug Info"If status_code = 200 ThenCallDeepSeekAPI = responseElseCallDeepSeekAPI = "Error: " & status_code & " - " & responseEnd IfSet Http = NothingEnd FunctionSub DeepSeekR1()Dim api_key As StringDim inputText As StringDim response As StringDim regex As ObjectDim reasoningRegex As ObjectDim contentRegex As ObjectDim matches As ObjectDim reasoningMatches As ObjectDim originalSelection As ObjectDim reasoningContent As StringDim finalContent As Stringapi_key = "替换为你的api key"If api_key = "" ThenMsgBox "Please enter the API key."Exit SubElseIf Selection.Type <> wdSelectionNormal ThenMsgBox "Please select text."Exit SubEnd If' 保存原始选中的文本Set originalSelection = Selection.Range.DuplicateinputText = 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 WithSet 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 ThenreasoningContent = 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 ThenfinalContent = 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 ThenSelection.TypeParagraphSelection.TypeText "推理过程:"Selection.TypeParagraphSelection.TypeText reasoningContentSelection.TypeParagraphSelection.TypeText "最终回答:"Selection.TypeParagraphEnd If' 插入最终回答Selection.TypeText finalContent' 将光标移回原来选中文本的末尾originalSelection.SelectElseMsgBox "Failed to parse API response.", vbExclamationEnd IfElseMsgBox response, vbCriticalEnd IfEnd Sub
4. 自定义功能区
回到WPS主界面,点击“文件” → “选项” → “自定义功能区”。 在右侧功能区列表中,点击“新建组”,命名为“DeepSeek”。
在左侧的命令列表中,找到刚才添加的宏(比如“DeepSeekV3”),点击“添加”。
右键重命名为“生成”,然后点击“确定”保存设置。
第三步:使用DeepSeek-R1生成内容
第四步:创建WPS模板
点击“文件” → “另存为”。 在保存类型中选择“Microsoft Word 带宏的模板文件 (*.dotm)”。
将文件保存到WPS的模板文件夹中,路径大概是: C:\Users\用户名\AppData\Roaming\kingsoft\wps\startup。下次使用时,打开这个模板文件就行。
以后写文档不再是“硬仗”,而是轻松的“AI配合”,赶快试试吧!
最后,我为大家打造了一份deepseek的入门到精通教程,完全免费:https://www.songshuhezi.com/deepseek
同时,也欢迎加入下方的交流群,一起研究deepseek的最新玩法