LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Special character replacer for word files and converting docx to doc

Solved!
Go to solution

Hi! 

 

I am developing a tool for our team. Withouth much detail I have to look up a lot of special characters in a Word file (docx but I should also convert it to doc but later on this subject) than change these special characters with others. 

 

For example word replaces ... with one character but an other software of us can not handle this character. So right now I have an excel table that has the special characters in one column and the ones I want them replaced with in the next. The one that is now looping constantly is the replacement of the ... with . . . (dots with space in between) 

 

The little tool was working fine on a test document where I have just dropped in all the characters I want replaced. Than I tried it with the doc type it should be used on and it starts an infinite loop of spamming characters. I'll attach a picture of the code sniplet and a picture of what it does in the document right now. 

 

Can anyone help me with this? I tried to increment the range after I found something but it is not changing the problem. I can not attach the VI sadly. 

 

 

Also I have to convert docx files to doc files (I think 2007 version?) Can someone help with this? So far I tried to make a macro in word and use some activex magic to copy the macro but I hit hard walls everywhere...

 

 

Thanks in advance! 

(And sorry, I am new to the forums)

Download All
0 Kudos
Message 1 of 13
(3,391 Views)

First question I have.   You talk about workign with Word documents, but your screenshot "snap3,jpg" is working with an Excel file.  Which are you working with?

0 Kudos
Message 2 of 13
(3,338 Views)

Almost impossible to help you without playing with the code and with a typical word file and the list of characters to replace. One observation: the range start shift register should be initialize to 0.

 

To save to .doc format use the Document SaveAs2 method with .doc extension and set WdSaveFormat input to 0.

 

Ben64

0 Kudos
Message 3 of 13
(3,337 Views)
That is a docx file but it has some realy special formating and a lot of tables.
0 Kudos
Message 4 of 13
(3,329 Views)

share the code instead of image.....Smiley Happy

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 5 of 13
(3,324 Views)

Please attach actual code (which typically means "Attach a VI") rather than a picture of a Block Diagram (or Front Panel).  We cannot closely inspect a Picture, cannot see the other "hidden" cases, and, most important, cannot execute or test pictures of code.

 

Something we can also learn from code (most new posters to the Forum don't know to tell us) is which version of LabVIEW you are using.

 

Your picture shows a function "Excel Read VI" that I do not recognize.  Where (and how) are you reading the Word Document?  Are you using a tool like the Report Generation Toolkit to open and gain access to the "document" (meaning the text) in Word?

 

You do know, I presume, that LabVIEW is designed as an "Engineering WorkBench" (that phrase is the "EW" of LabVIEW), not as a General Purpose Text Processing language.  The Report Generation Toolkit is designed to "generate Reports", presumably from Engineering Tests.  You can "push the envelope" and actually do simple editing of both Word and Excel documents.  I've found that using the RGT, particularly the version that has been shipping for the last, say, half-decade, is really not too bad (compared with complexities of VBA and ActiveX).

 

How about coming back with some Code and some example Excel and Word documents?  To pass more than three files into the Forum, assemble all of your files into a single folder, tell Windows to Compress the folder, and attach the resulting .ZIP file.

 

Bob Schor 

0 Kudos
Message 6 of 13
(3,319 Views)

@PalanivelThiruvenkadam wrote:

share the code instead of image.....Smiley Happy


Agreed,  If you go to the edit menu there is a entry to "Create snippet from VI Selection" this will embed the code into a *.png file that you can add inline with your post (Then we can actually see the code in context of your question.)  Better YET! we can drag-n-drop that .png onto a LabVIEW Block diagram and "POOF" we have the code to play with ourselves.

 

Spoiler
There has got to be a punctuation error in that last sentance that eludes me pre-coffee! Smiley Embarassed  But, I hope you know which way I meant it to be interperated.

"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 13
(3,313 Views)

Sadly, I can not share the files. Neither the word file nor the VI-s. The list of characters is now rather faint, so far they are only these: … – „” 
But I have to figure out some more. The replacements are simple, right now the following: 

. . .
-
''
''

 

For some reason the VI can not find the last sign but it is a story for an other day. 

 

Thanks for the observation, you are totaly right. I should do it. (With 0)

 

And thanks for the SaveAs2 method - I had no idea what I should have wired to the input (I could not find a list of available inputs). I am relatively new to developing for LV - I do not have too much routine with it. Specially these... I only developed stuff for NI devices and never had to work with word files... 

 

Sadly the VI it self has sensitive data inside so I can not share it. Neither the document as it is classified... But thanks for the help 🙂 

0 Kudos
Message 8 of 13
(3,307 Views)

Oooh, classified.  Just EMAIL it...and then delete the email and no one will ever know.  Smiley Very Happy

 

Why don't you set the range for the whole document?  I assume that the Find/Replace method will do a replace all.  Sometimes, the best way to figure out how to do something with ActiveX is to record a macro in Word/Excel and then edit the macro.  You can see the auto-generated code that will very closely match to what is needed for ActiveX calls. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 9 of 13
(3,293 Views)

I can not attach it, sadly. It has classified data. Also as this is for work, I have no ownership rights over the code - only the company I work at. Sorry, I know.... Not the best thing 😄 

 

No hidden cases, this VI only has this much of stuff inside. 

 

LV version is 2015 sp1 32 bit but normaly I am required to work in 7.1 :'D So I am not even trying to get answers for questions regarding that version :'D 

 

Excel Read VI is just a VI I made in 10 minutes - it just puts the data into an array and than I can unbundle it in the VI shown on the picture. 

 

The Word doc is read in with NI_report.lvclass:New Report.vi than passed Get ActiveX references than into this VI. If this is understandable. 

 

I know what it is designed for. I studied physics at university, that's how I met it and I used a lot of stuff from NI. But it is not my descision to use LV for something it is not designed to do 🙂 We have access to LV because we are developing in LV - now I have to do this tool so it makes our work a bit easier... Just so you know I work as a test software developer and I am making automatic software for a pneumatic test bench. So it is - in fact - engineering work. As I just said, I have access to LV for this reason 🙂 

And as I stated, I can not share even one single file 😞 This print screen was also risky. But if someone is interested and has, say, examples, I am gladly checking them out. I can not share the word file because it has company data hardcoded inside, and it is not allowed to leave the system. 

0 Kudos
Message 10 of 13
(3,289 Views)