If it is a simple excel spreadsheet, then you can “Save As” and change the file type to “XML Spreadsheet 2003” .xml. This following code is referencing a spreadsheet of 2 columns and 4 rows. Column 1 has names and column 2 has numbers. Good luck!
<abs contexttype="opengear" style="">
<meta>
<params>
<param access="1" constrainttype="INT_NULL" name="elementsFound" oid="elementsFound" precision="0" type="INT16" value="8" widget="default"/>
<param access="1" maxlength="0" name="finalReturnedXML" oid="finalReturnedXML" precision="0" type="STRING_ARRAY" value="Bob;76;Tom;52;Larry;64;Mike;23" widget="default">
<value>Bob</value>
<value>76</value>
<value>Tom</value>
<value>52</value>
<value>Larry</value>
<value>64</value>
<value>Mike</value>
<value>23</value>
</param>
<param access="1" maxlength="0" name="returnedString" oid="returnedString" type="STRING" value="Mike 23" widget="text-display"/>
<param access="1" maxlength="0" name="searchName" oid="searchName" type="STRING" value="Mike" widget="text"/>
</params>
</meta>
<tab height="595" left="5" top="6" width="641">
<abs id="RepSearch" name="RepSearch">
<button buttontype="push" height="38" id="GetReps" left="486" name="Get Reps" top="25" width="114">
<task tasktype="ogscript">var xmlPath = "file:///C:/DashBoard/Practice_Panel_01/searchWidget/RepList.xml"; //this defines the path of the xml file
var testXML = ogscript.parseXML(xmlPath); //this variable stores all the parsed xml in Dashboard
// check parse worked
if (testXML == null) {
// if parse failed debug msg
ogscript.debug('Failed to read file');
} else {
// if parse worked
ogscript.debug('Parsing XML');
var Tags = "Data"; //this sets the search string
var searchName = params.getValue('searchName', 0); //set search name
var dataTags = testXML.getElementsByTagName(Tags); // seperates the testXML data by the searchTag(s) in an array called dataTags.
if (dataTags.length == 0)
{
// if parse failed debug msg
ogscript.debug('Failed to find that tag');
} else {
ogscript.debug("items found: " + dataTags.length); // degub msg dataTags array length
params.setValue('elementsFound', 0, dataTags.length); // set param, elementsFound, to dataTags length
var myString = " "; //create an empty string to later add our results to
var NamesNums = new Array();
// loop through dataTags array and return only text content in new array,
for (xmlData = 0; xmlData < dataTags.length; xmlData++) {
var node = dataTags.item(xmlData); //making variable of the current node for this loop through the dataTags array
var xmlDataTagsText = node.getTextContent(); // making variable for the Text Content in this node
ogscript.debug("No. " + xmlData + " contains: " + xmlDataTagsText); // debug msg for Text value returned
NamesNums[xmlData] = xmlDataTagsText;
params.setValue('finalReturnedXML', xmlData, xmlDataTagsText); // set a finalReturnedXML param value for text returned in dataTag
myString += xmlDataTagsText + ', '; //appending current node's text content to our outputstring
}
//params.setValue('returnedString', 0, myString); //output string to output textbox
for (index = 0; index < dataTags.length; index++)
{
if (NamesNums[index] == searchName)
{
var adjust = index + 1;
var results = NamesNums[index] + " " + NamesNums[adjust];
params.setValue('returnedString', 0, results); //output string to output textbox
}
}
}
}</task>
</button>
<param expand="true" height="315" left="70" oid="finalReturnedString" top="98" width="273"/>
<param expand="true" height="277" left="226" oid="returnedString" top="187" width="273"/>
<param expand="true" height="46" left="227" oid="searchName" top="122" width="172"/>
<label height="40" left="128" name="Search name:" style="txt-align:west" top="127" width="92"/>
<label height="40" left="129" name="Results:" style="txt-align:west;" top="199" width="90"/>
</abs>
</tab>
</abs>
#DashBoard