通过Excel VBA进行IE11自动化-提取表数据

时间:2018-07-02 01:10:56

标签: html excel-vba internet-explorer-11 vba excel

这是我的原始帖子herehere的第3部分。因此,现在登录后,就可以单击LH端的Current现状(在Supervisor下面)。现在显示该表,我想从中提取数据(每一行,每一列)。该图显示了表单结构。

Table

数据表深埋在HTML中。如何遍历表的所有行和列,并将结果粘贴到excel单元格中?例如,我想将“ Not_Scheduled”粘贴到excel中(该值在员工上岗的全天都会改变)。

我已经尝试了以下方法来运气不佳:

myWindow.document.getElementById("frameMainMenu").contentWindow.document.getElementById("frameTabs").contentWindow.document.getelmentbyid("divTabVarsGrid")

<FRAMESET id=framesetMain frameSpacing=3 frameBorder=1 cols="200px, *"><FRAME id=frameMainMenu src="../NoSSL/MainMenu.asp" name=frameMainMenu><FRAME id=frameMainForm src="../NoSSL/Redirection.asp" name=frameMainForm scrolling=no>
<FRAME id=frameTabs noResize src="../NoSSL/CurrentSituation.asp?THEFRM=CS" scrolling=no>

<BODY onresize=ResizeDB(); id=idBody onload=OnLoadFuncs(); style="CURSOR: default" bottomMargin=0 leftMargin=0 topMargin=0 scroll=no rightMargin=0 onunload="" marginheight="0" marginwidth="0"><FORM style="VISIBILITY: visible" method=post name=CurrentSituation action=../NoSSL/CurrentSituation.asp?THEFRM=CurrentSituation><INPUT id=hiddenFormName type=hidden value=../NoSSL/CurrentSituation.asp name=hiddenFormName>
<SCRIPT language=JavaScript src="../javascript/KBADHTMLTabs.js"></SCRIPT>
 <LINK rel=StyleSheet href="../styles/KBADHTMLTabs.css">
<SCRIPT language=javascript>
var tabSet = new CDHTMLTabSet('DBTabSet');
tabSet.set3DPane(true);
tabSet.add(' Current Situation  ', 'JavaScript:DashBoardTab("CS");', true);
tabSet.add(' Unusual Time  ', 'JavaScript:DashBoardTab("UT");', false);
tabSet.add(' Time Card Review  ', 'JavaScript:DashBoardTab("TR");', false);
tabSet.add(' Time off Scheduling  ', 'JavaScript:DashBoardTab("TS");', false);
tabSet.add(' History/Attendance  ', 'JavaScript:DashBoardTab("HA");', false);
tabSet.add(' Labor Review  ', 'JavaScript:DashBoardTab("LR");', false);
tabSet.write();
</SCRIPT>

<DIV id=divTabVarsGrid style="OVERFLOW: hidden; HEIGHT: 223px; WIDTH: 701px; POSITION: relative"><INPUT type=hidden value=" Zoom In" name=strZoomIn> <INPUT type=hidden value=" Zoom Out" name=strZoomOut> <INPUT type=hidden value=" Print" name=strPrint> <INPUT type=hidden value=" Close" name=strClose> <INPUT type=hidden value=" Click to Sort Table on This Column" name=strSortColumHeader>
<SCRIPT language=javascript src="../javascript/KBADHTMLToolbar.js"></SCRIPT>

<SCRIPT language=javascript>
var theToolBar = GetMenuToolbar();
 if (theToolBar) 
 {
	theToolBar.removeButtons();
	theToolBar.addButton('butRefresh', 'Refresh', 'Refresh', 'RefreshSelection(\'CS\');', '../images/refresh.gif');
	theToolBar.addButton('butClear', 'Clear', 'Clear','Clear(\'CS\');' , '../images/clear.gif');
	theToolBar.addButton('butSelAll', 'Sel All Emps', 'Sel All Emps', 'SelAllRows()', '../images/emps.gif');
	var aButton = GetMenuToolbar().getButton('butSelAll');
	aButton.buttonPressed = false;
	aButton.setButtonType(CDHTMLToolbarButton.c_buttonTypeModal);
	theToolBar.addButton('butDetail', 'Details', 'Details', 'Details(\'CS\');', '../images/details.gif');
	theToolBar.addButton('butPostEvent', 'Post Event', 'Post Event', 'GetWndDBHeader().PostEvent();', '../images/new.gif');
theToolBar.addButton('butSign', 'Sign', 'Sign', 'SignUnsign(\'Sign\',\'CS\');', '../images/sign.gif');
	theToolBar.addButton('butUnSign', 'Unsign', 'Unsign', 'SignUnsign(\'UnSign\',\'CS\');', '../images/unsign.gif');
	theToolBar.addButton('butPrint', 'Print', 'Print',  'Print(this);', '../images/printer_small.gif');
	theToolBar.draw();
 }
</SCRIPT>
 <INPUT type=hidden name=DataAction> <INPUT type=hidden value=cs name=tabpage> <INPUT type=hidden value=23 name=textSortByField> <INPUT type=hidden value=asc name=textSortByOrder> <INPUT type=hidden value=1 name=textUsedDefaultSort> <INPUT type=hidden value=21 name=textRowCount> <INPUT type=hidden value=1 name=textCurrPage> <INPUT type=hidden value=100 name=textEmpsPerPage> <INPUT type=hidden value=14 name=textColCount> <INPUT id=hiddenNow type=hidden value=7/1/2018 name=hiddenNow><INPUT id=hiddenNow__month type=hidden value=7 name=hiddenNowMonth><INPUT id=hiddenNow__day type=hidden value=1 name=hiddenNowDay><INPUT id=hiddenNow__year type=hidden value=2018 name=hiddenNowYear><INPUT type=hidden value=07 name=HourshiddenNow><INPUT type=hidden value=17 name=MinuteshiddenNow><INPUT type=hidden value=29 name=SecondshiddenNow><INPUT type=hidden value=PM name=PMtimehiddenNow> 
<DIV id=divPageButtons class=classPageButtons style="FONT-SIZE: 0px; HEIGHT: 4px" align=center></DIV>
<SCRIPT language=javascript>
var dataTable = new CDHTMLGrid('Grid', 'dataTable');
dataTable.setBrowserInfo('IE', 7);
dataTable.setRowSelection(true, true, true, true);
dataTable.SetMultiRowSelection(true);
dataTable.setRowDClick(true, false, false, false);
dataTable.addColumn('Emp Name', 'Emp<br>Name', 'right', 'CustomizeSorting', '', '', true, '', 0);
dataTable.addColumn('Status', 'Status', 'right', 'CustomizeSorting', '', '', true, '', 0);
dataTable.addColumn('Activity', 'Activity', 'right', 'CustomizeSorting', '', '', true, '', 0);
dataTable.addColumn('Schedule', 'Schedule', 'right', 'CustomizeSorting', '', '', true, '', 0);
dataTable.addColumn('Rounded Start', 'Rounded<br>Start', 'right', 'CustomizeSorting', '', '', true, '', 0);
dataTable.addColumn('Rounded End', 'Rounded<br>End', 'right', 'CustomizeSorting', '', '', true, '', 0);
dataTable.addColumn('Efficiency', 'Efficiency', 'right', 'CustomizeSorting', '', '', true, '', 0);
dataTable.addColumn('Warning', 'Warning', 'right', 'CustomizeSorting', '', '', true, '', 0);
dataTable.addColumn('Total Hours', 'Total<br>Hours', 'right', 'CustomizeSorting', '', '', true, '', 0);
dataTable.addColumn('Paid Hours', 'Paid<br>Hours', 'right', 'CustomizeSorting', '', '', true, '', 0);
dataTable.addColumn('Unpaid Hours', 'Unpaid<br>Hours', 'right', 'CustomizeSorting', '', '', true, '', 0);
dataTable.addColumn('Emp Signed', 'Emp<br>Signed', 'right', 'CustomizeSorting', '', '', true, '', 0);
dataTable.addColumn('Sup Signed', 'Sup<br>Signed', 'right', 'CustomizeSorting', '', '', true, '', 0);
var dataRows = new Array();
dataRows[0] = new Array();
dataRows[0][0] = '<A id=aEmpName HREF=\'CurrentSituation.asp?DataAction=Details&EMPNUM=00813510\'>Joseph A Ordasz</A>&nbsp;';
dataRows[0][1] = 'NOT_SCHEDULED';
dataRows[0][2] = '&nbsp;';
dataRows[0][3] = '&nbsp;';
dataRows[0][4] = '<DIV></DIV>';
dataRows[0][5] = '<DIV></DIV>';
dataRows[0][6] = '0%&nbsp;';
dataRows[0][7] = '&nbsp;&nbsp;';
dataRows[0][8] = '0.00&nbsp;';
dataRows[0][9] = '0.00&nbsp;';
dataRows[0][10] = '0.00&nbsp;';
dataRows[0][11] = '&nbsp;&nbsp;';
dataRows[0][12] = '&nbsp;&nbsp;';
dataRows[0][14] = '00813510';
dataRows[1] = new Array();
dataRows[1][0] = '<A id=aEmpName HREF=\'CurrentSituation.asp?DataAction=Details&EMPNUM=00821191\'>Rajan   Mathew</A>&nbsp;';
dataRows[1][1] = 'NOT_SCHEDULED';
dataRows[1][2] = '&nbsp;';
dataRows[1][3] = '&nbsp;';
dataRows[1][4] = '<DIV></DIV>';
dataRows[1][5] = '<DIV></DIV>';
dataRows[1][6] = '0%&nbsp;';
dataRows[1][7] = '&nbsp;&nbsp;';
dataRows[1][8] = '0.00&nbsp;';
dataRows[1][9] = '0.00&nbsp;';
dataRows[1][10] = '0.00&nbsp;';
dataRows[1][11] = '&nbsp;&nbsp;';
dataRows[1][12] = '&nbsp;&nbsp;';
dataRows[1][14] = '00821191';
dataRows[2] = new Array();
dataRows[2][0] = '<A id=aEmpName HREF=\'CurrentSituation.asp?DataAction=Details&EMPNUM=00821638\'>Elena   Gonzalez</A>&nbsp;';
dataRows[2][1] = 'NOT_SCHEDULED';
dataRows[2][2] = '&nbsp;';
dataRows[2][3] = '&nbsp;';
dataRows[2][4] = '<DIV></DIV>';
dataRows[2][5] = '<DIV></DIV>';
dataRows[2][6] = '0%&nbsp;';
dataRows[2][7] = '&nbsp;&nbsp;';
dataRows[2][8] = '0.00&nbsp;';
dataRows[2][9] = '0.00&nbsp;';
dataRows[2][10] = '0.00&nbsp;';
dataRows[2][11] = '&nbsp;&nbsp;';
dataRows[2][12] = '&nbsp;&nbsp;';
dataRows[2][14] = '00821638';
dataTable.setData(dataRows);
dataTable.setDataReport(dataRows);
dataTable.setReportTitle('Current Situation');
dataTable.write(true);
dataTable.resize(true);
var m_bOverrideUnload = false;
</SCRIPT>

<SCRIPT language=javascript>
 NoWaitCursorDashboard ();
</SCRIPT>

0 个答案:

没有答案