Skip to content

Commit

Permalink
Updated Excel Create Dataset and added sample for looping dataset sau…
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepleez committed Jan 13, 2020
1 parent 4913df5 commit c801667
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public BeginExcelDatasetLoopCommand()
{
this.CommandName = "BeginExcelDataSetLoopCommand";
this.SelectionName = "Loop Excel Dataset";
this.CommandEnabled = true;
//this command is no longer required as list loop can successfully loop.
this.CommandEnabled = false;
this.CustomRendering = true;
}

Expand Down
14 changes: 12 additions & 2 deletions taskt/Core/Automation/Commands/ExcelCreateDataSetCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,29 @@ public class ExcelCreateDataSetCommand : ScriptCommand
[Attributes.PropertyAttributes.Remarks("")]
public string v_SheetName { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Indicate if Header Row Exists")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Yes")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("No")]
[Attributes.PropertyAttributes.InputSpecification("Select the necessary indicator")]
[Attributes.PropertyAttributes.SampleUsage("Select **Yes**, **NO**. Data will be loaded as column headers if **YES** is selected.")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_ContainsHeaderRow { get; set; }

public ExcelCreateDataSetCommand()
{
this.CommandName = "ExcelCreateDatasetCommand";
this.SelectionName = "Create Dataset";
this.CommandEnabled = true;
this.CustomRendering = true;
v_ContainsHeaderRow = "Yes";
}

public override void RunCommand(object sender)
{

DatasetCommands dataSetCommand = new DatasetCommands();
DataTable requiredData = dataSetCommand.CreateDataTable(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + v_FilePath + @";Extended Properties=""Excel 12.0;HDR=No;IMEX=1""", "Select * From [" + v_SheetName + "$]");
DataTable requiredData = dataSetCommand.CreateDataTable(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + v_FilePath.ConvertToUserVariable(sender) + $@";Extended Properties=""Excel 12.0;HDR={v_ContainsHeaderRow.ConvertToUserVariable(sender)};IMEX=1""", "Select * From [" + v_SheetName.ConvertToUserVariable(sender) + "$]");

var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;

Expand All @@ -70,7 +80,7 @@ public override List<Control> Render(frmCommandEditor editor)
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataSetName", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_FilePath", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_SheetName", this, editor));

RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_ContainsHeaderRow", this, editor));
return RenderedControls;

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Script xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Commands>
<ScriptAction>
<ScriptCommand xsi:type="CommentCommand" CommandID="f3a14099-21a7-43d4-8362-a2c063e63799" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="1" PauseBeforeExeucution="false" v_Comment="Open Worksheet and Pull Dataset. Sample DataSet used Below." CommandEnabled="true" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="CommentCommand" CommandID="1d340af1-0819-492d-b94f-03fa695e8119" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="2" PauseBeforeExeucution="false" v_Comment="A B&#xD;&#xA;name&#x9;color&#xD;&#xA;Jason&#x9;Red&#xD;&#xA;John&#x9;Blue&#xD;&#xA;Tom&#x9;Green&#xD;&#xA;" CommandEnabled="true" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="ExcelCreateDataSetCommand" CommandID="85ff8a9d-3364-4db9-9594-dc1f883a53cd" CommandName="ExcelCreateDatasetCommand" IsCommented="false" SelectionName="Create Dataset" DefaultPause="0" LineNumber="3" PauseBeforeExeucution="false" CommandEnabled="true" v_DataSetName="vExcelDS" v_FilePath="D:\Dropbox\Environment Folders\Desktop\test2.xlsx" v_SheetName="Sheet1" v_ContainsHeaderRow="Yes" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="CommentCommand" CommandID="edb775f6-57f1-420d-a655-951b1b11ac0b" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="4" PauseBeforeExeucution="false" v_Comment="Loop each row" CommandEnabled="true" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="BeginListLoopCommand" CommandID="0d36938d-6529-4e3c-b3ef-9dd938b4e5bb" CommandName="BeginListLoopCommand" IsCommented="false" SelectionName="Loop List" DefaultPause="0" LineNumber="5" PauseBeforeExeucution="false" CommandEnabled="true" v_LoopParameter="vExcelDS" />
<AdditionalScriptCommands>
<ScriptCommand xsi:type="CommentCommand" CommandID="820b8929-4c66-4e33-8656-c90604ce5476" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="6" PauseBeforeExeucution="false" v_Comment="Calling by {datasetName} will return array. This can additionally be parsed by &quot;Parse Json Array&quot; command." CommandEnabled="true" />
</AdditionalScriptCommands>
<AdditionalScriptCommands>
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="f3019daa-775b-4d00-85c8-f7c801b75596" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="7" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="{vExcelDS}" v_AutoCloseAfter="0" />
</AdditionalScriptCommands>
<AdditionalScriptCommands>
<ScriptCommand xsi:type="CommentCommand" CommandID="0e74779c-34a7-4677-a5ce-d6038e75dde2" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="8" PauseBeforeExeucution="false" v_Comment="Items can be pulled by column index" CommandEnabled="true" />
</AdditionalScriptCommands>
<AdditionalScriptCommands>
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="c5445d7e-772f-4906-8335-c1b6678889fc" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="9" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="{vExcelDS.0}" v_AutoCloseAfter="0" />
</AdditionalScriptCommands>
<AdditionalScriptCommands>
<ScriptCommand xsi:type="CommentCommand" CommandID="9d10da57-5f39-41dc-9499-bafc58e93534" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="10" PauseBeforeExeucution="false" v_Comment="Items can be pulled by column name (If Header = Yes)" CommandEnabled="true" />
</AdditionalScriptCommands>
<AdditionalScriptCommands>
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="5c7cab75-cfd0-496f-88d3-6e6fadd1a916" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="11" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="{vExcelDS.Name}" v_AutoCloseAfter="0" />
</AdditionalScriptCommands>
<AdditionalScriptCommands>
<ScriptCommand xsi:type="CommentCommand" CommandID="dc649501-79b8-4b9f-b552-f21871c7838a" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="12" PauseBeforeExeucution="false" v_Comment="Items can be pulled by column index (second column index)" CommandEnabled="true" />
</AdditionalScriptCommands>
<AdditionalScriptCommands>
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="0f54aef0-59ad-4690-b8db-1034640b3308" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="13" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="{vExcelDS.1}" v_AutoCloseAfter="0" />
</AdditionalScriptCommands>
<AdditionalScriptCommands>
<ScriptCommand xsi:type="CommentCommand" CommandID="8ec67541-7fb1-4a63-8fb7-07c6d4f3510a" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="14" PauseBeforeExeucution="false" v_Comment="Items can be pulled by column name (If Header = Yes)" CommandEnabled="true" />
</AdditionalScriptCommands>
<AdditionalScriptCommands>
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="4f888d9b-9fad-4399-857e-039c65010281" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="15" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="{vExcelDS.Color}" v_AutoCloseAfter="0" />
</AdditionalScriptCommands>
<AdditionalScriptCommands>
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="c84ccce3-ccec-4d2c-b6f3-f357bdacb5be" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="16" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="{vExcelDS =&gt;$.[0]}" v_AutoCloseAfter="0" />
</AdditionalScriptCommands>
<AdditionalScriptCommands>
<ScriptCommand xsi:type="CommentCommand" CommandID="e63dfa71-a242-4361-a139-a959e4476e76" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="17" PauseBeforeExeucution="false" v_Comment="Items in this section will run within the loop" CommandEnabled="true" />
</AdditionalScriptCommands>
<AdditionalScriptCommands>
<ScriptCommand xsi:type="EndLoopCommand" CommandID="3b8469d3-894d-4cb4-af78-bb30111dbc00" CommandName="EndLoopCommand" IsCommented="false" SelectionName="End Loop" DefaultPause="0" LineNumber="18" PauseBeforeExeucution="false" CommandEnabled="true" />
</AdditionalScriptCommands>
</ScriptAction>
</Commands>
<Variables />
</Script>

0 comments on commit c801667

Please sign in to comment.