Jump to content

Recommended Posts

Posted (edited)

Greetings AutoIt community!

I did a quick search and found nothing posted for working with WPS Office using AutoIt so far, though I did see a few requests for it over the years.

In my testing and research I have found that WPS Office seems to be just a free, re-branded version of MSOffice. Underneath the makeup, the COM methods etc are all the same, even the CLSID’s! That being the case you can use the UDF’s by water (or others) meant for working with Microsoft Office’s products, such as the Word and Excel UDF’s included with AutoIt already, as well as the PowerPoint UDF by water, found here: https://www.autoitscript.com/forum/files/file/374-powerpoint-udf/

That being said, I have not exhaustively tested automating WPS using the MSWord COM methods. Though I have used many MSOffice COM methods, etc., for automating WPS without a problem, you are encouraged to do testing yourself and make sure it works. I do not have much experience with MSOffice and related products, and thus may not be able to help much with bugs, but I will try to help as time permits.

The question will arise, why did I have to make a function, since these two Office programs are seemingly identical? Well, First, to open a new instance of WPS Office programs (Writer, Spreadsheets, Presentation), the Class names are different. (KWPS.Application vs Word.Application; KWPP.Application vs PowerPoint.Application; KET.Application vs Excel.Application). And secondly, when connecting (or attaching) to an existing instance of WPS, you can easily get a MSOffice application Object instead of a WPS Application Object, and vice versa, if you so happen to have both installed and running. Thus I added a check for the Registry path to contain the string “\kingsoft\” to ensure you retrieve the intended object. (If anyone has a better method, I would appreciate any hints. The CLSID’s are identical, as well as the class name when it is running (Word.Application; Excel.Application; PowerPoint.Application))

So far I haven’t come up with a better name, so I have called it simply “WPS Office Adapter” because it allows you to use MS Office UDF functions for WPS. Any suggestions for a name will also be appreciated.

The functions I made are copies from those written by water in the respective MS Office UDFs, with modifications to work with WPS, and some personal preference. Once you retrieve the Object you need for the WPS application, simply use those Objects in the respective MS Office UDF function.

One note for the _Excel_Close function, you will need to call ForceClose with True, or implement water’s internal __Excel_CloseOnQuit function as done in _Excel_Open, to allow the usual functionality of _Excel_Close to work.

Also, in order for the examples of WPS Presentation to work, you will need to modify the Include path to point to the PowerPoint UDF, or place a copy into the main WPS UDF folder.

Question or comments, or suggestions are welcome and appreciated. And also, if you wish to take this function and improve it or expand it, feel free, I’m not intending to go further than I have, with the exception of perhaps bug fixes as time permits.

The Functions that replace existing MS Office functions are as follows:

  • _WPS_Presentation_Attach -- Replaces --> _PPT_PresentationAttach
  • _WPS_Presentation_Open -- Replaces --> _PPT_Open
  • _WPS_Spreadsheets_BookAttach -- Replaces --> _Excel_BookAttach
  • _WPS_Spreadsheets_BookList -- Replaces --> _Excel_BookList
  • _WPS_Spreadsheets_Open -- Replaces --> _Excel_Open
  • _WPS_Writer_Create -- Replaces --> _Word_Create

Best regards,

WPS Office Adapter.zip

Edited by donnyh13

LibreOffice UDF  ; Scite4AutoIt Spell-Checker Using LibreOffice

Spoiler

"Life is chiefly made up, not of great sacrifices and wonderful achievements, but of little things. It is oftenest through the little things which seem so unworthy of notice that great good or evil is brought into our lives. It is through our failure to endure the tests that come to us in little things, that the habits are molded, the character misshaped; and when the greater tests come, they find us unready. Only by acting upon principle in the tests of daily life can we acquire power to stand firm and faithful in the most dangerous and most difficult positions."

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...