网易首页 > 网易号 > 正文 申请入驻

Deepseek嵌入Excel,帮你自动做表格,感觉我要失业了

0
分享至

之前跟大家分享了, 如何将Deepseek嵌入Word,有粉丝就问道如何将Deepseek嵌入到Excel呢?这不,今天方法就来了,跟嵌入Word的使用方法类似

一、使用方法

先来简单地说下使用的方法,操作非常的简单,跟嵌入Word类似

首先我们需要先选中对应的数据区域,然后在上方点击Deepseek,最后会跳出窗口,在窗口中提出问题,等待一段时间后就能得到对应的结果了,下面来看下如何构建这个效果

二、代码准备

首先需要复制下方的代码,关键点是需要修改API为自己的API,如何获取API的话,大家可以翻下之前的文章,是需要在Deepseek的官网获取的。

api_key = "你的api"

在这里将你的api直接替换为deepseek的api秘钥即可

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 Excel 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 DeepSeekExcel()
Dim api_key As String
Dim userQuestion As String
Dim selectedRange As Range
Dim cell As Range
Dim combinedInput As String
Dim response As String
Dim regex As Object
Dim matches As Object
api_key = "你的api"
If api_key = "" Then
MsgBox "请先设置API密钥", vbExclamation
Exit Sub
End If
On Error Resume Next
Set selectedRange = Selection
On Error GoTo 0
If selectedRange Is Nothing Then
MsgBox "请先选择要处理的数据区域", vbExclamation
Exit Sub
End If
userQuestion = InputBox("请输入您的问题(选中的单元格内容将作为处理数据):", "DeepSeek 提问")
If userQuestion = "" Then Exit Sub
Set regex = CreateObject("VBScript.RegExp")
regex.Pattern = """content"":""(.*?)"""
regex.Global = False
regex.MultiLine = True
Application.ScreenUpdating = False
For Each cell In selectedRange
If Trim(cell.Value) <> "" Then
' 组合问题和单元格内容
combinedInput = userQuestion & vbCrLf & vbCrLf & "数据内容:" & vbCrLf & cell.Value
' 转义特殊字符
combinedInput = Replace(combinedInput, "\", "\\")
combinedInput = Replace(combinedInput, """", "\""")
combinedInput = Replace(combinedInput, vbCrLf, "\n")
combinedInput = Replace(combinedInput, vbCr, "\n")
combinedInput = Replace(combinedInput, vbLf, "\n")
' 调用API
response = CallDeepSeekAPI(api_key, combinedInput)
If Left(response, 5) <> "Error" Then
Set matches = regex.Execute(response)
If matches.Count > 0 Then
Dim outputText As String
outputText = matches(0).SubMatches(0)
' 处理转义字符
outputText = Replace(outputText, "\""", """")
outputText = Replace(outputText, "\\", "\")
outputText = Replace(outputText, "\n", vbCrLf)
' 写入右侧相邻单元格
cell.Offset(0, 1).Value = outputText
Else
cell.Offset(0, 1).Value = "解析失败"
End If
Else
cell.Offset(0, 1).Value = "API错误"
End If
End If
Next cell
Application.ScreenUpdating = True
MsgBox "处理完成!", vbInformation
Set regex = Nothing
Set selectedRange = Nothing
End Sub

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 Excel 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 = NothingEnd FunctionSub DeepSeekExcel() Dim api_key As String Dim userQuestion As String Dim selectedRange As Range Dim cell As Range Dim combinedInput As String Dim response As String Dim regex As Object Dim matches As Object api_key = "你的api" If api_key = "" Then MsgBox "请先设置API密钥", vbExclamation Exit Sub End If On Error Resume Next Set selectedRange = Selection On Error GoTo 0 If selectedRange Is Nothing Then MsgBox "请先选择要处理的数据区域", vbExclamation Exit Sub End If userQuestion = InputBox("请输入您的问题(选中的单元格内容将作为处理数据):", "DeepSeek 提问") If userQuestion = "" Then Exit Sub Set regex = CreateObject("VBScript.RegExp") regex.Pattern = """content"":""(.*?)""" regex.Global = False regex.MultiLine = True Application.ScreenUpdating = False For Each cell In selectedRange If Trim(cell.Value) <> "" Then ' 组合问题和单元格内容 combinedInput = userQuestion & vbCrLf & vbCrLf & "数据内容:" & vbCrLf & cell.Value ' 转义特殊字符 combinedInput = Replace(combinedInput, "\", "\\") combinedInput = Replace(combinedInput, """", "\""") combinedInput = Replace(combinedInput, vbCrLf, "\n") combinedInput = Replace(combinedInput, vbCr, "\n") combinedInput = Replace(combinedInput, vbLf, "\n") ' 调用API response = CallDeepSeekAPI(api_key, combinedInput) If Left(response, 5) <> "Error" Then Set matches = regex.Execute(response) If matches.Count > 0 Then Dim outputText As String outputText = matches(0).SubMatches(0) ' 处理转义字符 outputText = Replace(outputText, "\""", """") outputText = Replace(outputText, "\\", "\") outputText = Replace(outputText, "\n", vbCrLf) ' 写入右侧相邻单元格 cell.Offset(0, 1).Value = outputText Else cell.Offset(0, 1).Value = "解析失败" End If Else cell.Offset(0, 1).Value = "API错误" End If End If Next cell Application.ScreenUpdating = True MsgBox "处理完成!", vbInformation Set regex = Nothing Set selectedRange = NothingEnd Sub

三、代码粘贴

在Excel中点击【开发工具】然后点击【Visiual Basic】进入编辑窗口,在右侧空白区域点击鼠标右键找到插入,找到【模块】,然后在右侧的窗口那里直接粘贴即可

在这里一定记得,API替换为自己的API

四、制作按钮

需要在右侧点击文件,然后最下放找到【选项】来调出Excel选项,在Excel选项中找到【自定义功能区】

我们需要在左侧将类别设置【宏】选中【DEEPSeekExcel】这个宏,然后在右侧的窗口中点击对应的选项卡,最后点击添加,即可将宏作为按钮添加到Excel表格中,至此就设置完毕了

五、加载宏

如果想要将这个宏按钮永久的保留在Excel中是需要使用加载宏的,之前发过,大家可以搜一下

DeepSeek搭配Excel,制作自定义按钮,实现办公自动化!

视频Excel从零到一

特别声明:以上内容(如有图片或视频亦包括在内)为自媒体平台“网易号”用户上传并发布,本平台仅提供信息存储服务。

Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.

相关推荐
热点推荐
教育部:要增强做好中小学科学教育紧迫感

教育部:要增强做好中小学科学教育紧迫感

中国青年报
2025-12-16 21:38:09
小鹏汽车法务部:已报案

小鹏汽车法务部:已报案

每日经济新闻
2025-12-18 14:52:26
布伦森三分准绝杀25+7+7尼克斯逆转步行者 内姆哈德31分

布伦森三分准绝杀25+7+7尼克斯逆转步行者 内姆哈德31分

醉卧浮生
2025-12-19 10:32:48
刘德华撤档,《内幕》亏损近2亿,我感慨:卖情怀救不了港片

刘德华撤档,《内幕》亏损近2亿,我感慨:卖情怀救不了港片

糊咖娱乐
2025-12-17 18:46:48
又打起来了?特朗普一声令下,美军深夜开火,拜登默克尔重出江湖

又打起来了?特朗普一声令下,美军深夜开火,拜登默克尔重出江湖

老塕是个手艺人
2025-12-19 10:50:52
携程与柬埔寨合作惹众怒,利润率高得吓人

携程与柬埔寨合作惹众怒,利润率高得吓人

上峰视点
2025-12-18 11:41:46
2026年慢病新规!对60/80岁以上老人开药有精准倾斜

2026年慢病新规!对60/80岁以上老人开药有精准倾斜

慧眼看世界哈哈
2025-12-17 05:55:37
又翻车!媒体称赞39岁无腿外卖员很励志,却被网友一边倒怒批!

又翻车!媒体称赞39岁无腿外卖员很励志,却被网友一边倒怒批!

麦杰逊
2025-12-16 14:29:46
两地分居?李梦发声,官宣选择,已无缘WCBA新赛季,张隆看懂了

两地分居?李梦发声,官宣选择,已无缘WCBA新赛季,张隆看懂了

乐聊球
2025-12-18 12:36:52
“新冠疫苗之父”落马,荣誉清零!打过三针的网友慌了

“新冠疫苗之父”落马,荣誉清零!打过三针的网友慌了

胡严乱语
2025-12-07 15:51:07
千万不要过度体检?医生再三强调:55岁后,5种体检能不做就不做

千万不要过度体检?医生再三强调:55岁后,5种体检能不做就不做

小胡军事爱好
2025-12-18 20:18:05
蒙古国又出昏招!蒙古国女外长狂妄至极,推行“第三邻国”政策

蒙古国又出昏招!蒙古国女外长狂妄至极,推行“第三邻国”政策

百态人间
2025-12-18 16:46:19
虽然毛主席享年83岁,保健医生却说:其实毛主席不具备长寿条件

虽然毛主席享年83岁,保健医生却说:其实毛主席不具备长寿条件

刘哥谈体育
2025-11-12 09:18:23
生日夜刷纪录!杰约43+11+9比肩詹皇 美媒:无法想象他能如此出色

生日夜刷纪录!杰约43+11+9比肩詹皇 美媒:无法想象他能如此出色

颜小白的篮球梦
2025-12-19 10:42:19
莫迪的四条战线全面溃败,让印度国际地位一跌再跌

莫迪的四条战线全面溃败,让印度国际地位一跌再跌

老范谈史
2025-12-18 22:05:40
从提车到坐牢,中间仅用时2分钟,杭州小米新车未出园区撞人致死

从提车到坐牢,中间仅用时2分钟,杭州小米新车未出园区撞人致死

华庭讲美食
2025-12-19 00:29:34
4岁男童晕倒,呼吸都没了,奶奶崩溃:救救宝宝!女店主跪地施救,视频揪心

4岁男童晕倒,呼吸都没了,奶奶崩溃:救救宝宝!女店主跪地施救,视频揪心

环球网资讯
2025-12-19 11:26:10
日本为什么挑衅中国,西班牙专家:中国错就错在没跟日本彻底清算

日本为什么挑衅中国,西班牙专家:中国错就错在没跟日本彻底清算

我心纵横天地间
2025-12-08 18:32:33
国务院国资委印发《中央企业违规经营投资责任追究实施办法》

国务院国资委印发《中央企业违规经营投资责任追究实施办法》

界面新闻
2025-12-18 17:59:48
李泽楷被她迷,林丹为她不顾妻儿,她究竟有什么魅力?

李泽楷被她迷,林丹为她不顾妻儿,她究竟有什么魅力?

趣文说娱
2025-12-12 18:03:47
2025-12-19 13:47:00
Excel从零到一 incentive-icons
Excel从零到一
0基础,0成本学习Excel
579文章数 87182关注度
往期回顾 全部

科技要闻

2025新一代人工智能创业大赛总决赛收官

头条要闻

团播女生私下卖力维护"大哥":经常擦边 有女生会被约走

头条要闻

团播女生私下卖力维护"大哥":经常擦边 有女生会被约走

体育要闻

没有塔图姆,还有塔秃姆

娱乐要闻

曲协表态仅6天,郭德纲担心的事还是发生

财经要闻

非法集资911亿!"金融大鳄"终审被判无期

汽车要闻

最便宜GLS 2026款奔驰GLS经典版售96.8万

态度原创

本地
时尚
亲子
健康
公开课

本地新闻

云游安徽|访黄山云海古村,读一城山水风骨

“烟管裤”今年冬天爆火,怎么搭都时髦!

亲子要闻

很多家长问支具铝板是什么,名字叫指铝板,网上都能搜到

这些新疗法,让化疗不再那么痛苦

公开课

李玫瑾:为什么性格比能力更重要?

无障碍浏览 进入关怀版