Ask Your Question
0

macro to open a document & read the first line of text

asked 2015-04-13 11:13:08 +0200

jay Arr gravatar image

I have a need for a macro to open a document (it could be WORD, OO, LO, text or rtf) most importantly NOT to display it in a frame (I have 1000's of documents to process) and read the first line of text.

I've been reading Andrew Pitonyak excellent (if opaque) useful macro information but can't find anything useful.

I'm hoping that I can make use of LO's internals and have ONE macro to process any kind of document.Is that unreasonable?

Any pointers and/or code would be most useful.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2015-04-13 13:40:49 +0200

jay Arr gravatar image

updated 2015-04-13 13:42:33 +0200

This great! Thank you very much it's saved me hours of work. Doing this with VBA on Windows is much more complicated!

I've tested it with LO Version: 4.4.1.2 on my Apple iMac with OS X Yosemite 10.10.2 and it works for:

.docx .doc .odt .txt .rtf documents

it doesn't appear to work for .rtfd or TextEdit documents

Where can I find out more about using

com.sun.star.beans.PropertyValue

please?

edit flag offensive delete link more

Comments

css.beans.PropertyValue itself provides nothing of interest here its only a kind of "pack-box" for the Information of Interest ( the pair "Hidden": True in this case)

karolus gravatar imagekarolus ( 2015-04-13 13:59:47 +0200 )edit

Information on Hidden here

DLP done great work bug AKAIK not on RTFD, that said, if I'm not mistaken it is a bundle, a folder containing a RTF. So you can unzip...

pierre-yves samyn gravatar imagepierre-yves samyn ( 2015-04-13 18:56:58 +0200 )edit
0

answered 2015-04-13 11:53:16 +0200

pierre-yves samyn gravatar image

Hi - Attached is a sample procedure that meets the strict sense to demand: read the first line (and display). I draw your attention to the fact that it is the first line (not the first sentence or paragraph), and that the program not "loop" to look for the first line containing something.

Sub Main

dim sUrlDoc as string
dim oDoc as object, oCursor as object

dim Prop(0) as new com.sun.star.beans.PropertyValue

Prop(0).Name = "Hidden"
Prop(0).Value = true

sUrlDoc = convertToUrl("C:\Tests\a.odt")

oDoc = StarDesktop.loadComponentFromURL(sUrlDoc, "_blank", 0, Prop() )
oCursor = oDoc.CurrentController.viewCursor
oCursor.gotoStart(false)
oCursor.gotoEndOfLine(true)

msgbox oCursor.string

oDoc.close(true)

End Sub
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-04-13 11:13:08 +0200

Seen: 909 times

Last updated: Apr 13 '15