ABAP OLE - Open excel password protected workbook - ole

I'm trying to open a password protected excel file using SAP ABAP OLE OBJECT as follows:
DATA: lt_excel_line(4096) OCCURS 10 WITH HEADER LINE.
DATA: app TYPE ole2_object,
workbook TYPE ole2_object,
worksheet TYPE ole2_object.
CREATE OBJECT app 'EXCEL.APPLICATION'.
SET PROPERTY OF app 'VISIBLE' = 0.
CALL METHOD OF app 'WORKBOOKS' = workbook.
CALL METHOD OF workbook 'OPEN'
EXPORTING
#1 = '<filename>'
#5 = '<password>'.
The filename and password are definitely correct and the following VBA code opens the file as required no problem:
Dim wb1 As Workbook
Set wb1 = Workbooks.Open Filename:="<filename>", Password:="<password>")
But the ABAP code always returns sy-subrc = 2. Anyone know what could be going on? Or what else I can try? Grateful for any help.

I think the problem is with the parameters being positional only (just a guess), as the SAP GUI automation does not support parameter names. There are 3 parameters between Filename and Password, so you numbered them correctly, but I guess the SAP GUI automation controller does not see it that way.
I replicated your problem and got it working as follows:
CALL METHOD OF workbook 'OPEN' = document
EXPORTING
#1 = '<filename>'
#2 = 0 "UpdateLinks
#3 = 0 "ReadOnly
#4 = 1 "Format
#5 = '<password>'.
Here I am explicitly passing the parameters UpdateLinks, ReadOnly and Format.
I tested it first in VBA. It seems Format (#4) must be set to true. I don't know what that does.
Remember to set the document handle as a return from this call as I do here, otherwise you don't have a reference to it!

Related

QA Wizard checkpoint wrong evaluation when using data source?

I'm using QA Wizard Pro from Perforce. I've added a checkpoint to my automated test case to verify a textbox contains a certain value, which was calculated by the program.
When I use the hard coded value (here 5.273) the test passes
Window("FormMain").EditBox("tbClassC").Checkpoint("Text", "5.273", True, "")
When I read the value from a data source (excel file) I get an error
Window("FormMain").EditBox("tbClassC").Checkpoint("Text", Cell("ClassC"), True, "")
Error:
Control (tbClassC) Property (Text): The "5.273" expected value does not match the actual value of "5.273".
I followed this tutorial on how to use the checkpoint feature.
Any idea what I may do wrong?
I figured out the problem. Since I was using an Excel file as source I had to specificly declare the cell as data type Text. This way QA Wizard interpreted the excel value as text and not as a number.

Using COM from a R script

I woud like to be able to start and call a COM object from within a R script (in Windows obviously). There is a library called RDCOM http://www.omegahat.net/RDCOMClient/ but
it does not support VARIANT data types - and the COM object
expects VARIANT as parameters and returns arrays in them
is it maintained? are there active alternatives?
What I need to call is a function defined like this in the .idl file (the idl file gets compiled to create a COM object - not important except if you want to know the exact deeclaration of the object)
[id(3), helpstring("method GetQuestionList")] HRESULT GetQuestionList([out] VARIANT* nQuestionCount,[out] VARIANT* arrNames, [out] VARIANT* arrIndents, [out] VARIANT* arrTypes);
In this method the fields are passed by reference - in VB you would call it like this
Dim myObject = CreateObject("AskiaAPI.Analyse")
Dim arrIndents, nQuestionCount, arrNames, arrTypes As Object
myObject.GetQuestionList(nQuestionCount, arrNames, arrIndents, arrTypes)
Dim nQuestion
For nQuestion = 0 To nQuestionCount - 1
lstResults.Items.Add(nQuestion & ": " & arrNames(nQuestion))
Next nQuestion
In the code above, the variables nQuestionCount, arrNames, arrIndents, arrTypes are initialised by GetQuestionList (that's why they are passed by reference). In that example, lstResults would be a ListBox used to display the content of one of the parameters.
Any hint or idea is welcome!

Save an Excel sheet as PDF programatically through powerbuilder

There is a requirement to save an excel sheet as a pdf file programmatically through powerbuilder (Powerbuilder 12.5.1).
I run the code below; however, I am not getting the right results. Please let me know if I should do something different.
OLEObject ole_excel;
ole_excel = create OLEObject;
IF ( ole_excel.ConnectToObject(ls_DocPath) = 0 ) THEN
ole_excel.application.activeworkbook.SaveAs(ls_DocPath,17);
ole_excel.application.activeworkbook.ExportAsFixedFormat(0,ls_DocPath);
END IF;
....... (Parsing values from excel)
DESTROY ole_excel;
I have searched through this community and others for a solution but no luck so far. I tried using two different commands that I found during this search. Both of them return a null object reference error. It would be great if someone can point me in the right direction.
It looks to me like you need to have a reference to the 'activeworkbook'. This would be of type OLEobject so the declaration would be similar to: OLEobject lole_workbook.
Then you need to set this to the active work book. Look for the VBA code on Excel (should be in the Excel help) for something like a 'getactiveworkbook' method. You would then (in PB) need to do something like
lole_workbook = ole_excel.application.activeworkbook
This gets the reference for PB to the activeworkbook. Then do you saveas and etc. like this lole_workbook.SaveAs(ls_DocPath,17)
workBook.saveAs() documentation says that saveAs() has the following parameters:
SaveAs(Filename, FileFormat, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution, AddToMru, TextCodepage, TextVisualLayout, Local)
we need the two first params:
FileName - full path with filename and extension, for instance: c:\myfolder\file.pdf
FileFormat - predefined constant, that represents the target file format.
According to google (MS does not list pdf format constant for XLFileFormat), FileFormat for pdf is equal to 57
so, try to use the following call:
ole_excel.application.activeworkbook.SaveAs(ls_DocPath, 57);

How to write some amounts to a File?

I'm doing this program for a class; I have a listbox with 4 choices that are counted each time they're selected,and i'm supposed to write out the results to an out.File so that they can then be retrieved and displayed when asked to.
Here's an image,so you can see what i mean.
Here's the code i got for the file part so far:
'declare a streamwriter variable
Dim outFile As IO.StreamWriter
'open file for output
outFile = IO.File.CreateText("Commercials.txt")
'write to file
For intIndex As Integer = 0 To lstCommercial.Items.Count - 1
outFile.WriteLine(lstCommercial.Items(intIndex))
Next intIndex
'close th efile
outFile.Close()
So my problem is this,i can get everything to work except for it to write the totals to the file,with the result of not displaying. How do i go about doing this? What am i doing wrong in any case?
It depends on what lstCommercial.Items is.
If it is a Collection object, then you can get the index of an item using the following:
outFile.WriteLine(lstCommercial.Items.Item(intIndex))
If it is an array, then instead of using the Count property to find the length, you should rather use GetUpperBound(0) to find the last index:
For intIndex As Integer = 0 To lstCommercial.Items.GetUpperBound(0)
I have very little experience in Visual Basic so I am probably wrong, but I have just gathered this from reading Arrays in Visual Basic and Collection Object (Visual Basic).
Also, looking at the docs here, you may need to 'Flush' the buffer to the file before closing it:
outFile.Flush()
'close the file
outFile.Close()

How to set (unix) permissions when creating a file in SAP ABAP?

you would think this would be obvious, but searching through documentation, SAP forums, Googling, etc., I've been spectacularly unsuccessful. I'm creating a file in ABAP on a solaris filesystem using the following code:
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
the resulting file is owned and grouped according to a pre-defined admin user, which is fine, but the sticky wicket is that the permissions are set to 660/rw-rw----, meaning I can't examine the results. is there a way (possibly using that vaguely defined TYPE addition?) I can specify the resulting permissions on the new file?
thanks!
Go to SM69, create a logical system command, you could call it ZCHMOD.
Map that command to chmod, then call with the proper parameter
(man chmod on the command line is your friend).
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
EXPORTING
commandname = 'ZCHMOD'
additional_parameters = l_par
operatingsystem = l_os
TABLES
exec_protocol = it_log
EXCEPTIONS
no_permission = 1
command_not_found = 2
parameters_too_long = 3
security_risk = 4
wrong_check_call_interface = 5
program_start_error = 6
program_termination_error = 7
x_error = 8
parameter_expected = 9
too_many_parameters = 10
illegal_command = 11
wrong_asynchronous_parameters = 12
cant_enq_tbtco_entry = 13
jobcount_generation_error = 14
OTHERS = 15.
Obviously, that would be a 2 step process, but it works.
this works in 4.6B:
CONCATENATE 'chmod ugo=rw ' lc_filename
INTO lc_chmod SEPARATED BY space.
CALL 'SYSTEM' ID 'COMMAND' FIELD lc_chmod.
Hope this helps.
Cheers,
Heiko
In RZ10 add parameter install/umask.
Default value is 007, you can change it: 000, 002...
So, the files created will be -rw-rw-rw-, -rw-rw-r--...

Resources