百科 > IT百科 > 专业问答 > 智能聚合 > 正文

deepseek怎么生成word文档

发布时间:2025-03-10 18:59

在如今这个信息爆炸的时代,高效地处理文档信息成为了许多职场人士和学生党梦寐以求的技能。而今天,我要给大家介绍的,就是如何在DeepSeek中轻松生成Word文档,让你的工作效率瞬间提升!

一、前期准备

注册并登录 DeepSeek :访问 DeepSeek 官网,注册一个账号并登录,进入 API 开放平台,创建 API Key,这将是后续调用 DeepSeek 服务的凭证。

确保 Word 版本支持 :确认你使用的 Word 版本支持 VBA 宏功能,因为接下来的操作需要用到 VBA 编程来实现 DeepSeek 与 Word 的集成。

二、配置 Word 开发者工具

打开 Word 文档,点击 “文件” 选项卡,选择 “选项”。

在弹出的 “Word 选项” 对话框中,点击 “自定义功能区”。

在右侧的 “主选项卡” 列表中,勾选 “开发者工具”,然后点击 “确定”。这样,Word 的功能区就会出现 “开发者工具” 选项卡。

三、设置信任中心

再次点击 “文件” 选项卡,选择 “选项”,进入 “Word 选项” 对话框。

点击 “信任中心”,然后在右侧点击 “信任中心设置”。

在 “信任中心设置” 对话框中,选择 “宏设置”,勾选 “启用所有宏” 以及 “信任对 VBA 项目的数字签名”,然后点击 “确定” 保存设置。

四、添加 VBA 脚本

点击 “开发者工具” 选项卡,然后点击 “Visual Basic”,这将打开 Visual Basic 编辑器。

在编辑器中,右键点击 “VBAProject (你的文档名称)”,选择 “插入” -> “模块”,创建一个新的模块。

将以下代码复制并粘贴到模块中,注意将代码中的 api_key = "请输入自己的API密钥" 替换为你之前获取的 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 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 Range

api_key = "请输入自己的API密钥"

If api_key = "" Then

MsgBox "Please enter the API key.", vbExclamation

Exit Sub

End If

If Selection.Type <> wdSelectionNormal Then

MsgBox "Please select text.", vbExclamation

Exit Sub

End If

Set originalSelection = Selection.Range.Duplicate

inputText = Selection.Text

inputText = Replace(inputText, "\", "\\")

inputText = Replace(inputText, vbCrLf, " ")

inputText = Replace(inputText, vbCr, " ")

inputText = Replace(inputText, vbLf, " ")

inputText = Replace(inputText, """", "\""") ' 转义双引号

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", vbCrLf)

response = Replace(response, "\\", "\")

response = Replace(response, "&", "")

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

五、添加生成按钮

点击 “文件” -> “选项” -> “自定义功能区”。

在右侧的 “自定义功能区” 列表中,右键点击 “开发工具”,选择 “添加新组”。

在新创建的组中,点击 “从以下命令选择”,在下拉列表中找到 “宏”,然后把之前创建的宏模块添加到开发工具里。

选中添加的命令,右键点击重命名,选择开始符号作为图标,并重命名为 “生成”,最后点击 “确定”。

六、生成 Word 文档

在 Word 文档中,选中你想要 DeepSeek 处理的文本内容。点击刚刚添加的 “生成” 按钮,DeepSeek 将会根据你选中的文本内容,利用其强大的 AI 能力生成相应的 Word 文档材料。生成的内容会自动添加在文档的末尾,你可以根据需要对其进行进一步的编辑和修改。

通过以上步骤,你就可以在 DeepSeek 中轻松生成 Word 文档了。这不仅大大提高了文档创作的效率,还能让你在撰写报告、论文、文案等各种文档时更加得心应手。赶紧试试吧,让你的工作和学习效率瞬间提升!