OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Split large file into individual pages - uniq file names

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Writer
View previous topic :: View next topic  
Author Message
jaykup
Newbie
Newbie


Joined: 09 May 2006
Posts: 2

PostPosted: Mon Apr 02, 2007 12:19 pm    Post subject: Split large file into individual pages - uniq file names Reply with quote

I have a very large (300+ page) odt document that has the following layout:

Quote:

A577 BLACK

Delrin A577 BLACK ACETAL, G-FILLED

Acetal

_________________Virgin
_________________Regrind
Weight:_________________
Verified By:______________
Date Verified:_____________


The first three lines change with each page, the rest is the same.

I would like to split this into 300+ files all with the file names corresponding to the unique first line. How can I do this?

os: Windows 2000 / Slackware 10.2
Back to top
View user's profile Send private message
conficio
General User
General User


Joined: 06 Jun 2006
Posts: 16
Location: Melrose, MA USA

PostPosted: Thu Apr 05, 2007 5:52 am    Post subject: Reply with quote

It won't be an easy thing that you get tools for.

However, the *.odt files are compressed xml files. I'm not sure if you can uncompress them with WinZip and then attack it with n XSLT script.

The other option would be to write a macro, that does this for you.

Are you a programmer? If not, I'd look for someone to do it for you and pay her.

K<o>
_________________
Plan-B for OpenOffice.org - Software Help for the Rest of Us!
by Conficio - teaching software one screencast at a time
Back to top
View user's profile Send private message Visit poster's website
acknak
Moderator
Moderator


Joined: 13 Aug 2004
Posts: 4295
Location: ~ 40°N,75°W

PostPosted: Thu Apr 05, 2007 11:26 am    Post subject: Reply with quote

Could I ask why you want to do this? It sounds like something you'll later wish to un-do Wink
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Fri Apr 06, 2007 6:20 am    Post subject: Reply with quote

Here's a macro that should do what you want. Because it will overwrite existing files I would suggest that you put your current file in a new directory so there are no other files in that directory to worry about.
Code:
'Creates one file per page of current file
'with file name = 1st para with text. WARNING, will
'overwrite file with same name without asking.
Option Explicit
Sub ManyFromOne
Dim oDoc,sUrl,fPath,oVC,oTC,fName,s
Dim oNew,oNewVC,oNewTC,oStart,nUrl
oDoc = ThisComponent
sUrl = oDoc.URL
s = Split(sUrl,"/") : s(uBound(s)) = ""
fPath = Join(s,"/")
oVC = oDoc.CurrentController.getViewCursor
oVC.gotoStart(false)
oTC = oDoc.Text.createTextCursor
oNew = StarDesktop.loadComponentFromUrl("private:factory/swriter","_blank",0,Array())
oNewVC = oNew.CurrentController.getViewCursor
Do
 oStart = oDoc.Text.createTextCursorByRange(oVC)'The beginning of a page.
 oTC.gotoRange(oVC,false)
 TryAgain:
 While oTC.isEndOfParagraph 'Get the filename from first para. with text.
  oTC.gotoNextParagraph(false)
 Wend
 oTC.gotoEndOfParagraph(true)
 fName = Trim(oTC.String)
 If Len(fName) = 0 then 'File name was from para. with spaces only.
   oTC.collapseToEnd : oTC.gotoNextParagraph(false)
   GoTo TryAgain
  Else nUrl = fPath & fName & ".odt"
 EndIf
 oVC.JumpToEndOfPage
 oVC.gotoRange(oStart,true)
 oNewVC.String = oVC.String
 oNewTC = oNew.Text.createTextCursor
 While oNewTC.gotoNextParagraph(false) 'Delete line breaks at
  oNewTC.goRight(1,true)               'beginning of paras.
  IF Asc(oNewTC.String) = 10 then oNewTC.String = ""
 Wend 
 oNew.StoreToURL(nUrl,Array())
 oNewVC.String = "" : oVC.collapseToEnd
Loop While oVC.JumpToNextPage
oNew.dispose
End Sub
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Writer All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group