2015-01-20 12:49 GMT+01:00 Stuart Murray <s.mur...@hart-builders.co.uk>:

> When I save information as a CSV file it brings up the text import window.
> I click on ok and then it always opens the file. Is there a way of
> preventing the file from opening when I click on ok? I do this several
> times a day every day so each file saved needs to be closed after it is
> saved. It's not the end of the world but it would save a little time each
> day and the make the process sleeker for the dozen or so files I am saving
> all at the same time each day.
>
> Many thanks
>
> Stuart
>
>
I'm afraid I can't answer your question, but I still have something to say,
I think.

I had a couple of spreadsheets that I needed to convert to csv (or rather
tsv – Tab Separated Values, but I still used the .csv suffix) and copy it
to my Android phone, so I could view it there with a simple csv app…

I used a macro for it and I ran the macro by pushing a button that I added
to the first row of the spreadsheet. That row is always visible, since I
use the Freeze feature, otherwise I could run the macro from the keyboard,
add a menu item or something.

Anyway, I only needed this for one or two particular document, so some
things in my macro are hard coded. I just wanted to get the job done, so to
speak…

Here it is. If you want to use it, you need to edit at least the hard coded
path (which is faked in this version anyway)…
I removed the part where it moves the csv to the phone, since that part is
done by a Bash script anyway, called from the macro.

Sub SaveAsCsv
' Place the cursor at the first unused row.
Call SelectRow

' Then, save the spreadsheet.
ThisComponent.store()

' Now, save the active sheet as CSV.
Dim PropVal(1) as New com.sun.star.beans.PropertyValue
PropVal(0).Name="FilterName"
PropVal(0).Value="Text - txt - csv (StarCalc)"
PropVal(1).Name="FilterOptions"
REM You need to edit the line below if you prefer saving as csv rather than
tsv.
REM I don't remember which number means what, but I remember that I
REM ”Googled it” to determine the number that I actually used. A wild guess
REM would be that the 9 means TAB (since that is its ASCII-code), but I'm
REM sure some ”Googling” will get the right numbers for you.
PropVal(1).Value ="9,34,0,1,1"

Dim FileURL As String, FilePath As String
REM The next line needs to be edited. I'm not sure why I hard coded the
path,
REM but I think I remember that I just couldn't find another way at the
time being.
REM I still would like to know, so if anyone… There should be a simple way
to
REM find out the path to the current file, shouldn't it? I think there were
some
REM discussions about this in this mailing list, but I don't remember if
anyone
REM finally figured it out…
FilePath="/some/path/to/this/file/"
FilePath=FilePath & ThisComponent.getTitle()
FileUrl=ConvertToUrl(FilePath)
FileUrl=Left(FileUrl,Len(FileUrl)-3) & "csv"
ThisComponent.StoreToUrl(FileUrl, PropVal())
End Sub

Sub SelectRow
Dim Row As Integer, Sheet As Object
 Sheet=ThisComponent.Sheets.getByName("Tider")
Row=Sheet.getCellByPosition(0,0).getValue()
SelectFirstEmptyRow(Sheet,0,Row)
End Sub

Sub SelectFirstEmptyRow(Sheet As Object, Column As Integer,Row As Integer)
Dim Cell As Object
Dim Ranges As Object

Cell=Sheet.GetCellByPosition(Column,Row)

SelectCell(Sheet,Column,Row)
End Sub

Function SelectCell(Sheet As Object, Column As Integer,Row As Integer)
' Select and highlight the cell
ThisComponent.CurrentController.Select(Sheet.getCellByPosition(Column,Row))
SelectEmptyRange
End Function

Sub SelectEmptyRange
Dim EmptyRange

EmptyRange=ThisComponent.createInstance("com.sun.star.sheet.SheetCellRanges")
ThisComponent.CurrentController.Select(EmptyRange)
End Sub


Read the REM lines above for more information…



Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ

Reply via email to