Page 1 of 1

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

Posted: Fri Nov 18, 2011 12:08 pm
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

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

Posted: Fri Nov 18, 2011 1:08 pm
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)

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

Posted: Fri Nov 18, 2011 1:26 pm
by saurabh42s
sheetCount is number of sheets in our spreadsheet.

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

Posted: Fri Nov 18, 2011 1:35 pm
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?

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

Posted: Fri Nov 18, 2011 1:50 pm
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.
:(

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

Posted: Fri Nov 18, 2011 1:54 pm
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?

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

Posted: Fri Nov 18, 2011 2:03 pm
by saurabh42s
i want to save all the data that the user enters in the sheet.
Like the attached file.

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

Posted: Fri Nov 18, 2011 2:17 pm
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

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

Posted: Wed Nov 23, 2011 6:54 am
by saurabh42s
Hats Off to Mr Pitonyak and Mr. JohnSUN-Pensioner.
You both have saved me from facing a big problem.
Thanx a Lot...

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

Posted: Fri Nov 25, 2011 8:21 am
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

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

Posted: Fri Nov 25, 2011 11:39 am
by kingfisher
Have a look at the method createCursor. For that you will not need the text you mention.

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

Posted: Fri Nov 25, 2011 12:04 pm
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.

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

Posted: Fri Nov 25, 2011 3:16 pm
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

:)