How to save all separate spreadsheets using libre office calc?

i am new using libre office
how to save all separate spreadsheets using libre office calc?
like
Split a Workbook to Separate Excel Files with VBA code

If i using excel i can ALT+F11 and using this modul

Sub Splitbook()
'Updateby20140612
Dim xPath As String
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each xWs In ThisWorkbook.Sheets
    xWs.Copy
    Application.ActiveWorkbook.SaveAs Filename:=xPath & "C:\Users\Administrator\Documents\testing\" & xWs.Name & ".xlsx"
    Application.ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

But how about to libre office calc
can same like excel ??

i need help guys
thx for your kindes

Welcome @yagami456 !
Does this code work in Excel? I’m a little puzzled by the line
Filename:=xPath & "C:\Users\Administrator\Documents\testing\" & xWs.Name & ".xlsx"

Hallo
Example in python:

from pathlib import Path
from com.sun.star.beans import PropertyValue as PV


def new_doc(which):
    pv = PV()
    pv.Name = "Hidden"
    pv.Value = True
    desktop = XSCRIPTCONTEXT.getDesktop()
    return desktop.loadComponentFromURL(f"private:factory/s{which}",
                                       "_blank",
                                       0,
                                       (pv,))

def store_to_single_sheets(*_):
    folder = Path.home() / "Documents"
    source_doc = XSCRIPTCONTEXT.getDocument()
    sheets = source_doc.Sheets
    target = new_doc('calc')
    
    for sheet in sheets:
        target.Sheets.importSheet(source_doc, sheet.Name,0)
        for t_sheet in target.Sheets.ElementNames:
            if t_sheet != sheet.Name:
                target.Sheets.removeByName(t_sheet)        
        url = (folder / f"{sheet.Name}.ods").as_uri()
        target.storeToURL(url, ())
    target.close(True)

In BASIC this is written a little longer:

Sub DivideSpreadsgeets()
Dim filePicker As Object, oDoc As Object, oArgs As Variant
Dim fileName As String, fileURL As String, sheetName As String, fileFilter As String
Dim i As Integer
Dim oSheets As Object, sheet As Object, aSheetsNames As Variant 
Dim aOpenParams(0) as New com.sun.star.beans.PropertyValue 
	aOpenParams(0).Name  = "Hidden"	:   aOpenParams(0).Value = TRUE
	GlobalScope.BasicLibraries.LoadLibrary("Tools")
	filePicker = createUnoService("com.sun.star.ui.dialogs.FilePicker")
	filePicker.setMultiSelectionMode(True)
	filePicker.setTitle("Select Source Files")
	filePicker.appendFilter("All Files", "*.ods;*.xls;*.xlsx;*.xlsm")
	If filePicker.execute() Then
    	For Each fileURL In filePicker.getSelectedFiles()
	    	fileName = GetFileNameWithoutExtension(ConvertFromURL(fileURL))
	    	oDoc = OpenDocument(fileURL, aOpenParams)
	    	oSheets = oDoc.getSheets()
	    	aSheetsNames = oSheets.getElementNames()
	    	fileFilter = "calc8"
	    	For Each oArgs In oDoc.getArgs()
	    		If oArgs.Name = "FilterName" Then 
	    			fileFilter = oArgs.Value
	    			Exit For 
	    		EndIf 
	    	Next oArgs
	    	oDoc.close(True)
	    	For Each sheetName In aSheetsNames
	    		oDoc = OpenDocument("private:factory/scalc", aOpenParams)
	    		oSheets = oDoc.getSheets()
	    		For i = oSheets.getCount()-1 To 1 Step -1
	    			oSheets.RemoveByName(oSheets.getByIndex(i).getName())
	    		Next i
	    		sheet = oSheets.getByIndex(0)
	    		sheet.setName(sheetName)
	    		sheet.link(fileURL, sheetName, fileFilter, "", com.sun.star.sheet.SheetLinkMode.VALUE) 'NORMAL) '
	    		sheet.setLinkMode(com.sun.star.sheet.SheetLinkMode.NONE)
	    		oDoc.storeToURL(ConvertToURL(fileName & "." & sheetName & ".ods"), Array())
	    		oDoc.close(True)
		    Next sheetName
	    Next fileURL
	    MsgBox "Splitted " & (UBound(filePicker.getSelectedFiles()) + 1) & " files", 16, "Done"
	End If
End Sub
1 Like