Empty cell as result of formula

How can I create an empty cell as a result of a formula in Calc?

I know I can do

IF(foo, 1, “”)

in order to create an empty string, but that is not the same as an empty cell, as can be seen for example when exporting as CSV.

That’s not possible with a formula alone. You can, however, create a macro that will do Find and Replace and delete the contents of any cells with a certain value. In your IF formula, instead of using “” to return an empty string, have it return a unique value that will not be used in the rest of your spreadsheet, either text or number. Then run your macro that will open the Find & Replace dialog, enter that unique string in Search For and leave Replace With blank. The macro will empty all the cells in your sheet with the specified value and you can export to CSV with empty cells.