[Solved] Generating .CSV file on upload of an ODS Sheet

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
saurabh42s
Posts: 34
Joined: Wed Oct 19, 2011 7:42 am

[Solved] Generating .CSV file on upload of an ODS Sheet

Post by saurabh42s »

Friends,
I have an ODS Sheet. I have to Generate .csv file on its upload.I dont have code to generate .csv file. :crazy:
Can anyone help me out in solving this?

Please find attached the sheet of whose .csv file is to be generated
Password : formvat48
Attachments
FORM VAT 48.ods
(72.44 KiB) Downloaded 342 times
Last edited by saurabh42s on Fri Nov 25, 2011 3:17 pm, edited 4 times in total.
OpenOffice 3.3 on Windows Vista
User avatar
JohnSUN-Pensioner
Volunteer
Posts: 876
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: How to Generate .CSV file on upload of an ODS Sheet?

Post by JohnSUN-Pensioner »

Excuse me, what means "If (sheetCount > 0) Then" ?..

About CSV-files... See example of storeToURL in [url=hhttp://www.pitonyak.org/oo.php]"AndrewMacro"[/url] (Listing 5.43: Export a document) and chapter 12.4.6.Loading and saving documents in "OOME_3_0" (about CSV filter options)
I may not have a lot to give but what I got I'll give to you...
Apache OpenOffice 4.1.5, LibreOffice 6.4.4.2 (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
saurabh42s
Posts: 34
Joined: Wed Oct 19, 2011 7:42 am

Re: How to Generate .CSV file on upload of an ODS Sheet?

Post by saurabh42s »

sheetCount is number of sheets in our spreadsheet.
OpenOffice 3.3 on Windows Vista
User avatar
JohnSUN-Pensioner
Volunteer
Posts: 876
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: How to Generate .CSV file on upload of an ODS Sheet?

Post by JohnSUN-Pensioner »

Oh, yes! Of course!
I ask about "Else" for this "If"... What value will be firstRowValue and secondRowValue if the number of sheets in the workbook is less than 1?
I may not have a lot to give but what I got I'll give to you...
Apache OpenOffice 4.1.5, LibreOffice 6.4.4.2 (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
saurabh42s
Posts: 34
Joined: Wed Oct 19, 2011 7:42 am

Re: How to Generate .CSV file on upload of an ODS Sheet?

Post by saurabh42s »

actually its a copy paste from somewhere.
Even i am also not sure what it actually does.
I have tried their code(from which i have copied), but its not working.
:(
OpenOffice 3.3 on Windows Vista
User avatar
JohnSUN-Pensioner
Volunteer
Posts: 876
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: How to Generate .CSV file on upload of an ODS Sheet?

Post by JohnSUN-Pensioner »

Once upon a time I tried to create a workbook with no sheets. Or at least with all the hidden pages. I did not. I was hoping that you know how.

What information do you want to save to CSV-file?
I may not have a lot to give but what I got I'll give to you...
Apache OpenOffice 4.1.5, LibreOffice 6.4.4.2 (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
saurabh42s
Posts: 34
Joined: Wed Oct 19, 2011 7:42 am

Re: How to Generate .CSV file on upload of an ODS Sheet?

Post by saurabh42s »

i want to save all the data that the user enters in the sheet.
Like the attached file.
Attachments
FORM VAT48.jpg
OpenOffice 3.3 on Windows Vista
User avatar
JohnSUN-Pensioner
Volunteer
Posts: 876
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: How to Generate .CSV file on upload of an ODS Sheet?

Post by JohnSUN-Pensioner »

...and to a string "This is end"?

Your macro will not work now because it is written at the beginning of the module "Option Explicit" but in code you use FileN without Dim.
In addition function fSaveFile() is nowhere written.

Operator "On Error GoTo Errorhandle" works on any of these mistakes and you get the message about "Modifications Are Not Saved,Upload File Not Generated"

Try "Listing 5.43: Export a document"
 Edit: You've been silent 

Code: Select all

Public Sub Generate_upload()
Dim sURL$ As String ' URL of current workbook
Dim FileN As String ' URL of target CSV-file
Dim oCurrentController As Object ' Before save - activate sheet sSheetName
Dim storeParms(2) as new com.sun.star.beans.PropertyValue ' You must delete Option VBASupport 1
REM in header of module. Otherwise, this line would be a mistake!
Const sSheetName = "VAT 48"
	GlobalScope.BasicLibraries.LoadLibrary("Tools") ' Only for GetFileName
	sURL = thisComponent.getURL()
	FileN = GetFileNameWithoutExtension(sURL) & ".csv"
REM Options to StoreTo:
	storeParms(0).Name = "FilterName"
	storeParms(0).Value = "Text - txt - csv (StarCalc)" 
REM See name of your filter vs Listing 5.45: Enumerate all supported filter names.
	storeParms(1).Name = "FilterOptions"
	storeParms(1).Value = "44,34,76,1,,0,true,true,true"
REM About this string see 12.4.6.Loading and saving documents in "OOME_3_0"
	storeParms(2).Name = "Overwrite"
	storeParms(2).Value = True 
REM Activate sheet for export - select "VAT 48"
	thisComponent.getCurrentController().setActiveSheet(thisComponent.getSheets().getByName(sSheetName))
REM storeToURL can raises com.sun.star.io.IOException! Only now:
On Error GoTo Errorhandle
REM Export
	thisComponent.storeToURL(FileN,storeParms())
	MsgBox ("No Error Found,Upload file is saved : """ + ConvertFromUrl(FileN) + """.")
Exit Sub
REM Do not thank me, thank Mr. Pitonyak. You can do it right here. He reads this forum.  
Errorhandle:
    MsgBox ("Modifications Are Not Saved,Upload File Not Generated" & chr(13) _
    & "May be table " & ConvertFromUrl(FileN) & " is open in another window?")
    Exit Sub
    Resume
End Sub
I may not have a lot to give but what I got I'll give to you...
Apache OpenOffice 4.1.5, LibreOffice 6.4.4.2 (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
saurabh42s
Posts: 34
Joined: Wed Oct 19, 2011 7:42 am

Re: How to Generate .CSV file on upload of an ODS Sheet?

Post by saurabh42s »

Hats Off to Mr Pitonyak and Mr. JohnSUN-Pensioner.
You both have saved me from facing a big problem.
Thanx a Lot...
OpenOffice 3.3 on Windows Vista
saurabh42s
Posts: 34
Joined: Wed Oct 19, 2011 7:42 am

Re: Generating .CSV file on upload of an ODS Sheet

Post by saurabh42s »

Here is another problem in the sheet.
I have marked a text "This is end" in the sheet to determine the last cell via a function called "lena".
Now in its upload file it is showing this text.
I don't want the Text "This is end" in the generate upload file(.CSV file).
Please help me guyz...
Password : formvat48
Attachments
FORM VAT 48.ods
Sheet
(71.26 KiB) Downloaded 261 times
image
image
OpenOffice 3.3 on Windows Vista
User avatar
kingfisher
Volunteer
Posts: 2123
Joined: Tue Nov 20, 2007 10:53 am

Re: [Solved] Generating .CSV file on upload of an ODS Sheet

Post by kingfisher »

Have a look at the method createCursor. For that you will not need the text you mention.
Apache OpenOffice 4.1.9 on Linux
User avatar
JohnSUN-Pensioner
Volunteer
Posts: 876
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: Generating .CSV file on upload of an ODS Sheet

Post by JohnSUN-Pensioner »

Do you remember this string in my macro?

Code: Select all

GlobalScope.BasicLibraries.LoadLibrary("Tools") ' Only for GetFileName
The library Tools have a function GetLastUsedRow.
That with method createCursor (thank you, kingfisher, you are right!) find index of last used row.
I may not have a lot to give but what I got I'll give to you...
Apache OpenOffice 4.1.5, LibreOffice 6.4.4.2 (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
saurabh42s
Posts: 34
Joined: Wed Oct 19, 2011 7:42 am

Re: Generating .CSV file on upload of an ODS Sheet

Post by saurabh42s »

Thanks, Thanks , Thanks a lot Mr. KingFisher and Mr. JohnSUN-Pensioner , it got solved
I have used this function ::

Function getLastUsedRow(oSheet as Object) as Integer
Dim oCell As Object
Dim oCursor As Object
Dim aAddress As Variant
oCell = oSheet.GetCellbyPosition( 0, 0 )
oCursor = oSheet.createCursorByRange(oCell)
oCursor.GotoEndOfUsedArea(True)
aAddress = oCursor.RangeAddress
GetLastUsedRow = aAddress.EndRow
End Function

:)
OpenOffice 3.3 on Windows Vista
Post Reply