Step 1: Set up the ODBC Data Source
- Install the ODBC driver for SQL Server (if not already installed) as described in the previous answer.
- Configure the ODBC Data Source:
- Open the ODBC Data Source Administrator (in Windows, search for “ODBC Data Sources”).
- Click on the System DSN tab (for all users) or User DSN (for only your user).
- Click Add, select the ODBC Driver for SQL Server, and set up the connection to your SQL Server.
- Test the connection and complete the setup.
Step 2: Set up the ODBC Connection in LibreOffice
- Open LibreOffice Base (even though we’ll be using Calc, Base is needed to manage the database connection).
- Create a New Database:
- Choose “Connect to an existing database” from the initial screen.
- From the dropdown, select ODBC and click Next.
- Select ODBC Data Source:
- Click on Browse, and a window showing your system’s ODBC connections will open.
- Select the ODBC data source you created earlier for the SQL Server connection, then click OK.
- Enter your credentials:
- If your SQL Server requires a username and password, you’ll be prompted to enter them. You can save them for future use if desired.
- Save the Base Database file:
- LibreOffice Base will ask you to save the connection as a
.odb
file. This file is required for managing the connection to the database from Calc.
- LibreOffice Base will ask you to save the connection as a
- Test the Connection:
- When asked, click Yes to test the connection to make sure everything is set up correctly. You should be able to see the tables from your SQL Server.
Step 3: Import Data from Base to Calc
- Open LibreOffice Calc and go to Data > Select Range.
- To import data:
- Click View > Data Sources (or press
Ctrl+Shift+F4
). - This will open a pane with all registered data sources. Find your ODBC connection in the pane (it will show up as the
.odb
file you saved earlier). - Navigate to the table or query you want to use.
- Click View > Data Sources (or press
- Drag and drop the query or table from the data source window into your Calc spreadsheet. The data should populate in your spreadsheet.
Step 54: Enable Data Refresh in Calc
Now that the data is imported:
- Select the range of data that you imported.
- Go to Data > Define Range, and give the range a name.
- After defining the data range, the Refresh Range option should now be enabled.
- To refresh the data, go to Data > Refresh Range. This will pull the latest data from the connected SQL Server through the ODBC connection.
This process correctly handles database connections between LibreOffice Calc and SQL Server via ODBC.