Guest User

Nanotech Libreoffice Calc Csv Macro v1.2

a guest
Apr 15th, 2023
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1.  
  2. REM ***** BASIC *****
  3. ' tested on Libreoffice Calc 7.5.1.2 (x86_64) build:fcbaee479e84c6cd81291587d2ee68cba099e129 on Windows 10;
  4. ' It saves the current document and exports a csv copy to the same folder as the saved document;
  5. ' CSV delimters are ';' and text as "; on line: Propval(1).Value ="59,34,0,1,1" 'ASCII 59 = ; 34 = ";
  6. ' Name of file is the sheet name, this macro also exports all sheets you have on the ods file.
  7. '
  8. ' This macro is now Version 1.2! It exports to a parent folder + the given data folder name.
  9. ' See below where you can change the folder it exports to.
  10.  
  11. ' This is the function which will return the parent folder of the document
  12. Function GetParentFolder
  13. sUrl = ThisComponent.getURL()
  14. sParts = Split(sUrl, "/")
  15. 'ReDim will preserve the array parts, so -2 means
  16. '-1 the document path, and -1 the document folder,
  17. 'by that we get the parent folder.
  18. ReDim Preserve sParts(0 to UBound(sParts) - 2)
  19. GetParentFolder = Join(sParts, "/")
  20. End Function
  21.  
  22.  
  23. Sub Save_and_Export_CSV
  24. document = ThisComponent
  25. ThisComponent.Store
  26. GlobalScope.BasicLibraries.loadLibrary("Tools")
  27.  
  28. FileDirectoryParent = GetParentFolder()
  29. DataFolder = "data/" 'This is the name of your data folder!
  30. ' If the folder doesn't exist it is going to create a new one.
  31.  
  32. Sheets = document.Sheets
  33. NumSheets = Sheets.Count - 1
  34. Dim Propval(1) as New com.sun.star.beans.PropertyValue
  35. Propval(0).Name = "FilterName"
  36. Propval(0).Value = "Text - txt - csv (StarCalc)"
  37. Propval(1).Name = "FilterOptions"
  38. Propval(1).Value ="59,34,0,1,1" 'ASCII 59 = ; 34 = ";
  39. For I = 0 to NumSheets
  40. document.getCurrentController.setActiveSheet(Sheets(I))
  41. Filename = FileDirectoryParent + "/" + DataFolder + Sheets(I).Name + ".csvdata"
  42. FileURL = convertToURL(Filename)
  43. document.StoreToURL(FileURL, Propval())
  44. Next I
  45. End Sub
  46.  
Advertisement
Add Comment
Please, Sign In to add comment