Bug 162096 - BASIC: com.sun.star.io.TextOutputStream writeString() method does not overwrite all the text file's contents
Summary: BASIC: com.sun.star.io.TextOutputStream writeString() method does not overwri...
Status: UNCONFIRMED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
24.2.4.2 release
Hardware: All Windows (All)
: medium minor
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-07-19 01:16 UTC by maruguchi_masahiro
Modified: 2024-07-19 05:36 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
archive of CSV + ODS containing macro (7.92 KB, application/zip)
2024-07-19 02:32 UTC, Stéphane Guillou (stragu)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description maruguchi_masahiro 2024-07-19 01:16:42 UTC
Description:
予想される動作としてmyTextFile.writeString("")を実行すればファイルの中身が削除されると思うのですが同じ座標の文字を置き換えるだけです。

Steps to Reproduce:
sub test()
	mySf = createUnoService("com.sun.star.ucb.SimpleFileAccess")
	myTextFile = createUnoService("com.sun.star.io.TextOutputStream")
    myFileStream = mySf.openFileWrite("c:\test\test.csv")
    myTextFile.OutputStream = myFileStream
    myTextFile.Encoding = "UTF-8"
    myTextFile.writeString("a")
    myTextFile.closeOutput()
end sub

既に何らかのデータが入ったファイルに対して上記の関数を実行する

Actual Results:
bbbというファイルがabbに書き換えられる

Expected Results:
bbbというファイルがaに書き換わる


Reproducible: Always


User Profile Reset: No

Additional Info:
If mySf.exists("c:\test\test.csv") Then
   mySf.kill("c:\test\test.csv")
End If

一度ファイルを削除してから上書きすることで回避している
Comment 1 Stéphane Guillou (stragu) 2024-07-19 02:32:16 UTC
Created attachment 195383 [details]
archive of CSV + ODS containing macro

OOo 3.3 behaved the same way.

I'm not sure I understand the use case. You want to overwrite the whole file, so why not use a different method that first empties its contents, or you workaround that deletes the file and creates a new one?
Comment 2 maruguchi_masahiro 2024-07-19 05:36:52 UTC
返信ありがとうございます。

一応現在はmySf.kill("c:\test\test.csv")を使うことで一度ファイルを削除してからファイルの作成を通じて上書きしています