周一至周五 : 08:30 - 17:30 客服专员电话/微信:18049979371 QQ:2982200781
微信咨询

扫码微信咨询

关注公众号

关注微信公众号

电话: 021 5161 9370
返回顶部
通过VBA将快表API获得的数据填入表格中
显示全部楼层 倒序浏览 发表日期 2025-04-30 15:56:24 90次阅读 0次回复
数据来自快表API提供的数据。

企业版、独立版API文件在程序目录Kuaibiao\ThinkPHP\kbwebapp\index\controller下
  1. <?php
  2. namespace app\index\controller;
  3. use think\Db;
  4. use think\Request;
  5. use think\Session;
  6. class Custom extends \think\Controller{
  7.        
  8.         //数据库调用方法
  9.         public function logs(){
  10.                 $data1 = Db::table('sys_log')
  11.                                         ->field('lid,computername,username,logtype,logdate,logdetail')
  12.                                         ->limit(10)
  13.                                         ->select();
  14.                 return json($data1);
  15.         }
  16. }
  17. ?>
复制代码


VBA取得数据并填充

  1.        Public Sub ButtunClick(sender As Object,e As SpreadsheetGear.Windows.Controls.ShapeActionEventArgs)
  2.                 If e.Shape.Name = "Button 1" Then                           
  3.                            Dim client As New WebClient()
  4.                            client.Encoding = Encoding.UTF8
  5.                            client.Headers.Item("Content-Type") = "application/json"
  6.                            Dim resulta As String = client.DownloadString("http://127.0.0.1:9385/index.php/index/custom/logs")
  7.                            Dim result As String = JToken.Parse(resulta).ToString(Formatting.Indented)
  8. '                           messagebox.show(result)
  9.                            ' 解析 JSON 字符串为 JArray
  10.                            Dim res As JArray = JArray.Parse(result)
  11. '                           messagebox.show(res.Item(0).Item("lid"))
  12.                           
  13.                            Dim reslength As Integer = res.Count
  14.                            Dim r As Integer
  15.                            For r = 0 To reslength - 1
  16.                                    ActiveWorkbook.Worksheets("Sheet1").Cells(r + 10, 1).Value = res.Item(r).Item("lid").ToString
  17.                                    ActiveWorkbook.Worksheets("Sheet1").Cells(r + 10, 2).Value = res.Item(r).Item("computername").ToString
  18.                                    ActiveWorkbook.Worksheets("Sheet1").Cells(r + 10, 3).Value = res.Item(r).Item("logtype").ToString
  19.                            Next r
  20.                 End If
  21.                
  22.        End Sub'按钮/标签点击事件
复制代码



您需要登录后才可以回帖 登录 | 立即注册

本版积分规则  允许回帖邮件提醒楼主

快表软件是国内较早研究表格类软件开发平台的团队之一,迄今已有十多年的行业经验.致力于为企事业单位提供实用可靠的数字化平台。
  • 微信公众号

  • 微信小商店

  • 微信客服

  • Powered by Discuz! X3.4 | Copyright © 2022-2024, XiRong Soft. | 快表软件
  • 沪ICP备13033196号 | 营业执照 |上海西戎软件科技有限公司|沪公网安备31011502002146号|沪ICP备13033196号 |