I have a LibreOffice sheet where many of the cells contain the string "<br>"
. I want to replace that string with a new line. So something like this:
- some text
2. some more text
becomes
- some text
- some more text
How do I do that? I tried using the Regular Expression field and it put the string "\n"
in the cell, so I don’t think that’s the right way. I tried using alt+010 on the numpad but that doesn’t do anything.
EDIT: In case someone thinks of suggesting it, I did ask ChatGPT to do it for me and it worked. I would still like to know how to do it within Calc. if it’s possible. This the Python code it used:
import pandas as pd
import openpyxl
from odf.opendocument import load
from odf.table import Table, TableRow, TableCell
from odf.text import P
# Load the ODS file
file_path = '/mnt/data/BR-to-NL.ods'
doc = load(file_path)
# Function to replace "<br>" with newline
def replace_br_with_newline(cell):
if cell:
text_elements = cell.getElementsByType(P)
for element in text_elements:
text_content = element.firstChild
if text_content and text_content.data:
# Replace "<br>" with newline
text_content.data = text_content.data.replace("<br>", "\n")
return cell
# Process all tables in the document
for table in doc.spreadsheet.getElementsByType(Table):
for row in table.getElementsByType(TableRow):
for cell in row.getElementsByType(TableCell):
replace_br_with_newline(cell)
# Save the modified file
modified_file_path = '/mnt/data/Modified_BR-to-NL.ods'
doc.save(modified_file_path)
modified_file_path
L
Text with BR.ods (10.3 KB)