Editing existing *.doc and *.xls files

Editing existing *.doc and *.xls files

dariopanic
Explorer Explorer
855 Views
9 Replies
Message 1 of 10

Editing existing *.doc and *.xls files

dariopanic
Explorer
Explorer

Hello everyone,

I am trying to create a lisp which will:

1. enter somehow into/read existing doc and xls file (separately)

2. find specific words and replace it with another words

 

so basically it will be "find and replace" functions in advance prepared files, but without opening files, just quiet search and replacing.

Can anyone help me with this , I can't find and visual or autolisp functions for that, I would be very grateful. Thanks in advance.

0 Likes
856 Views
9 Replies
Replies (9)
Message 2 of 10

cadffm
Consultant
Consultant

Possible by ActiveX (microsoft Windos, not for mac)

 

Search for sample to read and write excel files..

Thats the first step.

Untestet sample

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getting-excelvalue-of-the-next-colum...

 

If you have access to the file, you need to lern about the Word and Excel ActiveX Object Model (microsoft docs),

but the fastest way is to search for samples.

 

If you start at zero, it isn't easy 

Acad activeX access to another application

Excel objectmodel

Word objectmodel

much stuff..

 

VBA Word and Excel forums are very usefull to find samples for search&replace,

then you need to translate it for your lisp program.

 

Sorry that i can not offer perfect samples, because i am on my mobile (it's a pain to search, copy and paste..)

Sebastian

0 Likes
Message 3 of 10

dariopanic
Explorer
Explorer

ahh I was afraid it is not simple. Thanks again, I will try to follow your advices.

0 Likes
Message 4 of 10

martti.halminen
Collaborator
Collaborator

For Excel there is an easier way than ActiveX but only if you can save the files as .csv instead of .xls

- This has limitations, as .csv doesn't retain any formatting  or any more advanced features, just raw cell values.

 

In that case, just read in the file line by line, split each line into a list of strings, do your modifications using normal Lisp commands, and write out the result as a .csv file.

 

-- 

0 Likes
Message 5 of 10

cadffm
Consultant
Consultant

I suspect that is indusceptible,
but generally a creative approach because you can also save an existing Excel file as csv and an existing DOC as txt

 

one thumbs up

Sebastian

0 Likes
Message 6 of 10

dariopanic
Explorer
Explorer

My first approach was read doc and xls file the same way I read txt file, edit them, and then save them as doc and xls files respectively. The problem is, if you open doc file in notepad, and save it immediately without editing, the doc file would be corrupted. I assume it would be same behaviour doing that with lisp.

 

0 Likes
Message 7 of 10

cadffm
Consultant
Consultant

With this answer you have made it clear: you lack knowledge about file formats, Programming, interfaces etc.


What I wrote was the conversion from xls to txt (by using excel application, it is "save as *.txt" / or to *csv),

this is not the same as renaming the file extension or trying to edit xls or doc formats as a simple text file.


Sorry, I'm getting out of here.

Sebastian

0 Likes
Message 8 of 10

dariopanic
Explorer
Explorer

Why so? The same thing you can do with dxf/dwg files (open them as txt, make changes and save it) and it works.

 

Thinking you can do the same with *.doc or *.xls files isn't that much "horrible" idea how you presented it.

0 Likes
Message 9 of 10

cadffm
Consultant
Consultant

"how you described it."

The last one was just an reply to martti.halminen post.

 

My (first) answer was prefer to work the clean well working way, open the files by using activeX

with the source application, nothing else!

_

 

And further details of file codepages formats and write/read-line functions in general and specially for autolisp and

text code formats.. sorry again, no time to explain such things (in english).

I hope someone who will find it easier will give you the explanation.

Sebastian

0 Likes
Message 10 of 10

dariopanic
Explorer
Explorer

Sorry, I misunderstood that part 🙂 Anyway, tnx for your help.  I will post code here if I manage to create something usefull.

0 Likes