Page 1 of 2
Read from an external file.
Posted: 23 Jan 2014 11:12
by ahmednadi
Dear Sirs;
Could you help me?
How can I capture the content of doc file and put it on a text control box.
Regards;
Ahmed Nady
Posted: 24 Jan 2014 8:06
by Tonton Luc
Hi,
Make a search of "DDE" in this forum.
Re: Read from an external file.
Posted: 24 Jan 2014 9:00
by Thomas Linder Puls
ahmednadi wrote:How can I capture the content of doc file ...
Do you mean a Microsoft Word document?
Posted: 24 Jan 2014 19:41
by ahmednadi
Dear Sir;
Thank you for your reply.
yes, sir Microsoft word.
How can I access an external file in MS word and open it to copy its contents to my program in Visual Prolog.
Best regards;
AHMED NADY
Posted: 24 Jan 2014 23:17
by Harrison Pratt
Ahmednadi,
Can you give more specifics ...
Will your application require an installed version of Word, or do you want to read the file directly without using MS Word?
Do you want ALL of the document, or a specific part of it?
Is it acceptable to have the user open Word and export some (or all) of the document, or must activity that be hidden from the user?
Have you looked into using VBA (Microsoft Visual Basic for Applications) to export the document or copy it to the clipboard?
So many ways of attacking your problem, so we need more info to help you.
Harrison
Posted: 25 Jan 2014 10:55
by ahmednadi
Dear Harrison;
Thank you.
Please be informed that I want to read the file directly with/without using MS Word.
It may be ALL of the document, or a specific part of it.
It is acceptable to have the user open Word and export some (or all) of the document.
Have you looked into using VBA (Microsoft Visual Basic for Applications) to export the document or copy it to the clipboard? No, but could you help me in this direction with a specific examples.
Your fast action will be highly appreciated.
AHMED
Posted: 25 Jan 2014 14:03
by Harrison Pratt
Copy from Word to Windows clipboard, retrieve from clipboard in your application with
Code: Select all
tryGetString/0-> tryGetString : () -> string String determ.
It is acceptable to have the user open Word and export some (or all) of the document.
That's the fastest way to get started since you don't seem to have strict requirements about not opening the document in Word.
Posted: 26 Jan 2014 7:32
by ahmednadi
Dear Sir;
I would like to draw you attention that I have a form and I want to access an external file in somewhere on the hard disk through the form. Then open the file and read its contents and make a copy of all or a specific part from it.
How could you help me by more details about tryGetString predicate usage.
Thank you.
Best regards;
AHMED NADY
Posted: 27 Jan 2014 8:38
by ahmednadi
Dear Sir;
Could you help me to solve this problem?
regards;
AHMED NADY
Posted: 27 Jan 2014 9:34
by George
If your requirement is just about the reading a data from external file, you could find the below code,
Code: Select all
predicates
onPushButtonClick : button::clickResponder.
clauses
onPushButtonClick(_Source) = button::defaultAction:-
MyStream = inputStream_file::openFile8(@"D:\TestMe.txt"), %External file
MYVal = varM{string}::new(""),
%Loop through all the line and fetch a data from the file
std::repeat(),
if not(MyStream:endOfStream()) then
LieVal = MyStream:readLine(),
MYVal:value := string::concat(MYVal:value, LieVal, "\n"), %Keep a copy @ Temp variable
fail %fail to loop through
end if,
MyStream:close(), %Close the input stream handle
edit_ctl:setText(MYVal:value), %display the message to edit control.
!.
onPushButtonClick(_Source) = button::defaultAction.
Posted: 27 Jan 2014 11:14
by ahmednadi
Posted: 28 Jan 2014 7:55
by Tonton Luc
Hi,
Something like :
Code: Select all
predicates
onTest1 : window::menuItemListener.
clauses
onTest1(_Source, _MenuTag):-
Path = "C:\\",
Type = "*.doc",
List_doc_files = [F||F = directory::getFilesInDirectory_nd(Path,Type)],
foreach Cpt = std::fromTo(0,list::length(List_doc_files)-1) do
Fic = fileName::setPath(list::nth(Cpt,List_doc_files),Path),
read_doc_file(Fic)
end foreach.
predicates
read_doc_file:(string DocFile) procedure(i).
clauses
read_doc_file(Fic):-
MyStream = inputStream_file::openFile8(Fic), %External file
MYVal = varM{string}::new(""),
%Loop through all the line and fetch a data from the file
std::repeat(),
if not(MyStream:endOfStream()) then
LieVal = MyStream:readLine(),
MYVal:value := string::concat(MYVal:value, LieVal, "\n"), %Keep a copy @ Temp variable
fail %fail to loop through
end if,
MyStream:close(), %Close the input stream handle
!.
read_doc_file(_).
Posted: 28 Jan 2014 12:10
by ahmednadi
Dear Sir;
Thank you.
Where I can put these predicates?
How can I use it?
regards;
AHMED
Posted: 28 Jan 2014 16:26
by Tonton Luc
...when user click on a button, like it :
Code: Select all
predicates
onPushButtonClick : button::clickResponder.
clauses
onPushButtonClick(_Source) = button::defaultAction:-
Path = "C:\\",
Type = "*.doc",
List_doc_files = [F||F = directory::getFilesInDirectory_nd(Path,Type)],
foreach Cpt = std::fromTo(0,list::length(List_doc_files)-1) do
Fic = fileName::setPath(list::nth(Cpt,List_doc_files),Path),
read_doc_file(Fic)
end foreach.
Posted: 28 Jan 2014 16:30
by Thomas Linder Puls
Most suggestions above will
not work.
The
doc format used by Microsoft Word is an undocumented proprietary format.
The newer
docx format follows a public standard. That does however not help much. A
docx file is actually a zipped directory. If you change the extension to
zip you can unpack it and see that its contents is rather difficult to find heads and tails in.
I suggest that you (either give up
or) look for ways where Microsoft Word or some third party tool makes the conversion. Letting Microsoft Word put the relevant text on the clipboard is one possibility.