I'm writing a C# program to run QTP.
Now my program can trigger QTP automatically and send the result to my mailbox. But this result is HTML, i find that QTP can export a PDF result.
so, here is my code.
qtpAutoReport = qtpApp.Options.Run.AutoExportReportConfig;
qtpAutoReport.AutoExportResults = true;
qtpAutoReport.StepDetailsReport = true;
qtpAutoReport.DataTableReport = false;
qtpAutoReport.LogTrackingReport = false;
qtpAutoReport.ScreenRecorderReport = false;
qtpAutoReport.SystemMonitorReport = false;
qtpAutoReport.StepDetailsReportFormat = "Short";
qtpAutoReport.ExportLocation = AutoExportPath;
qtpAutoReport.ExportForFailedRunsOnly = false;
qtpAutoReport.StepDetailsReportType = "PDF";
When i use this code qtpAutoReport.StepDetailsReportType = "HTML";
My program can run successfully, and i can find this HTML file on my disk.
But, when i use this code qtpAutoReport.StepDetailsReportType = "PDF";
After QTP test is over, i can't any file on my disk.
So my question is why QTP can't export result when i set StepDetailsReportType as "PDF"?
There does seem to be an issue with UFT, I found a method that works for GUI tests(vbscript), give it a try with Service Test (c#).
All options are the same as your example, with one addition:
uftObject.Options.Run.ViewResults = True
This tells UFT that you want to view the results after completion. Without this flag I get no PDF result, with it the file is waiting at the export path.
Option Explicit
Dim uftObject, qtResultsOpt
Set uftObject=CreateObject("Quicktest.application")
uftObject.Launch
uftObject.Visible = True
Set qtResultsOpt = uftObject.Options.Run.AutoExportReportConfig
Dim AutoExportPath
AutoExportPath = "C:\Users\paxic\Desktop\stackoverflow\results"
qtResultsOpt.AutoExportResults = true
qtResultsOpt.StepDetailsReport = true
qtResultsOpt.DataTableReport = false
qtResultsOpt.LogTrackingReport = false
qtResultsOpt.ScreenRecorderReport = false
qtResultsOpt.SystemMonitorReport = false
qtResultsOpt.StepDetailsReportFormat = "Short"
qtResultsOpt.ExportLocation = AutoExportPath
qtResultsOpt.ExportForFailedRunsOnly = false
qtResultsOpt.StepDetailsReportType = "PDF"
uftObject.Open "C:\Users\JMorley\Desktop\stackoverflow\ExampleOne"
qtResultsOpt.AutoExportResults = True
uftObject.Options.Run.ViewResults = True
uftObject.Test.Run
Related
I am using DataLogic utilities(Datalogics.PDFL) to manipulate the PDF, I am facing issues with the below scenario.
A PDF with non-english text getting weird output.
Sample input file SS
Getting output in the below format for the same:
WordFinderConfig wordConfig = new WordFinderConfig();
wordConfig.IgnoreCharGaps = false;
wordConfig.IgnoreLineGaps = false;
wordConfig.NoAnnots = false;
wordConfig.NoEncodingGuess = false;
// Std Roman treatment for custom encoding; overrides the noEncodingGuess option
wordConfig.UnknownToStdEnc = true;
wordConfig.DisableTaggedPDF = false; // legacy mode WordFinder creation
wordConfig.NoXYSort = true;
wordConfig.PreserveSpaces = false;
wordConfig.NoLigatureExp = false;
wordConfig.NoHyphenDetection = false;
wordConfig.TrustNBSpace = false;
wordConfig.NoExtCharOffset = false; // text extraction efficiency
wordConfig.NoStyleInfo = false; // text extraction efficiency
WordFinder wordFinder = new WordFinder(doc, WordFinderVersion.Latest, wordConfig);
I'd encourage you to upgrade to the most current release (e.g. via Nuget) and if you still experience problematic Text Extraction results to then contact our (Datalogics) Support Department for assistance and provide them with the input document and a runnable sample for reproduction purposes.
For a while i've been trying to make a standalone program in c#, which uses the BrowseTags function from iHistorian_SDK. (iFix 5.8 and Historian 7.0)
First I made this function in VBA where it works great, but due to VBA being single threaded, I want to moive it out of VBA.
My VBA code that works today:
Public connectedServer As Object
Public myServerManager As Object
Private Sub TestBrowseFunction()
Call BrowseTagsFromHistorianCollector("SVNF-IFIX-HIS01", "SVNF-IFIX-SCA01_iFIX")
End Sub
Public Function BrowseTagsFromHistorianCollector(ByVal HistServer As String, ByVal HistCollector As String, Optional AdditionsOnly As Boolean = False, Optional SourceFilter As String = "*", Optional DescriptionFilter As String = "*")
On Error Resume Next
Dim MyTags As Variant
Dim Tag As Variant
Set connectedServer = Nothing
Set MyServerManager = CreateObject("iHistorian_SDK.ServerManager")
DoEvents
'Make sure Historian is installed correctly'
If MyServerManager Is Nothing Then
Err.Raise 0, , "Error Creating iHistorian Server Manager - please check to see if Historain Client is correctly installed on your system", vbOKOnly, "test"
Exit Function
End If
'Create iHistorian server object'
Set connectedServer = CreateObject("iHistorian_SDK.Server")
'Check to see if the connection is established, else connect.'
If CheckConnection = False Then connectedServer.Connect (HistServer)
If CheckConnection = True Then
'Browse the collector for tags.'
Set MyTags = connectedServer.collectors.Item(HistCollector).BrowseTags(AdditionsOnly, SourceFilter, DescriptionFilter)
'Loop all the tags from the collector'
For Each Tag In MyTags.Item
'INSERT CODE TO DO FOR EACH TAG HERE!'
Debug.Print Tag.tagName
Next
End If
End Function
' make sure that we are connected to a server'
Public Function CheckConnection() As Boolean
On Error GoTo errc
If connectedServer Is Nothing Then
CheckConnection = False
Exit Function
End If
If Not connectedServer.Connected Then
CheckConnection = False
Exit Function
End If
If connectedServer.ServerTime < CDate("1/1/1970") Then
CheckConnection = False
Exit Function
End If
CheckConnection = True
Exit Function
errc:
CheckConnection = False
End Function
This works great.
But in my attempt to convert the same function over to C# i keep getting errors.
First i connect to my historian server, which is pretty painless.
tsStatus.Text = "Connecting to " + HistServer;
try
{
connectedServer = new iHistorian_SDK.Server();
connectedServer.Connect(HistServer);
tsStatus.Text = "Connected to " + HistServer;
}
catch (Exception ex)
{
Debug.Print("Server connection threw exception: " + ex);
tsStatus.Text = "Failed connecting to " + HistServer;
}
My status label before i try to connect:
My status label after i try to connect:
After the connection is established, I would like to be able to do something like what i've done in VBA.
Set MyTags = connectedServer.collectors.Item(HistCollector).BrowseTags(AdditionsOnly, SourceFilter, DescriptionFilter)
My c# attempt goes as follows
iHistorian_SDK.TagRecordset MyTags;
MyTags = new iHistorian_SDK.TagRecordset();
MyTags = connectedServer.Collectors.Item("SVNF-IFIX-SCA01_iFIX").BrowseTags(false, "*", "*");
Does anyone know how I can come around this, or if it's even possible in C# to browse tags with the same methode of the collector object.
I've seen this video a few times so I would assume it's possible, they just skip the code where they actually browse tags.
Thanks in advance
/T
The parenthesis in VBA is an indexer. Try to replace .Collectors.Item.("...") with .Collectors.Item.["..."]
If you check the source code for the video link you provided (I.e. The client SDK sample), they aren't using the collectors to query the tags.
cmdBrowseTags_Click is using the ITags "Query" method to 'Browse Tags'.
Here is the GE provided help doco example included in "iHistClientAccessAPI.chm":
TagQueryParams query = new TagQueryParams();
List<Tag> list = new List<Tag>(), temp = null;
query.Criteria.TagnameMask = "*";
// simple query
connection.ITags.Query(ref query, out list);
// paged query
list.Clear();
query.PageSize = 100; // return at most 100 results per request
while (connection.ITags.Query(ref query, out temp))
list.AddRange(temp);
list.AddRange(temp);
I prefer something like this (includes the server connection for completeness):
ServerConnection serverConnection = new ServerConnection(
new ConnectionProperties
{
ServerHostName = "MyHistorianHostName",
Username = "MyUserName",
Password = "MyPassword",
ServerCertificateValidationMode = CertificateValidationMode.None
});
serverConnection.Connect();
if (serverConnection.IsConnected())
{
List<Tag> tagList = new List<Tag>();
TagQueryParams tagQueryParams = new TagQueryParams
{
Criteria = new TagCriteria { TagnameMask = "*" }, // Wilcard, get all tags.
Categories = Tag.Categories.All, // Change this to Basic fo mimimal info.
PageSize = 100 // The batch size of the while loop below..
};
bool isQuery = true;
while (isQuery)
{
isQuery = serverConnection.ITags.Query(ref tagQueryParams, out var tags);
tagList.AddRange(tags);
}
// At this point, tagList contains a list of all tags that matched your wildcard filter.
// To filter to a specific collector, you could then do something like:
var collectorTagList = tagList.Where(t => t.CollectorName == "MyCollector");
}
Goodluck :)
The following code finds instances of the word "Family" in a Word document. It selects and deletes the instances. The code works fine, but I want to find all instances of only highlighted words.
public void FindHighlightedText()
{
const string filePath = "D:\\COM16_Duke Energy.doc";
var word = new Microsoft.Office.Interop.Word.Application {Visible = true};
var doc = word.Documents.Open(filePath);
var range = doc.Range();
range.Find.ClearFormatting();
range.Find.Text = "Family";
while (range.Find.Execute())
{
range.Select();
range.Delete();
}
doc.Close();
word.Quit(true, Type.Missing, Type.Missing);
}
Set the Find.Highlight property to true.
Interop uses the same objects and methods that are available to VBA macros. You can find the actions, properties you need to perform a task by recording a macro with those steps and inspecting it.
Often, but not always, the properties match the UI. If something is a property in the general Find box, it's probably a property in the Find interface as well.
For example, searching only for highlighted words produced this macro :
Selection.Find.ClearFormatting
Selection.Find.Highlight = True
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Which can be translated to :
range.Find.ClearFormatting();
range.Find.Highlight=1;
...
while(range.Find.Execute())
{
...
}
I have a server that returns large amounts of comma separated data in an http response. I need to import this data into excel.
I have this working by passing the contents to a temp file and then reading the temp file as a csv, but this process seems inefficient. The query tables can read directly from the http response, but it puts each line of data into a single cell, rather than separating into one cell per comma.
Is it possible to read comma separated data from an http response directly into excel from a C# excel add-in?
Thanks!
public static void URLtoCSV(string URL, Excel.Worksheet destinationSheet, Excel.Range destinationRange, int[] columnDataTypes, bool autoFitColumns)
{
destinationSheet.QueryTables.Add(
"URL;" + URL,
destinationRange, Type.Missing);
destinationSheet.QueryTables[1].Name = URL;
destinationSheet.QueryTables[1].FieldNames = true;
destinationSheet.QueryTables[1].RowNumbers = false;
destinationSheet.QueryTables[1].FillAdjacentFormulas = false;
destinationSheet.QueryTables[1].PreserveFormatting = true;
destinationSheet.QueryTables[1].RefreshOnFileOpen = false;
destinationSheet.QueryTables[1].RefreshStyle = XlCellInsertionMode.xlInsertDeleteCells;
destinationSheet.QueryTables[1].SavePassword = false;
destinationSheet.QueryTables[1].SaveData = true;
destinationSheet.QueryTables[1].AdjustColumnWidth = true;
destinationSheet.QueryTables[1].RefreshPeriod = 0;
destinationSheet.QueryTables[1].Refresh(false);
if (autoFitColumns == true)
destinationSheet.QueryTables[1].Destination.EntireColumn.AutoFit();
}
The easier solution than the one you reference is to use the type of "TEXT" instead of URL. TEXT supports all CSV imports, including from HTTP sources. URL appears to be designed to handle screen scraping more than anything else.
e.g. in your case:
destinationSheet.QueryTables.Add("URL;" + URL,
becomes
destinationSheet.QueryTables.Add("TEXT;" + URL,
And for those stumbling upon this post asking the same question but with VB scripting in Excel, the complete solution would look like:
' Load new data from web
With ActiveSheet.QueryTables.Add(Connection:="TEXT;http://yourdomain.com/csv.php", Destination:=Range("$A$1"))
.TextFileCommaDelimiter = True
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = False
.AdjustColumnWidth = True
.Refresh BackgroundQuery:=False
End With
I am creating a OO Writer document with C#.
Any help would be appreciated - I no longer know whether I am coming or going, I have tried so many variations....
using C#, has anybody successfully got the following to work? I just have a simple table of 2 columns and want to set the column widths to different values (actual value at this stage immaterial - just not identical widths).
This code is adapted from various web sources given as examples of how to do column widths. I cannot get it to work....
//For OpenOffice....
using unoidl.com.sun.star.lang;
using unoidl.com.sun.star.uno;
using unoidl.com.sun.star.bridge;
using unoidl.com.sun.star.frame;
using unoidl.com.sun.star.text;
using unoidl.com.sun.star.beans;
..............................
XTextTable odtTbl = (XTextTable) ((XMultiServiceFactory)oodt).createInstance("com.sun.star.text.TextTable");
odtTbl.initialize(10, 2);
XPropertySet xPS = (XPropertySet)odtTbl;
Object xObj = xPS.getPropertyValue("TableColumnSeparators")**; // << Runtime ERROR**
TableColumnSeparator[] xSeparators = (TableColumnSeparator[])xObj;
xSeparators[0].Position = 500;
xSeparators[1].Position = 5000;
xPS.setPropertyValue("TableColumnSeparators", new uno.Any(typeof(unoidl.com.sun.star.text.XTextTable),xSeparators));
// Runtime ERROR indicates the ; at the end of the Object line, with message of IllegalArgumentException
Now this is only one type of error out of all the combinations of attempts. Not many allowed execution at all, but the above code did actually run until the error.
What is the correct code for doing this in C# please?
In addition, what is the correct C# code to set an O'Writer heading to a particular style (such as "Heading 1") so that it looks and prints like that style in the document?
Thank you.
unoidl.com.sun.star.uno.XComponentContext localContext = uno.util.Bootstrap.bootstrap();
unoidl.com.sun.star.lang.XMultiServiceFactory multiServiceFactory = (unoidl.com.sun.star.lang.XMultiServiceFactory)localContext.getServiceManager();
XComponentLoader componentLoader =(XComponentLoader)multiServiceFactory.createInstance("com.sun.star.frame.Desktop");
XComponent xComponent = componentLoader.loadComponentFromURL(
"private:factory/swriter", //a blank writer document
"_blank", 0, //into a blank frame use no searchflag
new unoidl.com.sun.star.beans.PropertyValue[0]);//use no additional arguments.
//object odtTbl = null;
//odtTbl = ((XMultiServiceFactory)xComponent).createInstance("com.sun.star.text.TextTable");
XTextDocument xTextDocument = (unoidl.com.sun.star.text.XTextDocument)xComponent;
XText xText = xTextDocument.getText();
XTextCursor xTextCursor = xText.createTextCursor();
XPropertySet xTextCursorProps = (unoidl.com.sun.star.beans.XPropertySet) xTextCursor;
XSimpleText xSimpleText = (XSimpleText)xText;
XTextCursor xCursor = xSimpleText.createTextCursor();
object objTextTable = null;
objTextTable = ((XMultiServiceFactory)xComponent).createInstance("com.sun.star.text.TextTable");
XTextTable xTextTable = (XTextTable)objTextTable;
xTextTable.initialize(2,3);
xText.insertTextContent(xCursor, xTextTable, false);
XPropertySet xPS = (XPropertySet)objTextTable;
uno.Any xObj = xPS.getPropertyValue("TableColumnSeparators");
TableColumnSeparator[] xSeparators = (TableColumnSeparator[])xObj.Value; //!!!! xObj.Value
xSeparators[0].Position = 2000;
xSeparators[1].Position = 3000;
xPS.setPropertyValue("TableColumnSeparators", new uno.Any(typeof(TableColumnSeparator[]), xSeparators)); //!!!! TableColumnSeparator[]