**
最近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 =