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

[SOLVED]Export from OO curent sheet to a text document

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
vladi
General User
General User


Joined: 26 Jun 2012
Posts: 7
Location: Romania

PostPosted: Tue Jun 26, 2012 1:47 am    Post subject: [SOLVED]Export from OO curent sheet to a text document Reply with quote

Hello,

I need a macro that gets all the information from all the rows and columns from the current opened spreadsheet. Searching this forum i found out that 2 for structures might be the answear thing is i dont know how to specify where should the for start and where should the for end
Up till now i got this piece of code:

Sub Exp
Dim Sheet As Object
Dim Cell As Object
Dim strTmp As String

Sheet=ThisComponent.CurrentController.ActiveSheet
For Row=RowStart To RowEnd
For Col=ColStart To ColEnd
Cell=Sheet.GetCellByPosition(Col,Row)
strTmp=Cell.String
Next Col
Next Row


i=FreeFile()
Open "D:\example.txt" For Output As i
Print #i, strTmp
Close #i

End Sub

Thanks in advance hope you can help me


Last edited by vladi on Tue Jun 26, 2012 10:17 pm; edited 1 time in total
Back to top
View user's profile Send private message
patel
Power User
Power User


Joined: 14 Apr 2012
Posts: 54
Location: Italy

PostPosted: Tue Jun 26, 2012 2:36 am    Post subject: Reply with quote

this macro export to csv file, you can arrange delimiters
Code:
Sub ExportCurrentToCsv
Dim args(2) as new com.sun.star.beans.PropertyValue
   ' This is the hardcoded pathname to a folder containing Excel files.
   cFolder = "C:\users\Andrew\Desktop\"

   ' Get the pathname of each file within the folder.
   cFile = "test.csv"
   cFieldDelimiters = ";"
   cTextDelimiter = Chr(34)
   cFieldTypes = "2/2/2/2/2/2/2/9/9/9/9/9/9/9/9/9/9"
   cFieldDelims = ""
   For i = 1 To Len( cFieldDelimiters )
       c = Mid( cFieldDelimiters, i, 1 )
       If Len( cFieldDelims ) > 0 Then
           cFieldDelims = cFieldDelims + "/"
       EndIf
       cFieldDelims = cFieldDelims + CStr(Asc( c ))
   Next
  If Len( cTextDelimiter ) > 0 Then
      cTextDelim = CStr(Asc( cTextDelimiter ))
  Else
      cTextDelim = "0"
  EndIf
  cFilterOptions = cFieldDelims + "," + cTextDelim + ",0,1," + cFieldTypes
  oDoc= ThisComponent
  oSheet = ThisComponent.Sheets(1)
  args(0).Name = "FilterName"
  args(0).Value = "Text - txt - csv (StarCalc)"
  args(1).Name = "FilterOptions"
  args(1).Value = cFilterOptions
  oDoc.StoreToURL( ConvertToUrl( cFolder + "/" + cFile ), args() )
End Sub

_________________
If your problem has been solved please add "[Solved]" to the beginning of your first post title (edit button).
Back to top
View user's profile Send private message
vladi
General User
General User


Joined: 26 Jun 2012
Posts: 7
Location: Romania

PostPosted: Tue Jun 26, 2012 3:18 am    Post subject: Reply with quote

Hey again tnx for the help but it doesnt work first of all when running the macro i get and error (error type:com.sun.star.taskErrorCodeIOException)
And secondly i already have a data in an open office spreadsheat (.ods).Thing is i need the data from my spreadsheet to be exported to .txt file. I dont have any business with excel spreadsheets but with OOffice spreadsheets.

So is what im asking even possible?
PS im a newbie when it comes to OO macros and code.

THanks

My Code:

Sub Test
Dim Sheet As Object
Dim Cell As Object
Dim str As String
Dim Count As Integer
count=0

i=FreeFile()
Open "D:\vladi.txt" For Output As i

Sheet=ThisComponent.CurrentController.ActiveSheet
Cell=Sheet.GetCellByPosition(0,count)
str=Cell.String


While Not(Cell.string="")
Print #i, str
count=count+1
Cell=Sheet.GetCellByPosition(0,count)
Wend
Close #i
End Sub

There are two problems with this code:
1. The macro exports to my .txt file only the first cell of my Open Office spreadsheet.
2. It prints into .txt file the first cell multiple times


i want it to print to the txt file all of my data from the Open Office spreadsheet
Back to top
View user's profile Send private message
patel
Power User
Power User


Joined: 14 Apr 2012
Posts: 54
Location: Italy

PostPosted: Tue Jun 26, 2012 7:44 am    Post subject: Reply with quote

Code:
Sub Test
Dim Sheet As Object
Dim Cell As Object
Dim str As String
Dim Count As Integer
count=0
i=FreeFile()
Open "D:\vladi.txt" For Output As i
Sheet=ThisComponent.CurrentController.ActiveSheet
str="prova"
While Not(str="")
  str=Sheet.GetCellByPosition(0,count).string
  Print #i, str
  count=count+1
Wend
Close #i
End Sub

_________________
If your problem has been solved please add "[Solved]" to the beginning of your first post title (edit button).
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 Macros and API 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