From 879ddf723d8904e084c2bc5f58af3fd3508b7f30 Mon Sep 17 00:00:00 2001 From: Francesca Faerman Date: Mon, 16 Mar 2020 11:41:45 -0400 Subject: [PATCH 1/3] word commands --- .../Core/Automation/Commands/ScriptCommand.cs | 12 ++ .../Commands/WordAddDocumentCommand.cs | 58 +++++++ .../Commands/WordAppendDataTableCommand.cs | 151 ++++++++++++++++++ .../Commands/WordAppendImageCommand.cs | 77 +++++++++ .../Commands/WordAppendTextCommand.cs | 149 +++++++++++++++++ .../Commands/WordCloseApplicationCommand.cs | 77 +++++++++ .../WordCreateApplicationCommandcs.cs | 64 ++++++++ .../Commands/WordExportToPDFCommand.cs | 80 ++++++++++ .../Commands/WordOpenDocumentCommand.cs | 65 ++++++++ .../Commands/WordReadDocumentCommand.cs | 80 ++++++++++ .../Commands/WordReplaceTextCommand.cs | 97 +++++++++++ .../Automation/Commands/WordSaveAsCommand.cs | 79 +++++++++ .../Automation/Commands/WordSaveCommand.cs | 65 ++++++++ taskt/UI/CustomControls/CustomControls.cs | 12 ++ taskt/packages.config | 1 + taskt/taskt.csproj | 16 ++ 16 files changed, 1083 insertions(+) create mode 100644 taskt/Core/Automation/Commands/WordAddDocumentCommand.cs create mode 100644 taskt/Core/Automation/Commands/WordAppendDataTableCommand.cs create mode 100644 taskt/Core/Automation/Commands/WordAppendImageCommand.cs create mode 100644 taskt/Core/Automation/Commands/WordAppendTextCommand.cs create mode 100644 taskt/Core/Automation/Commands/WordCloseApplicationCommand.cs create mode 100644 taskt/Core/Automation/Commands/WordCreateApplicationCommandcs.cs create mode 100644 taskt/Core/Automation/Commands/WordExportToPDFCommand.cs create mode 100644 taskt/Core/Automation/Commands/WordOpenDocumentCommand.cs create mode 100644 taskt/Core/Automation/Commands/WordReadDocumentCommand.cs create mode 100644 taskt/Core/Automation/Commands/WordReplaceTextCommand.cs create mode 100644 taskt/Core/Automation/Commands/WordSaveAsCommand.cs create mode 100644 taskt/Core/Automation/Commands/WordSaveCommand.cs diff --git a/taskt/Core/Automation/Commands/ScriptCommand.cs b/taskt/Core/Automation/Commands/ScriptCommand.cs index f3ba71eae..f79ef3c1d 100644 --- a/taskt/Core/Automation/Commands/ScriptCommand.cs +++ b/taskt/Core/Automation/Commands/ScriptCommand.cs @@ -62,6 +62,18 @@ namespace taskt.Core.Automation.Commands [XmlInclude(typeof(ExcelGetLastRowCommand))] [XmlInclude(typeof(ExcelSaveAsCommand))] [XmlInclude(typeof(ExcelSaveCommand))] + [XmlInclude(typeof(WordCreateApplicationCommand))] + [XmlInclude(typeof(WordCloseApplicationCommand))] + [XmlInclude(typeof(WordOpenDocumentCommand))] + [XmlInclude(typeof(WordSaveCommand))] + [XmlInclude(typeof(WordSaveAsCommand))] + [XmlInclude(typeof(WordExportToPDFCommand))] + [XmlInclude(typeof(WordAddDocumentCommand))] + [XmlInclude(typeof(WordReadDocumentCommand))] + [XmlInclude(typeof(WordReplaceTextCommand))] + [XmlInclude(typeof(WordAppendTextCommand))] + [XmlInclude(typeof(WordAppendImageCommand))] + [XmlInclude(typeof(WordAppendDataTableCommand))] [XmlInclude(typeof(SeleniumBrowserCreateCommand))] [XmlInclude(typeof(SeleniumBrowserNavigateURLCommand))] [XmlInclude(typeof(SeleniumBrowserNavigateForwardCommand))] diff --git a/taskt/Core/Automation/Commands/WordAddDocumentCommand.cs b/taskt/Core/Automation/Commands/WordAddDocumentCommand.cs new file mode 100644 index 000000000..eafbe6abf --- /dev/null +++ b/taskt/Core/Automation/Commands/WordAddDocumentCommand.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Xml.Serialization; +using taskt.UI.CustomControls; +using taskt.UI.Forms; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("Word Commands")] + [Attributes.ClassAttributes.Description("This command adds a new Word Document.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to add a new document to a Word Instance")] + [Attributes.ClassAttributes.ImplementationDescription("This command implements Excel Interop to achieve automation.")] + public class WordAddDocumentCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] + [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + public string v_InstanceName { get; set; } + + public WordAddDocumentCommand() + { + this.CommandName = "WordAddDocumentCommand"; + this.SelectionName = "Add Document"; + this.CommandEnabled = true; + this.CustomRendering = true; + } + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + var vInstance = v_InstanceName.ConvertToUserVariable(engine); + var excelObject = engine.GetAppInstance(vInstance); + + + Microsoft.Office.Interop.Word.Application excelInstance = (Microsoft.Office.Interop.Word.Application)excelObject; + excelInstance.Documents.Add(); + + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + //create standard group controls + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor)); + + return RenderedControls; + + } + public override string GetDisplayValue() + { + return base.GetDisplayValue() + " [Instance Name: '" + v_InstanceName + "']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/WordAppendDataTableCommand.cs b/taskt/Core/Automation/Commands/WordAppendDataTableCommand.cs new file mode 100644 index 000000000..e0b216657 --- /dev/null +++ b/taskt/Core/Automation/Commands/WordAppendDataTableCommand.cs @@ -0,0 +1,151 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Xml.Serialization; +using taskt.UI.CustomControls; +using taskt.UI.Forms; +using System.Data; +using System.Linq; +using System.Text.RegularExpressions; +using Microsoft.Office.Interop.Word; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("Word Commands")] + [Attributes.ClassAttributes.Description("This command appends text to a word document.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to append text to a specific document.")] + [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] + public class WordAppendDataTableCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] + [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + public string v_InstanceName { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please indicate the DataTable Name")] + [Attributes.PropertyAttributes.InputSpecification("Enter the DataTable you would like to append.")] + [Attributes.PropertyAttributes.SampleUsage("**myData**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_DataTableName { get; set; } + + public WordAppendDataTableCommand() + { + this.CommandName = "WordAppendDataTableCommand"; + this.SelectionName = "Append DataTable"; + this.CommandEnabled = true; + this.CustomRendering = true; + } + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + var vInstance = v_InstanceName.ConvertToUserVariable(engine); + var wordObject = engine.GetAppInstance(vInstance); + var dataSetVariable = LookupVariable(engine); + + System.Data.DataTable dataTable = new System.Data.DataTable(); + dataTable = (System.Data.DataTable)dataSetVariable.VariableValue; + + //selecting the word instance and open document + Microsoft.Office.Interop.Word.Application wordInstance = (Microsoft.Office.Interop.Word.Application)wordObject; + Document wordDocument = wordInstance.ActiveDocument; + + + //converting System DataTable to Word DataTable + int RowCount = dataTable.Rows.Count; + int ColumnCount = dataTable.Columns.Count; + Object[,] DataArray = new object[RowCount + 1, ColumnCount + 1]; + + int r = 0; + for (int c = 0; c <= ColumnCount - 1; c++) + { + DataArray[r, c] = dataTable.Columns[c].ColumnName; + for (r = 0; r <= RowCount - 1; r++) + { + DataArray[r, c] = dataTable.Rows[r][c]; + } //end row loop + } //end column loop + + object collapseEnd = WdCollapseDirection.wdCollapseEnd; + dynamic docRange = wordDocument.Content; + docRange.Collapse(ref collapseEnd); + + String tempString = ""; + for (r = 0; r <= RowCount - 1; r++) + { + for (int c = 0; c <= ColumnCount - 1; c++) + { + tempString = tempString + DataArray[r, c] + "\t"; + } + } + + //appending data row text after all text/images + docRange.Text = tempString; + + //converting and formatting data table + object Separator = WdTableFieldSeparator.wdSeparateByTabs; + object Format = WdTableFormat.wdTableFormatGrid1; + object ApplyBorders = true; + object AutoFit = true; + + object AutoFitBehavior = WdAutoFitBehavior.wdAutoFitContent; + docRange.ConvertToTable(ref Separator, ref RowCount, ref ColumnCount, Type.Missing, ref Format, + ref ApplyBorders, Type.Missing, Type.Missing, Type.Missing,Type.Missing, + Type.Missing, Type.Missing, Type.Missing, ref AutoFit, ref AutoFitBehavior, Type.Missing); + + docRange.Select(); + wordDocument.Application.Selection.Tables[1].Select(); + wordDocument.Application.Selection.Tables[1].Rows.AllowBreakAcrossPages = 0; + wordDocument.Application.Selection.Tables[1].Rows.Alignment = 0; + wordDocument.Application.Selection.Tables[1].Rows[1].Select(); + wordDocument.Application.Selection.InsertRowsAbove(1); + wordDocument.Application.Selection.Tables[1].Rows[1].Select(); + + //Adding header row manually + for (int c = 0; c <= ColumnCount - 1; c++) + { + wordDocument.Application.Selection.Tables[1].Cell(1, c + 1).Range.Text = dataTable.Columns[c].ColumnName; + } + + //Formatting header row + wordDocument.Application.Selection.Tables[1].Rows[1].Select(); + wordDocument.Application.Selection.Cells.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter; + wordDocument.Application.Selection.Font.Bold = 1; + + } + + private Script.ScriptVariable LookupVariable(Core.Automation.Engine.AutomationEngineInstance sendingInstance) + { + //search for the variable + var requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == v_DataTableName).FirstOrDefault(); + + //if variable was not found but it starts with variable naming pattern + if ((requiredVariable == null) && (v_DataTableName.StartsWith(sendingInstance.engineSettings.VariableStartMarker)) && (v_DataTableName.EndsWith(sendingInstance.engineSettings.VariableEndMarker))) + { + //reformat and attempt + var reformattedVariable = v_DataTableName.Replace(sendingInstance.engineSettings.VariableStartMarker, "").Replace(sendingInstance.engineSettings.VariableEndMarker, ""); + requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == reformattedVariable).FirstOrDefault(); + } + + return requiredVariable; + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + //create standard group controls + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataTableName", this, editor)); + + return RenderedControls; + } + public override string GetDisplayValue() + { + return base.GetDisplayValue() + " ['" + v_DataTableName + "' To Instance Name: '" + v_InstanceName + "']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/WordAppendImageCommand.cs b/taskt/Core/Automation/Commands/WordAppendImageCommand.cs new file mode 100644 index 000000000..6c72d69c9 --- /dev/null +++ b/taskt/Core/Automation/Commands/WordAppendImageCommand.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Xml.Serialization; +using taskt.UI.CustomControls; +using taskt.UI.Forms; +using System.Data; +using System.Linq; +using System.Text.RegularExpressions; +using Microsoft.Office.Interop.Word; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("Word Commands")] + [Attributes.ClassAttributes.Description("This command appends text to a word document.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to append text to a specific document.")] + [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] + public class WordAppendImageCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] + [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + public string v_InstanceName { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please indicate the path to the image")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter or Select the path to the image.")] + [Attributes.PropertyAttributes.SampleUsage("C:\\temp\\myimage.png or [vTextFilePath]")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_ImagePath { get; set; } + + public WordAppendImageCommand() + { + this.CommandName = "WordAppendImageCommand"; + this.SelectionName = "Append Image"; + this.CommandEnabled = true; + this.CustomRendering = true; + } + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + var vInstance = v_InstanceName.ConvertToUserVariable(engine); + var vImagePath = v_ImagePath.ConvertToUserVariable(engine); + var wordObject = engine.GetAppInstance(vInstance); + + Microsoft.Office.Interop.Word.Application wordInstance = (Microsoft.Office.Interop.Word.Application)wordObject; + Document wordDocument = wordInstance.ActiveDocument; + + //Appends image after text/images + object collapseEnd = WdCollapseDirection.wdCollapseEnd; + Range imageRange = wordDocument.Content; + imageRange.Collapse(ref collapseEnd); + imageRange.InlineShapes.AddPicture(vImagePath, Type.Missing, Type.Missing, imageRange); + + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + //create standard group controls + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_ImagePath", this, editor)); + + return RenderedControls; + } + public override string GetDisplayValue() + { + return base.GetDisplayValue() + " ['" + v_ImagePath + "' To Instance Name: '" + v_InstanceName + "']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/WordAppendTextCommand.cs b/taskt/Core/Automation/Commands/WordAppendTextCommand.cs new file mode 100644 index 000000000..584dc78fb --- /dev/null +++ b/taskt/Core/Automation/Commands/WordAppendTextCommand.cs @@ -0,0 +1,149 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Xml.Serialization; +using taskt.UI.CustomControls; +using taskt.UI.Forms; +using System.Data; +using System.Linq; +using System.Text.RegularExpressions; +using Microsoft.Office.Interop.Word; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("Word Commands")] + [Attributes.ClassAttributes.Description("This command appends text to a word document.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to append text to a specific document.")] + [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] + public class WordAppendTextCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] + [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + public string v_InstanceName { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the Text Variable Name to Set")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter the text value that will be set.")] + [Attributes.PropertyAttributes.SampleUsage("Hello World or [vText]")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_TextToSet { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Select or Enter the text font name")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Arial")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Calibri")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Helvetica")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Times New Roman")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Verdana")] + [Attributes.PropertyAttributes.InputSpecification("Specify the font name.")] + [Attributes.PropertyAttributes.SampleUsage("Select **Arial**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_FontName { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Select or Enter the text font size")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("10")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("11")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("12")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("14")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("16")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("18")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("20")] + [Attributes.PropertyAttributes.InputSpecification("Specify the font name.")] + [Attributes.PropertyAttributes.SampleUsage("Select **14**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_FontSize { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Select Bold")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Yes")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("No")] + [Attributes.PropertyAttributes.InputSpecification("Specify whether the text font should be bold.")] + [Attributes.PropertyAttributes.SampleUsage("Select **Yes** or **No**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_FontBold { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Select Italic")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Yes")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("No")] + [Attributes.PropertyAttributes.InputSpecification("Specify whether the text font should be italic.")] + [Attributes.PropertyAttributes.SampleUsage("Select **Yes** or **No**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_FontItalic { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Select Underline")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Yes")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("No")] + [Attributes.PropertyAttributes.InputSpecification("Specify whether the text font should be underlined.")] + [Attributes.PropertyAttributes.SampleUsage("Select **Yes** or **No**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_FontUnderline { get; set; } + + public WordAppendTextCommand() + { + this.CommandName = "WordAppendTextCommand"; + this.SelectionName = "Append Text"; + this.CommandEnabled = true; + this.CustomRendering = true; + this.v_FontName = "Calibri"; + this.v_FontSize = "11"; + this.v_FontBold = "No"; + this.v_FontItalic = "No"; + this.v_FontUnderline = "No"; + } + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + var vInstance = v_InstanceName.ConvertToUserVariable(engine); + var vText = v_TextToSet.ConvertToUserVariable(engine); + var wordObject = engine.GetAppInstance(vInstance); + + Microsoft.Office.Interop.Word.Application wordInstance = (Microsoft.Office.Interop.Word.Application)wordObject; + Document wordDocument = wordInstance.ActiveDocument; + + Paragraph paragraph = wordDocument.Content.Paragraphs.Add(); + paragraph.Range.Text = vText; + paragraph.Range.Font.Name = v_FontName; + paragraph.Range.Font.Size = float.Parse(v_FontSize); + if (v_FontBold == "Yes") + paragraph.Range.Font.Bold = 1; + else paragraph.Range.Font.Bold = 0; + if (v_FontItalic == "Yes") + paragraph.Range.Font.Italic = 1; + else paragraph.Range.Font.Italic = 0; + if (v_FontUnderline == "Yes") + paragraph.Range.Font.Underline = WdUnderline.wdUnderlineSingle; + else paragraph.Range.Font.Underline = WdUnderline.wdUnderlineNone; + + paragraph.Range.InsertParagraphAfter(); + + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + //create standard group controls + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_TextToSet", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_FontName", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_FontSize", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_FontBold", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_FontItalic", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_FontUnderline", this, editor)); + + return RenderedControls; + } + public override string GetDisplayValue() + { + return base.GetDisplayValue() + " ['" + v_TextToSet + "' To Instance Name: '" + v_InstanceName + "']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/WordCloseApplicationCommand.cs b/taskt/Core/Automation/Commands/WordCloseApplicationCommand.cs new file mode 100644 index 000000000..74989ab08 --- /dev/null +++ b/taskt/Core/Automation/Commands/WordCloseApplicationCommand.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Xml.Serialization; +using taskt.UI.CustomControls; +using taskt.UI.Forms; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("Word Commands")] + [Attributes.ClassAttributes.Description("This command allows you to close Word.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to close an open instance of Word.")] + [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] + public class WordCloseApplicationCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] + [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + public string v_InstanceName { get; set; } + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Indicate if the Document should be saved")] + [Attributes.PropertyAttributes.InputSpecification("Enter a TRUE or FALSE value")] + [Attributes.PropertyAttributes.SampleUsage("'TRUE' or 'FALSE'")] + [Attributes.PropertyAttributes.Remarks("")] + public bool v_WordSaveOnExit { get; set; } + public WordCloseApplicationCommand() + { + this.CommandName = "WordCloseApplicationCommand"; + this.SelectionName = "Close Word Application"; + this.CommandEnabled = true; + this.CustomRendering = true; + } + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + + var vInstance = v_InstanceName.ConvertToUserVariable(engine); + var wordObject = engine.GetAppInstance(vInstance); + + + Microsoft.Office.Interop.Word.Application wordInstance = (Microsoft.Office.Interop.Word.Application)wordObject; + + + //check if document exists and save + if (wordInstance.Documents.Count >= 1) + { + wordInstance.ActiveDocument.Close(v_WordSaveOnExit); + } + + //close word + wordInstance.Quit(); + + //remove instance + engine.RemoveAppInstance(vInstance); + + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + //create standard group controls + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_WordSaveOnExit", this, editor)); + + return RenderedControls; + + } + public override string GetDisplayValue() + { + return base.GetDisplayValue() + " [Save On Close: " + v_WordSaveOnExit + ", Instance Name: '" + v_InstanceName + "']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/WordCreateApplicationCommandcs.cs b/taskt/Core/Automation/Commands/WordCreateApplicationCommandcs.cs new file mode 100644 index 000000000..dfcef7e36 --- /dev/null +++ b/taskt/Core/Automation/Commands/WordCreateApplicationCommandcs.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Xml.Serialization; +using taskt.UI.CustomControls; +using taskt.UI.Forms; +using Word = Microsoft.Office.Interop.Word; + +namespace taskt.Core.Automation.Commands +{ + + [Serializable] + [Attributes.ClassAttributes.Group("Word Commands")] + [Attributes.ClassAttributes.Description("This command opens the Word Application.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to launch a new instance of Word.")] + [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] + public class WordCreateApplicationCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] + [Attributes.PropertyAttributes.InputSpecification("Signifies a unique name that will represemt the application instance. This unique name allows you to refer to the instance by name in future commands, ensuring that the commands you specify run against the correct application.")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **wordInstance**")] + [Attributes.PropertyAttributes.Remarks("")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + public string v_InstanceName { get; set; } + + public WordCreateApplicationCommand() + { + this.CommandName = "WordCreateApplicationCommand"; + this.SelectionName = "Create Word Application"; + this.CommandEnabled = true; + this.CustomRendering = true; + } + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + var vInstance = v_InstanceName.ConvertToUserVariable(engine); + + + var newWordSession = new Word.Application + { + Visible = true + }; + + engine.AddAppInstance(vInstance, newWordSession); + + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + //create standard group controls + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor)); + + return RenderedControls; + + } + + public override string GetDisplayValue() + { + return base.GetDisplayValue() + " [Instance Name: '" + v_InstanceName + "']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/WordExportToPDFCommand.cs b/taskt/Core/Automation/Commands/WordExportToPDFCommand.cs new file mode 100644 index 000000000..88f55b295 --- /dev/null +++ b/taskt/Core/Automation/Commands/WordExportToPDFCommand.cs @@ -0,0 +1,80 @@ +using Microsoft.Office.Interop.Word; +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Xml.Serialization; +using taskt.UI.CustomControls; +using taskt.UI.Forms; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("Word Commands")] + [Attributes.ClassAttributes.Description("This command allows you to save an Word document.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to save a document to a file.")] + [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] + public class WordExportToPDFCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] + [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + public string v_InstanceName { get; set; } + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please indicate the path of the pdf")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter or Select the path to the file.")] + [Attributes.PropertyAttributes.SampleUsage("C:\\temp\\myfile.pdf or [vWordPDFFilePath]")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_FileName { get; set; } + + public WordExportToPDFCommand() + { + this.CommandName = "WordExportToPDFCommand"; + this.SelectionName = "Export To PDF"; + this.CommandEnabled = true; + this.CustomRendering = true; + } + public override void RunCommand(object sender) + { + //get engine context + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + + //convert variables + var vInstance = v_InstanceName.ConvertToUserVariable(engine); + var fileName = v_FileName.ConvertToUserVariable(engine); + + //get word app object + var wordObject = engine.GetAppInstance(vInstance); + + //convert object + Microsoft.Office.Interop.Word.Application wordInstance = (Microsoft.Office.Interop.Word.Application)wordObject; + Document wordDocument = wordInstance.ActiveDocument; + + object fileFormat = WdSaveFormat.wdFormatPDF; + wordDocument.SaveAs(fileName, ref fileFormat, Type.Missing, Type.Missing, + Type.Missing, Type.Missing, Type.Missing, Type.Missing, + Type.Missing, Type.Missing, Type.Missing, Type.Missing, + Type.Missing, Type.Missing, Type.Missing, Type.Missing); + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + //create standard group controls + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_FileName", this, editor)); + + return RenderedControls; + + } + + public override string GetDisplayValue() + { + return base.GetDisplayValue() + " [Save To '" + v_FileName + "', Instance Name: '" + v_InstanceName + "']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/WordOpenDocumentCommand.cs b/taskt/Core/Automation/Commands/WordOpenDocumentCommand.cs new file mode 100644 index 000000000..6e0f29b43 --- /dev/null +++ b/taskt/Core/Automation/Commands/WordOpenDocumentCommand.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Xml.Serialization; +using taskt.UI.CustomControls; +using taskt.UI.Forms; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("Word Commands")] + [Attributes.ClassAttributes.Description("This command opens an Word Document.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to open an existing Word Document.")] + [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] + public class WordOpenDocumentCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] + [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + public string v_InstanceName { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please indicate the workbook file path")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter or Select the path to the applicable file that should be opened by Excel.")] + [Attributes.PropertyAttributes.SampleUsage(@"C:\temp\myfile.docx or [vFilePath]")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_FilePath { get; set; } + public WordOpenDocumentCommand() + { + this.CommandName = "WordOpenDocumentCommand"; + this.SelectionName = "Open Document"; + this.CommandEnabled = true; + this.CustomRendering = true; + } + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + var vInstance = v_InstanceName.ConvertToUserVariable(engine); + var vFilePath = v_FilePath.ConvertToUserVariable(sender); + + var wordObject = engine.GetAppInstance(vInstance); + Microsoft.Office.Interop.Word.Application wordInstance = (Microsoft.Office.Interop.Word.Application)wordObject; + wordInstance.Documents.Open(vFilePath); + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + //create standard group controls + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_FilePath", this, editor)); + + return RenderedControls; + + } + public override string GetDisplayValue() + { + return base.GetDisplayValue() + " [Open from '" + v_FilePath + "', Instance Name: '" + v_InstanceName + "']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/WordReadDocumentCommand.cs b/taskt/Core/Automation/Commands/WordReadDocumentCommand.cs new file mode 100644 index 000000000..0104a8fff --- /dev/null +++ b/taskt/Core/Automation/Commands/WordReadDocumentCommand.cs @@ -0,0 +1,80 @@ +using Microsoft.Office.Interop.Word; +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Xml.Serialization; +using taskt.UI.CustomControls; +using taskt.UI.Forms; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("Word Commands")] + [Attributes.ClassAttributes.Description("This command allows you to save an Word document.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to save changes to a document.")] + [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] + public class WordReadDocumentCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] + [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + public string v_InstanceName { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please define where the text should be stored")] + [Attributes.PropertyAttributes.InputSpecification("Select or provide a variable from the variable list")] + [Attributes.PropertyAttributes.SampleUsage("**vSomeVariable**")] + [Attributes.PropertyAttributes.Remarks("If you have enabled the setting **Create Missing Variables at Runtime** then you are not required to pre-define your variables, however, it is highly recommended.")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + public string v_UserVariableName { get; set; } + + public WordReadDocumentCommand() + { + this.CommandName = "WordReadDocumentCommand"; + this.SelectionName = "Read Document"; + this.CommandEnabled = true; + this.CustomRendering = true; + } + public override void RunCommand(object sender) + { + //get engine context + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + + //convert variables + var vInstance = v_InstanceName.ConvertToUserVariable(engine); + + //get word app object + var wordObject = engine.GetAppInstance(vInstance); + + //convert object + Microsoft.Office.Interop.Word.Application wordInstance = (Microsoft.Office.Interop.Word.Application)wordObject; + Document wordDocument = wordInstance.ActiveDocument; + + //store text in variable + string textFromDocument = wordDocument.Content.Text; + textFromDocument.StoreInUserVariable(sender, v_UserVariableName); + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + //create standard group controls + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor)); + + RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_UserVariableName", this)); + var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_UserVariableName", this).AddVariableNames(editor); + RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_UserVariableName", this, new Control[] { VariableNameControl }, editor)); + RenderedControls.Add(VariableNameControl); + + return RenderedControls; + + } + public override string GetDisplayValue() + { + return base.GetDisplayValue() + " [Instance Name: '" + v_InstanceName + "']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/WordReplaceTextCommand.cs b/taskt/Core/Automation/Commands/WordReplaceTextCommand.cs new file mode 100644 index 000000000..346ded5f3 --- /dev/null +++ b/taskt/Core/Automation/Commands/WordReplaceTextCommand.cs @@ -0,0 +1,97 @@ +using Microsoft.Office.Interop.Word; +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Xml.Serialization; +using taskt.UI.CustomControls; +using taskt.UI.Forms; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("Word Commands")] + [Attributes.ClassAttributes.Description("This command allows you to save an Word document.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to save changes to a document.")] + [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] + public class WordReplaceTextCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please enter the instance name")] + [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + public string v_InstanceName { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please define the text to find")] + [Attributes.PropertyAttributes.InputSpecification("Enter the text you wish to find.")] + [Attributes.PropertyAttributes.SampleUsage("**findText**")] + [Attributes.PropertyAttributes.Remarks("")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + public string v_FindText { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please define the text to replace with")] + [Attributes.PropertyAttributes.InputSpecification("Enter the text you wish to replace the found text.")] + [Attributes.PropertyAttributes.SampleUsage("**replaceWithText**")] + [Attributes.PropertyAttributes.Remarks("")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + public string v_ReplaceWithText { get; set; } + + public WordReplaceTextCommand() + { + this.CommandName = "WordReplaceTextCommand"; + this.SelectionName = "Replace Text"; + this.CommandEnabled = true; + this.CustomRendering = true; + } + public override void RunCommand(object sender) + { + //get engine context + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + + //convert variables + var vInstance = v_InstanceName.ConvertToUserVariable(engine); + var vFindText = v_FindText.ConvertToUserVariable(engine); + var vReplaceWithText = v_ReplaceWithText.ConvertToUserVariable(engine); + + //get excel app object + var wordObject = engine.GetAppInstance(vInstance); + + //convert object + Microsoft.Office.Interop.Word.Application wordInstance = (Microsoft.Office.Interop.Word.Application)wordObject; + Document wordDocument = wordInstance.ActiveDocument; + Range range = wordDocument.Content; + + //replace text + Find findObject = range.Find; + findObject.ClearFormatting(); + findObject.Text = vFindText; + findObject.Replacement.ClearFormatting(); + findObject.Replacement.Text = vReplaceWithText; + + object replaceAll = WdReplace.wdReplaceAll; + findObject.Execute(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, + Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, + ref replaceAll, Type.Missing, Type.Missing, Type.Missing, Type.Missing); + + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + //create standard group controls + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_FindText", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_ReplaceWithText", this, editor)); + + return RenderedControls; + + } + public override string GetDisplayValue() + { + return base.GetDisplayValue() + " [Find: '" + v_FindText + "', Replace With: '" + v_ReplaceWithText + "', Instance Name: '" + v_InstanceName + "']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/WordSaveAsCommand.cs b/taskt/Core/Automation/Commands/WordSaveAsCommand.cs new file mode 100644 index 000000000..d33716dfb --- /dev/null +++ b/taskt/Core/Automation/Commands/WordSaveAsCommand.cs @@ -0,0 +1,79 @@ +using Microsoft.Office.Interop.Word; +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Xml.Serialization; +using taskt.UI.CustomControls; +using taskt.UI.Forms; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("Word Commands")] + [Attributes.ClassAttributes.Description("This command allows you to save an Word document.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to save a document to a file.")] + [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] + public class WordSaveAsCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] + [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + public string v_InstanceName { get; set; } + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please indicate the path of the file")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter or Select the path to the file.")] + [Attributes.PropertyAttributes.SampleUsage("C:\\temp\\myfile.docx or [vWordFilePath]")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_FileName { get; set; } + + public WordSaveAsCommand() + { + this.CommandName = "WordSaveAsCommand"; + this.SelectionName = "Save Document As"; + this.CommandEnabled = true; + this.CustomRendering = true; + } + public override void RunCommand(object sender) + { + //get engine context + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + + //convert variables + var vInstance = v_InstanceName.ConvertToUserVariable(engine); + var fileName = v_FileName.ConvertToUserVariable(engine); + + //get word app object + var wordObject = engine.GetAppInstance(vInstance); + + //convert object + Microsoft.Office.Interop.Word.Application wordInstance = (Microsoft.Office.Interop.Word.Application)wordObject; + + //overwrite and save + wordInstance.DisplayAlerts = WdAlertLevel.wdAlertsNone; + wordInstance.ActiveDocument.SaveAs(fileName); + wordInstance.DisplayAlerts = WdAlertLevel.wdAlertsAll; + + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + //create standard group controls + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_FileName", this, editor)); + + return RenderedControls; + + } + + public override string GetDisplayValue() + { + return base.GetDisplayValue() + " [Save To '" + v_FileName + "', Instance Name: '" + v_InstanceName + "']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/WordSaveCommand.cs b/taskt/Core/Automation/Commands/WordSaveCommand.cs new file mode 100644 index 000000000..0d921dbf4 --- /dev/null +++ b/taskt/Core/Automation/Commands/WordSaveCommand.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Xml.Serialization; +using taskt.UI.CustomControls; +using taskt.UI.Forms; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("Word Commands")] + [Attributes.ClassAttributes.Description("This command allows you to save an Word document.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to save changes to a document.")] + [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] + public class WordSaveCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] + [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + public string v_InstanceName { get; set; } + + public WordSaveCommand() + { + this.CommandName = "WordSaveCommand"; + this.SelectionName = "Save Document"; + this.CommandEnabled = true; + this.CustomRendering = true; + } + public override void RunCommand(object sender) + { + //get engine context + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + + //convert variables + var vInstance = v_InstanceName.ConvertToUserVariable(engine); + + //get word app object + var wordObject = engine.GetAppInstance(vInstance); + + //convert object + Microsoft.Office.Interop.Word.Application wordInstance = (Microsoft.Office.Interop.Word.Application)wordObject; + + //save + wordInstance.ActiveDocument.Save(); + + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + //create standard group controls + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor)); + + return RenderedControls; + + } + public override string GetDisplayValue() + { + return base.GetDisplayValue() + " [Instance Name: '" + v_InstanceName + "']"; + } + } +} \ No newline at end of file diff --git a/taskt/UI/CustomControls/CustomControls.cs b/taskt/UI/CustomControls/CustomControls.cs index 4e486591e..f9fa80a35 100644 --- a/taskt/UI/CustomControls/CustomControls.cs +++ b/taskt/UI/CustomControls/CustomControls.cs @@ -485,6 +485,18 @@ public static Dictionary UIImageDictionary() uiImages.Add("ExcelGetLastRowCommand", taskt.Properties.Resources.command_spreadsheet); uiImages.Add("ExcelSaveCommand", taskt.Properties.Resources.command_spreadsheet); uiImages.Add("ExcelActivateSheetCommand", taskt.Properties.Resources.command_spreadsheet); + uiImages.Add("WordCreateApplicationCommand", taskt.Properties.Resources.command_files); + uiImages.Add("WordCloseApplicationCommand", taskt.Properties.Resources.command_files); + uiImages.Add("WordOpenDocumentCommand", taskt.Properties.Resources.command_files); + uiImages.Add("WordSaveCommand", taskt.Properties.Resources.command_files); + uiImages.Add("WordSaveAsCommand", taskt.Properties.Resources.command_files); + uiImages.Add("WordExportToPDFCommand", taskt.Properties.Resources.command_files); + uiImages.Add("WordAddDocumentCommand", taskt.Properties.Resources.command_files); + uiImages.Add("WordReadDocumentCommand", taskt.Properties.Resources.command_files); + uiImages.Add("WordReplaceTextCommand", taskt.Properties.Resources.command_files); + uiImages.Add("WordAppendTextCommand", taskt.Properties.Resources.command_files); + uiImages.Add("WordAppendImageCommand", taskt.Properties.Resources.command_files); + uiImages.Add("WordAppendDataTableCommand", taskt.Properties.Resources.command_files); uiImages.Add("AddDataRowCommand", taskt.Properties.Resources.command_spreadsheet); uiImages.Add("CreateDataTableCommand", taskt.Properties.Resources.command_spreadsheet); uiImages.Add("FilterDataTableCommand", taskt.Properties.Resources.command_spreadsheet); diff --git a/taskt/packages.config b/taskt/packages.config index 008b754c8..9cddd0b5a 100644 --- a/taskt/packages.config +++ b/taskt/packages.config @@ -20,6 +20,7 @@ limitations under the License. + diff --git a/taskt/taskt.csproj b/taskt/taskt.csproj index 00230a008..3e744a5a4 100644 --- a/taskt/taskt.csproj +++ b/taskt/taskt.csproj @@ -102,6 +102,10 @@ ..\packages\Microsoft.Office.Interop.Outlook.15.0.4797.1003\lib\net20\Microsoft.Office.Interop.Outlook.dll True + + ..\packages\Microsoft.Office.Interop.Word.15.0.4797.1003\lib\net20\Microsoft.Office.Interop.Word.dll + True + ..\packages\TaskScheduler.2.6.1\lib\net452\Microsoft.Win32.TaskScheduler.dll @@ -309,6 +313,18 @@ + + + + + + + + + + + + From eb7af74c5daee0d448cc27aa92fd5fc22cec4c69 Mon Sep 17 00:00:00 2001 From: Francesca Faerman Date: Mon, 16 Mar 2020 11:45:37 -0400 Subject: [PATCH 2/3] clean up --- taskt/Core/Automation/Commands/WordExportToPDFCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taskt/Core/Automation/Commands/WordExportToPDFCommand.cs b/taskt/Core/Automation/Commands/WordExportToPDFCommand.cs index 88f55b295..78c8342b5 100644 --- a/taskt/Core/Automation/Commands/WordExportToPDFCommand.cs +++ b/taskt/Core/Automation/Commands/WordExportToPDFCommand.cs @@ -23,7 +23,7 @@ public class WordExportToPDFCommand : ScriptCommand [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } [XmlAttribute] - [Attributes.PropertyAttributes.PropertyDescription("Please indicate the path of the pdf")] + [Attributes.PropertyAttributes.PropertyDescription("Please indicate the path of the new pdf")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)] [Attributes.PropertyAttributes.InputSpecification("Enter or Select the path to the file.")] From 5b5adf0972c3a1559cfef4cd5b680822a828339d Mon Sep 17 00:00:00 2001 From: Francesca Faerman Date: Tue, 17 Mar 2020 16:18:15 -0400 Subject: [PATCH 3/3] Changed command descriptions --- taskt/Core/Automation/Commands/WordAppendDataTableCommand.cs | 4 ++-- taskt/Core/Automation/Commands/WordAppendImageCommand.cs | 4 ++-- .../Automation/Commands/WordCreateApplicationCommandcs.cs | 2 +- taskt/Core/Automation/Commands/WordExportToPDFCommand.cs | 4 ++-- taskt/Core/Automation/Commands/WordReadDocumentCommand.cs | 2 +- taskt/Core/Automation/Commands/WordReplaceTextCommand.cs | 4 ++-- taskt/Core/Automation/Commands/WordSaveCommand.cs | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/taskt/Core/Automation/Commands/WordAppendDataTableCommand.cs b/taskt/Core/Automation/Commands/WordAppendDataTableCommand.cs index e0b216657..67ba98dee 100644 --- a/taskt/Core/Automation/Commands/WordAppendDataTableCommand.cs +++ b/taskt/Core/Automation/Commands/WordAppendDataTableCommand.cs @@ -13,8 +13,8 @@ namespace taskt.Core.Automation.Commands { [Serializable] [Attributes.ClassAttributes.Group("Word Commands")] - [Attributes.ClassAttributes.Description("This command appends text to a word document.")] - [Attributes.ClassAttributes.UsesDescription("Use this command when you want to append text to a specific document.")] + [Attributes.ClassAttributes.Description("This command appends a datatable to a word document.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to append a datatable to a specific document.")] [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] public class WordAppendDataTableCommand : ScriptCommand { diff --git a/taskt/Core/Automation/Commands/WordAppendImageCommand.cs b/taskt/Core/Automation/Commands/WordAppendImageCommand.cs index 6c72d69c9..81a76273c 100644 --- a/taskt/Core/Automation/Commands/WordAppendImageCommand.cs +++ b/taskt/Core/Automation/Commands/WordAppendImageCommand.cs @@ -13,8 +13,8 @@ namespace taskt.Core.Automation.Commands { [Serializable] [Attributes.ClassAttributes.Group("Word Commands")] - [Attributes.ClassAttributes.Description("This command appends text to a word document.")] - [Attributes.ClassAttributes.UsesDescription("Use this command when you want to append text to a specific document.")] + [Attributes.ClassAttributes.Description("This command appends an image to a word document.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to append an image to a specific document.")] [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] public class WordAppendImageCommand : ScriptCommand { diff --git a/taskt/Core/Automation/Commands/WordCreateApplicationCommandcs.cs b/taskt/Core/Automation/Commands/WordCreateApplicationCommandcs.cs index dfcef7e36..213bfe0d5 100644 --- a/taskt/Core/Automation/Commands/WordCreateApplicationCommandcs.cs +++ b/taskt/Core/Automation/Commands/WordCreateApplicationCommandcs.cs @@ -11,7 +11,7 @@ namespace taskt.Core.Automation.Commands [Serializable] [Attributes.ClassAttributes.Group("Word Commands")] - [Attributes.ClassAttributes.Description("This command opens the Word Application.")] + [Attributes.ClassAttributes.Description("This command creates a Word Application.")] [Attributes.ClassAttributes.UsesDescription("Use this command when you want to launch a new instance of Word.")] [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] public class WordCreateApplicationCommand : ScriptCommand diff --git a/taskt/Core/Automation/Commands/WordExportToPDFCommand.cs b/taskt/Core/Automation/Commands/WordExportToPDFCommand.cs index 78c8342b5..bf010c41a 100644 --- a/taskt/Core/Automation/Commands/WordExportToPDFCommand.cs +++ b/taskt/Core/Automation/Commands/WordExportToPDFCommand.cs @@ -10,8 +10,8 @@ namespace taskt.Core.Automation.Commands { [Serializable] [Attributes.ClassAttributes.Group("Word Commands")] - [Attributes.ClassAttributes.Description("This command allows you to save an Word document.")] - [Attributes.ClassAttributes.UsesDescription("Use this command when you want to save a document to a file.")] + [Attributes.ClassAttributes.Description("This command allows you to export a Word document to a PDF.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to save a document to a PDF.")] [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] public class WordExportToPDFCommand : ScriptCommand { diff --git a/taskt/Core/Automation/Commands/WordReadDocumentCommand.cs b/taskt/Core/Automation/Commands/WordReadDocumentCommand.cs index 0104a8fff..5658192ab 100644 --- a/taskt/Core/Automation/Commands/WordReadDocumentCommand.cs +++ b/taskt/Core/Automation/Commands/WordReadDocumentCommand.cs @@ -10,7 +10,7 @@ namespace taskt.Core.Automation.Commands { [Serializable] [Attributes.ClassAttributes.Group("Word Commands")] - [Attributes.ClassAttributes.Description("This command allows you to save an Word document.")] + [Attributes.ClassAttributes.Description("This command allows you to save a Word document.")] [Attributes.ClassAttributes.UsesDescription("Use this command when you want to save changes to a document.")] [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] public class WordReadDocumentCommand : ScriptCommand diff --git a/taskt/Core/Automation/Commands/WordReplaceTextCommand.cs b/taskt/Core/Automation/Commands/WordReplaceTextCommand.cs index 346ded5f3..3efaa5f41 100644 --- a/taskt/Core/Automation/Commands/WordReplaceTextCommand.cs +++ b/taskt/Core/Automation/Commands/WordReplaceTextCommand.cs @@ -10,8 +10,8 @@ namespace taskt.Core.Automation.Commands { [Serializable] [Attributes.ClassAttributes.Group("Word Commands")] - [Attributes.ClassAttributes.Description("This command allows you to save an Word document.")] - [Attributes.ClassAttributes.UsesDescription("Use this command when you want to save changes to a document.")] + [Attributes.ClassAttributes.Description("This command allows you to replace text in a Word document.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to replace text in a document.")] [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] public class WordReplaceTextCommand : ScriptCommand { diff --git a/taskt/Core/Automation/Commands/WordSaveCommand.cs b/taskt/Core/Automation/Commands/WordSaveCommand.cs index 0d921dbf4..f0f5950cc 100644 --- a/taskt/Core/Automation/Commands/WordSaveCommand.cs +++ b/taskt/Core/Automation/Commands/WordSaveCommand.cs @@ -9,7 +9,7 @@ namespace taskt.Core.Automation.Commands { [Serializable] [Attributes.ClassAttributes.Group("Word Commands")] - [Attributes.ClassAttributes.Description("This command allows you to save an Word document.")] + [Attributes.ClassAttributes.Description("This command allows you to save a Word document.")] [Attributes.ClassAttributes.UsesDescription("Use this command when you want to save changes to a document.")] [Attributes.ClassAttributes.ImplementationDescription("This command implements Word Interop to achieve automation.")] public class WordSaveCommand : ScriptCommand