Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 339427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:31:19+00:00 2026-05-12T10:31:19+00:00

Given: I recorded a simple macro in Openoffice to save my worksheet as a

  • 0

Given: I recorded a simple macro in Openoffice to save my worksheet as a CSV file. Here it is.

sub toCSV
dim document   as object
dim dispatcher as object
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(2) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = "file:///path/csv/filename.csv"
args1(1).Name = "FilterName"
args1(1).Value = "Text - txt - csv (StarCalc)"
args1(2).Name = "FilterOptions"
args1(2).Value = "59,34,76,1"
dispatcher.executeDispatch(document, ".uno:SaveAs", "", 0, args1())
end sub

Problem: I want to add some features to this function. 1. I need to get the current XLS filename so that I can put that at the end of my static path. So file:///path/csv/ is going to always remain the same, and filename.csv will be coming from filename.xls. 2. Well, I’ll need to do some regex replacement on that filename-revision01.xls to ultimately get filename.csv.

I can do regex matching well, I’m simply looking for hints on string concatenation, how to get the current filename, and how to write a regex expression within a macro.

BTW, what is this language called!?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:31:20+00:00Added an answer on May 12, 2026 at 10:31 am

    This is the solution I came up with to help in exporting a CSV (with my export options, filename adjustment, and file location) with one click.
    I’m on a Mac, so the file paths will be for such an operating system. The information that helped me do this is here.

    REM  *****  BASIC  *****
    sub toCSV
    dim document   as object
    dim dispatcher as object
    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    FileURL = ThisComponent.URL
    oMasterScriptProviderFactory = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
    oMasterScriptProvider = oMasterScriptProviderFactory.createScriptProvider("")
    oScriptReplace = oMasterScriptProvider.getScript("vnd.sun.star.script:Tools.Regex.js?language=JavaScript&location=user")
    sReturn = RegExpReplace(oScriptReplace, FileURL, "(.*)/(\w*-\w*)(-revision\d*)+\.xls", "i", "$2.csv")
    dim args1(2) as new com.sun.star.beans.PropertyValue
    args1(0).Name = "URL"
    args1(0).Value = "file:///Users/joe/Documents/mydocuments/trunk/my%20projects/dictionary/verbsXLS/proofed/csv/" + sReturn
    args1(1).Name = "FilterName"
    args1(1).Value = "Text - txt - csv (StarCalc)"
    args1(2).Name = "FilterOptions"
    args1(2).Value = "59,34,76,1"
    dispatcher.executeDispatch(document, ".uno:SaveAs", "", 0, args1())
    end sub
    
    function RegExpReplace(oScriptReplace as Object, sSource as String, sRegExp as String, sGlobUpcase as String, sReplace as String) as String
    RegExpReplace = oScriptReplace.invoke(Array(sSource, sRegExp, sGlobUpcase, sReplace ), Array(), Array())
    end function
    

    Here is a bit of javascript that the above macro relies upon. This file is named ~/Library/Application\ Support/OpenOffice.org/3/user/Scripts/javascript/Tools/Regex.js and is hardcoded and referenced above.

    sSource     = String(ARGUMENTS[0])
    sRegExp     = String(ARGUMENTS[1])
    sGlobUpcase = (ARGUMENTS[2])
    sReplace    = String(ARGUMENTS[3])
    myRe   = new RegExp(sRegExp, sGlobUpcase)
    ret = sSource.replace(myRe, sReplace)
    

    Finally, this post gives details on how to add a toolbar button to run your macro with one click.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a Python object of any kind, is there an easy way to get
Given the URL (single line): http://test.example.com/dir/subdir/file.html How can I extract the following parts using
Given a (source) patch file, what's the easiest way to apply this patch on
Given a specific DateTime value, how do I display relative time, like: 2 hours
Given a select with multiple option's in jQuery. $select = $(<select></select>); $select.append(<option>Jason</option>) //Key =
Given a DateTime representing a person's birthday, how do I calculate their age in
Given an absolute or relative path (in a Unix-like system), I would like to
Given 2 rgb colors and a rectangular area, I'd like to generate a basic
Given this HTML: <ul id=topnav> <li id=topnav_galleries><a href=#>Galleries</a></li> <li id=topnav_information><a href=#>Information</a></li> </ul> And this
Given a latitude and longitude, what is the easiest way to find the name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.