数据来自快表API提供的数据。
企业版、独立版API文件在程序目录Kuaibiao\ThinkPHP\kbwebapp\index\controller下
- <?php
- namespace app\index\controller;
- use think\Db;
- use think\Request;
- use think\Session;
- class Custom extends \think\Controller{
-
- //数据库调用方法
- public function logs(){
- $data1 = Db::table('sys_log')
- ->field('lid,computername,username,logtype,logdate,logdetail')
- ->limit(10)
- ->select();
- return json($data1);
- }
- }
- ?>
复制代码
VBA取得数据并填充
- Public Sub ButtunClick(sender As Object,e As SpreadsheetGear.Windows.Controls.ShapeActionEventArgs)
- If e.Shape.Name = "Button 1" Then
- Dim client As New WebClient()
- client.Encoding = Encoding.UTF8
- client.Headers.Item("Content-Type") = "application/json"
- Dim resulta As String = client.DownloadString("http://127.0.0.1:9385/index.php/index/custom/logs")
- Dim result As String = JToken.Parse(resulta).ToString(Formatting.Indented)
- ' messagebox.show(result)
- ' 解析 JSON 字符串为 JArray
- Dim res As JArray = JArray.Parse(result)
- ' messagebox.show(res.Item(0).Item("lid"))
-
- Dim reslength As Integer = res.Count
- Dim r As Integer
- For r = 0 To reslength - 1
- ActiveWorkbook.Worksheets("Sheet1").Cells(r + 10, 1).Value = res.Item(r).Item("lid").ToString
- ActiveWorkbook.Worksheets("Sheet1").Cells(r + 10, 2).Value = res.Item(r).Item("computername").ToString
- ActiveWorkbook.Worksheets("Sheet1").Cells(r + 10, 3).Value = res.Item(r).Item("logtype").ToString
- Next r
- End If
-
- End Sub'按钮/标签点击事件
复制代码
|
|
快表帝国客服01