Why the data write into only one file?

Crate a dictionary which contain values .

/tmp/test1.ods 1
/tmp/test2.ods 1

I want number 100 into A1 in both /tmp/test1.ods and /tmp/test1.ods just after the file created.

Sub loopwrite
    GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
    Dim oDict As Variant
    Dim oDesk As Object
    Dim oDoc As Object
    Dim sURL As String
    Dim sFilePath As String
    Dim oFileAccess As Object 
    Dim key as String
        
    oDict = CreateScriptService("Dictionary")    
    oDesk = StarDesktop
    sURL = "private:factory/scalc"
    oDoc = oDesk.loadComponentFromURL(sURL, "_blank", 0, Array())
    oDict.Add  "/tmp/test1.ods" , 1
    oDict.Add  "/tmp/test2.ods" , 2

    oFileAccess = createUnoService("com.sun.star.ucb.SimpleFileAccess")
    For Each key In oDict.Keys
        sFilePath = ConvertToURL(key)  
        if not  oFileAccess.exists(sFilePath) Then
            oDoc.storeAsURL(sFilePath, Array())
            oDoc.getSheets().getByName("Sheet1").getCellByPosition(0,0).value = 100
        end if
    Next key     
end sub

Why the data write into only one file “/tmp/test2.ods” ?

cause that’s what you programmed :wink:

try

[...]
            oDoc.getSheets().getByName("Sheet1").getCellByPosition(0,0).value = 100
            oDoc.storeAsURL(sFilePath, Array())

(post deleted by author)