ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 4393|回复: 45

[求助] 有偿求助-Excel数据向公司内网自动填表的程序

[复制链接]

TA的精华主题

TA的得分主题

发表于 2020-4-30 10:44 | 显示全部楼层 |阅读模式
因工作需要,经常需要把excel表格中的数据输入到公司内网的网页表单上,然后通过网页提交到公司内部数据库中。问题的难点是我自己没有Html,asp, js等网页程序经验,没有网页抓包等分析经验,搞不定如何定位到内网系统的一个个文本框,combobox等。

而且因为是公司内网,调试只能在本人电脑上进行,所以如果有上海地区的高手可以帮忙的话,本人愿意带电脑前往并给与一定的补偿;本人有一定的VBA基础,也附上在网上查找的一些自动填表的非系统方法,所以只需要您给出解决问题的思路和方法,对我进行点拨一下即可。 有意者请微信:18917606732  或邮箱:zouhy0442@sina.com


Capture.JPG

vba IE表单填写.zip

14.48 KB, 下载次数: 23

TA的精华主题

TA的得分主题

 楼主| 发表于 2020-4-30 10:47 | 显示全部楼层
PS,我是做机油研发的,美孚一号、嘉实多极护等都出自我公司,所以可以免费终身送全合成机油,只要我不失业的话,我电话13918969263

TA的精华主题

TA的得分主题

 楼主| 发表于 2020-5-2 10:51 | 显示全部楼层
zpy2 发表于 2020-4-30 13:50
应该是没有权限或官方接口,只好自己抓包分析提交。。

是的,老美没给中国员工操作数据库的权限

TA的精华主题

TA的得分主题

 楼主| 发表于 2020-5-2 11:06 | 显示全部楼层
HHAAMM 发表于 2020-4-30 23:29
html标签,一般都有name属性和id属性,name属性是可以重复的,有时候不能准确定位,id属性是不能重复的,所 ...

谢谢大神的回复和指点。一来这是美国总部10年前的系统,而且以前公司专门有负责数据录入的人,这两年外企日子艰难雇不起数据录入的人了,所以最近数据上传成了大问题;另外,这个系统做的比较变态,这些输入框的个数是不固定的,所以名称也是动态的:比如:A品牌的机油这次需要进行6项测试,系统默认是4行,我们点击下面的“Add Test" button,可以增加至6项;如果某个机油样品只需要测3项,只需要录入3项数据即可。最后,我也没有html的基础,F12找了半天也没发现这些包含这些input 的代码

TA的精华主题

TA的得分主题

 楼主| 发表于 2020-5-2 11:12 | 显示全部楼层
话说,有没有上海的兄弟们,约起来,我带着电脑,带着钱,带着机油,带着诚意去求救?

TA的精华主题

TA的得分主题

 楼主| 发表于 2020-5-2 11:32 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
不怕各位笑话,找了两天,没找到包含这些input 文本框或单选框的源代码; IE中按F12,只出现了三段比较短的小程序,而且公司的系统需要VPN 连到美国内网,所以没法发给大家测试。

没发现包含文本框的源码

没发现包含文本框的源码

测试用输入框

测试用输入框

VPN的网址

VPN的网址

点评

找个页面分析工具或抓包工具,不过不懂html也不行,原本问题不难。  发表于 2020-5-2 23:46

TA的精华主题

TA的得分主题

 楼主| 发表于 2020-5-2 11:50 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
deadzlq 发表于 2020-4-30 14:00
F12 查看Request 构造参数 Post

弱弱的问,是不是这样来查看Request参数?能不能给个示例教程或介绍?
我原来一直在debugger里面看,刚才看了一下发现很多有用的信息都在网络按钮中。PS:这个系统不支持在Chrome上查看,所以我只能用IE。
Capture6.JPG

TA的精华主题

TA的得分主题

 楼主| 发表于 2020-6-23 11:39 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
zpy2 发表于 2020-5-3 17:57
八仙过海各显神通,只要抓住老鼠就是好猫。
不管是那种方法,能解决问题就是好方法。

看到这么多大佬关注,还是很感动。花了两周时间学习了一下Python和Selenium,后来发现公司电脑不让安装Python(需要全球Tech Director approve);只好退而求其次研究了一下DOM和老掉牙的对IE编程。基本解决了我的所有诉求,废话少说,直接上代码。
  1. '---------------Fill Page 2---------------------------------------------------


  2. Sub fill_GBTRS_P2()
  3.     Dim Cols(8) As Integer, i%, j%, RowLen%, ColsLen%, BORows%, BOCols%
  4.     Dim ObjChkbtn As Object, d As Object
  5.     Dim mShellwindows As New ShellWindows
  6.     Dim objIE As InternetExplorer
  7.     Dim objFrame As FramesCollection
  8.     Dim objDOC As HTMLDocument
  9.     Dim Gbtrs_frm As Object, MyTable As Object, MySelect As Object
  10.     Dim TestArr
  11.     Dim isSelect As Boolean, IEOpen As Boolean
  12.     Dim Address As String, rng1 As Range
  13.     Dim BOSum As Double
  14.    
  15.     Address = Selection.Address
  16.     isSelect = False
  17.     Erase Cols
  18.     i = 4
  19.     Application.ScreenUpdating = False
  20.    
  21. '=======================connect with the opened GBTRS page===================================================
  22.     IEOpen = False
  23.     For Each objIE In mShellwindows
  24.         If objIE.LocationURL = "http://pap/" Then
  25.             IEOpen = True
  26.             Exit For
  27.         End If
  28.     Next
  29.     If Not IEOpen Then
  30.         MsgBox "Please Use Internet Explorer to open the PAP system.  " & Chr(10) & Chr(10) & _
  31.         "This tool only support IE, use IE to open the work order Page 1! ", vbCritical, "Open IE First, Exit now"
  32.         Exit Sub
  33.     End If
  34.     While objIE.Busy = True Or objIE.readyState <> 4
  35.         DoEvents
  36.     Wend
  37.     Set objFrame = objIE.document.frames
  38.     Set objDOC = objFrame("LZMain").document
  39.     Set Gbtrs_frm = objDOC.frames("BrowseArea").document
  40.    

  41. '===================------------------------------select group tests by checkbox-----------------------------------============================
  42.     With ActiveSheet
  43.         For Each ObjChkbtn In .OLEObjects   'shapes("group").groupitems
  44.             If TypeName(ObjChkbtn.Object) = "CheckBox" Then
  45.                 If ObjChkbtn.Object.Value = True Then
  46.                     Cols(i) = CInt(Right(ObjChkbtn.Name, 1)) + 3
  47.                     isSelect = True
  48.                 End If
  49.                 i = i + 1
  50.             End If
  51.         Next ObjChkbtn
  52.     End With
  53.     If Not isSelect Then Cols(4) = 4
  54.    
  55.     TestArr = ThisWorkbook.Worksheets("Sheet1").ListObjects("Tests").Range
  56.     Set d = CreateObject("scripting.Dictionary")
  57.    
  58.     For i = 2 To UBound(TestArr)
  59.         isSelect = False
  60.         For j = 4 To UBound(Cols)
  61.             If Cols(j) > 1 Then
  62.                 If TestArr(i, Cols(j)) * 1 = 1 Then
  63.                     isSelect = True
  64.                     Exit For
  65.                 End If
  66.             End If
  67.         Next j
  68.         If isSelect Then d(TestArr(i, 1)) = TestArr(i, 2) & StrLink & TestArr(i, 3)    '---------put selected tests into dictionary
  69.     Next i
  70.     Erase TestArr
  71.     TestArr = d.keys
  72.         
  73.    
  74.     If ThisWorkbook.ActiveSheet.Cells(100, 100) <> RRFlag And Len(Cells(100, 100)) = 0 Then '====Locate Base Oil Table===========
  75.         '--------------------计算基础油行数,配方列,添加剂首行等参数
  76.         Application.ScreenUpdating = True   '===================select data area=====================================
  77.         On Error Resume Next
  78.         Set rng1 = Application.InputBox("Please select ALL Base Oils in Column A", "Select All Base Oils", Address, , , , , Type:=8)
  79. '        Set rng2 = Application.InputBox("Please select torque reduction data columns at the same row as before", "Select results", Address, , , , , Type:=8)
  80.         On Error GoTo 0
  81.         
  82.         If Not rng1 Is Nothing Then
  83.             BORows = rng1.Rows.Count
  84.             BOCols = 2
  85.             Do While WorksheetFunction.CountA(ActiveSheet.ListObjects("myFormulation").DataBodyRange.Columns(BOCols + 1)) > 2
  86.                 BOCols = BOCols + 1
  87.             Loop
  88.             Set MyTable = Gbtrs_frm.getElementById("newblendstable")
  89.             RowLen = MyTable.Rows.Length
  90.             ColsLen = MyTable.Rows(0).Cells.Length
  91.             If BOCols > ColsLen - 5 Then BOCols = ColsLen - 4
  92.             Set rng1 = rng1.Resize(, BOCols)
  93.             Do While RowLen - 3 < BORows
  94.                 MyTable.Rows(RowLen - 2).Cells(0).Children(0).Click
  95.                 myDelay 0.2
  96.                 RowLen = RowLen + 2
  97.             Loop
  98.             For j = 1 To BOCols
  99.                 If j > 1 Then BOSum = WorksheetFunction.Sum(rng1.Columns(j))
  100.                 For i = 1 To BORows         '====================================fill baseoil part 基础油部分=======================================
  101.                     If Len(rng1(i, j)) > 0 Then
  102.                         If j = 1 Or BOSum = 100 Then
  103.                             MyTable.Rows(i).Cells(j).Children(0).Value = rng1(i, j)
  104.                         Else
  105.                             MyTable.Rows(i).Cells(j).Children(0).Value = Format(100 * rng1(i, j) / BOSum, "0.00")
  106.                         End If
  107.                     End If
  108.                 Next i
  109.             Next j
  110.             Set MyTable = Nothing
  111.         End If
  112.         
  113.         Set rng1 = Nothing
  114.         On Error Resume Next
  115.         Do
  116.             Set rng1 = Application.InputBox("Please select ALL Components in Column A", "Select All Components", Address, , , , , Type:=8)
  117.             DoEvents
  118.         Loop Until Not rng1 Is Nothing
  119.         On Error GoTo 0
  120.         Application.ScreenUpdating = False
  121.         
  122.         BORows = rng1.Rows.Count
  123.         BOCols = 2
  124.         Do While WorksheetFunction.CountA(ActiveSheet.ListObjects("myFormulation").DataBodyRange.Columns(BOCols + 1)) > 2
  125.             BOCols = BOCols + 1
  126.         Loop
  127.         Set MyTable = Gbtrs_frm.getElementById("newcompstable")   'getElementsByTagName("table")(1)  单剂部分
  128.         RowLen = MyTable.Rows.Length
  129.         ColsLen = MyTable.Rows(1).Cells.Length
  130.         If BOCols > ColsLen - 4 Then BOCols = ColsLen - 3
  131.         Set rng1 = rng1.Resize(, BOCols)
  132.         If BORows > RowLen - 4 Then Gbtrs_frm.parentWindow.execScript "morelines('newcompstable','comp'," & RowLen - 3 & "," & BORows - RowLen + 4 & ")", "JScript"
  133.         myDelay 0.3
  134.         For i = 1 To BORows '====================================fill ocmponents part=======================================
  135.             For j = 1 To BOCols
  136.                 If Len(rng1(i, j)) > 0 Then MyTable.Rows(i).Cells(j).Children(0).Value = rng1(i, j)
  137.             Next j
  138.         Next i
  139.         Set MyTable = Nothing
  140.         Set rng1 = Nothing
  141.     End If
  142.         
  143.     Set MyTable = Gbtrs_frm.getElementById("nonshivatable")   '====------------------Locate test items Table 测试部分----------------===========
  144.     RowLen = MyTable.Rows.Length
  145.     ColsLen = MyTable.Rows(1).Cells.Length
  146.     BORows = d.Count
  147.     If BORows > RowLen - 4 Then Gbtrs_frm.parentWindow.execScript "morelines('nonshivatable','nonperf'," & RowLen - 3 & "," & BORows - RowLen + 6 & ")", "JScript"
  148.     myDelay 0.3
  149.    
  150.     For i = 1 To BORows
  151.         Set MySelect = MyTable.Rows(i).Cells(0).Children(4)
  152. '        MySelect.selectedIndex = 5
  153.         MySelect.Value = "TPV00000R=10"
  154.         MySelect.FireEvent "onchange"
  155.         myDelay 0.1
  156.         
  157.         With MyTable.Rows(i).Cells(0)
  158.             .Children(0).Value = TestArr(i - 1)
  159.             .Children(2).Value = Split(d(TestArr(i - 1)), StrLink)(0)
  160.             .Children(3).Value = Split(d(TestArr(i - 1)), StrLink)(1)
  161.         End With
  162.         
  163.     Next i
  164.     Application.ScreenUpdating = True
  165.     MsgBox "Successfully fill all the data into the system", vbOKOnly
  166.     Set MyTable = Nothing
  167.     Set rng1 = Nothing
  168. End Sub
复制代码

评分

1

查看全部评分

TA的精华主题

TA的得分主题

 楼主| 发表于 2020-6-23 11:45 | 显示全部楼层
zpy2 发表于 2020-5-3 17:57
八仙过海各显神通,只要抓住老鼠就是好猫。
不管是那种方法,能解决问题就是好方法。

代码已上传,几点体会:
1.        F12开发工具的元素选择(小箭头)是个好东西,点一下基本可以找到所有想要搜素的元素的名称和继承关系
2.        Html网页中表格的遍历方法,及表格中输入框、选择框的选择方法children或childnodes表示可以简化程序;
3.        多个Frame跳转的技术
4.        执行html文件中某个元素事件的方法 fire event
5.        调用网页中已有的javascript方法,参数用单引号
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-27 23:51 , Processed in 0.050056 second(s), 16 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表