Skip to content

Commit dfed68b

Browse files
committed
ExcelGetRangeCommand second cell is optional
1 parent 3744451 commit dfed68b

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

taskt/Core/Automation/Commands/ExcelGetRangeCommand .cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ public override void RunCommand(object sender)
6060

6161
Microsoft.Office.Interop.Excel.Application excelInstance = (Microsoft.Office.Interop.Excel.Application)excelObject;
6262
Microsoft.Office.Interop.Excel.Worksheet excelSheet = excelInstance.ActiveSheet;
63-
var cellValue = excelSheet.Range[targetAddress1, targetAddress2];
63+
Microsoft.Office.Interop.Excel.Range cellValue;
64+
if (targetAddress2 != "")
65+
cellValue = excelSheet.Range[targetAddress1, targetAddress2];
66+
else
67+
{
68+
Microsoft.Office.Interop.Excel.Range last = excelSheet.Cells.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell, Type.Missing);
69+
cellValue = excelSheet.Range[targetAddress1, last];
70+
}
6471

6572
List<object> lst = new List<object>();
6673
int rw = cellValue.Rows.Count;
@@ -85,7 +92,6 @@ public override void RunCommand(object sender)
8592

8693
}
8794
string output = String.Join(",", lst);
88-
v_ExcelCellAddress1 = output;
8995

9096
//Store Strings of comma seperated values into user variable
9197
output.StoreInUserVariable(sender, v_userVariableName);

taskt/Core/Automation/Commands/ExcelGetRangeCommandASDT.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class ExcelGetRangeCommandAsDT : ScriptCommand
4040
[Attributes.PropertyAttributes.Remarks("")]
4141
public string v_Output { get; set; }
4242
[XmlAttribute]
43-
[Attributes.PropertyAttributes.PropertyDescription("Please Enter the Second Cell Location (ex. A1 or B2)")]
43+
[Attributes.PropertyAttributes.PropertyDescription("Please Enter the Second Cell Location (ex. A1 or B2, Optional)")]
4444
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
4545
[Attributes.PropertyAttributes.InputSpecification("Enter the actual location of the cell.")]
4646
[Attributes.PropertyAttributes.SampleUsage("A1, B10, [vAddress]")]
@@ -73,7 +73,16 @@ public override void RunCommand(object sender)
7373

7474
Microsoft.Office.Interop.Excel.Application excelInstance = (Microsoft.Office.Interop.Excel.Application)excelObject;
7575
Microsoft.Office.Interop.Excel.Worksheet excelSheet = excelInstance.ActiveSheet;
76-
var cellValue = excelSheet.Range[targetAddress1, targetAddress2];
76+
Microsoft.Office.Interop.Excel.Range cellValue;
77+
if (targetAddress2 != "")
78+
cellValue = excelSheet.Range[targetAddress1, targetAddress2];
79+
else
80+
{
81+
Microsoft.Office.Interop.Excel.Range last = excelSheet.Cells.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell, Type.Missing);
82+
cellValue = excelSheet.Range[targetAddress1, last];
83+
}
84+
85+
7786
if (v_Output == "Datatable")
7887
{
7988

@@ -142,7 +151,6 @@ public override void RunCommand(object sender)
142151

143152
}
144153
string output = String.Join(",", lst);
145-
v_ExcelCellAddress1 = output;
146154

147155
//Store Strings of comma seperated values into user variable
148156
output.StoreInUserVariable(sender, v_userVariableName);

0 commit comments

Comments
 (0)