Streamline Your Workflow: OpenOffice Calc Multiple ODS File Importer
Manually copying data from dozens of OpenDocument Spreadsheet (ODS) files is a major productivity killer. If your daily routine involves opening separate sheets just to consolidate rows into a master report, you are losing valuable time. Fortunately, you can automate this entire process.
By using OpenOffice Basic macros, you can build a custom importer that merges multiple ODS files into a single, centralized sheet with a single click. Why Automate Document Consolidation?
Eliminate Human Error: Manual copying risks missing rows, duplicating data, or pasting information into the wrong columns.
Save Massive Time: A macro processes dozens of files in seconds, freeing you up for critical data analysis.
Standardize Workflows: Automated scripts ensure that data from different departments or dates is combined uniformly every single time. Setting Up Your Master Spreadsheet
Before running the import automation script, you need to prepare your workspace.
Create a Master File: Open a fresh OpenOffice Calc spreadsheet and save it as Master_Importer.ods.
Label the Target Sheet: Rename your first sheet tab to Consolidated Data.
Set Up Headers: Add your column headers (e.g., Date, ID, Product, Revenue) in Row 1. Ensure these headers match the column structure of the source files you plan to import. The Macro Code: Multiple ODS Importer
OpenOffice features a built-in macro recorder, but recording cannot handle looping through separate files in a folder. For that, we use OpenOffice Basic.
To add the code, go to Tools > Macros > Organize Macros > OpenOffice Basic. Click Edit on your standard module and paste the following script:
Sub ImportMultipleODSFiles Dim Doc As Object Dim Sheet As Object Dim TargetSheet As Object Dim SourceDoc As Object Dim FolderPath As String Dim FileName As String Dim NextRow As Long Dim SourceRow As Long ‘ Define the master target sheet Doc = ThisComponent TargetSheet = Doc.Sheets.getByName(“Consolidated Data”) ’ Find the first empty row in the master sheet NextRow = GetLastRow(TargetSheet) + 1 ‘ Set the directory path containing your source ODS files ’ NOTE: Use the URL format (file:///C:/folder/) FolderPath = “file:///C:/YourSourceFolder/” FileName = Dir(FolderPath & “*.ods”, 0) ‘ Loop through all ODS files in the folder Do While FileName <> “” ’ Skip the master file if it is in the same folder If FileName <> Doc.Title Then ‘ Open source file hidden in the background Dim Props(0) As New com.sun.star.beans.PropertyValue Props(0).Name = “Hidden” Props(0).Value = True SourceDoc = StarDesktop.loadComponentFromURL(FolderPath & FileName, “_blank”, 0, Props()) Sheet = SourceDoc.Sheets.getByIndex(0) ’ Reads the first sheet SourceRow = 1 ‘ Start reading from row 2 (index 1) to skip headers ’ Loop through rows until an empty cell is found in column A Do While Sheet.getCellByPosition(0, SourceRow).String <> “” ‘ Example: Copying 4 columns (A to D) Dim i As Integer For i = 0 To 3 TargetSheet.getCellByPosition(i, NextRow).String = Sheet.getCellByPosition(i, SourceRow).String Next For SourceRow = SourceRow + 1 NextRow = NextRow + 1 Loop ’ Close the source file safely SourceDoc.close(True) End If ‘ Fetch the next file FileName = Dir() Loop MsgBox “Data import complete!”, 64, “Success” End Sub Function GetLastRow(Sheet As Object) As Long Dim CellCursor As Object CellCursor = Sheet.createCursor() CellCursor.gotoEndOfUsedArea(False) GetLastRow = CellCursor.RangeAddress.EndRow End Function Use code with caution. Customizing and Running the Importer 1. Update the Folder Path
Locate the line FolderPath = “file:///C:/YourSourceFolder/” in the code. Change this to the exact folder path where your source files live. Remember to use forward slashes (/) instead of backslashes (). 2. Adjust Your Columns
The script is currently configured to copy four columns (For i = 0 To 3). If your spreadsheets contain more columns, change the 3 to match your layout (e.g., use 9 for 10 columns, since column A starts at 0). 3. Run the Importer
Go back to your master spreadsheet workspace, navigate to Tools > Macros > Run Macro, select ImportMultipleODSFiles, and click Run. Watch your master sheet populate instantly. Pro-Tips for Seamless Imports
Consistent Formatting: Ensure all source files share the identical column order. If Sheet A has “Date” in column A, but Sheet B has “Date” in column B, the consolidated data will get mixed up.
Keep Data Clean: Check that there are no blank rows in the middle of your source files. The macro is designed to stop reading a file as soon as it hits an empty row in Column A.
Create a Shortcut Button: To make this tool even more user-friendly, go to Tools > Customize > Toolbars and add a clickable button right onto your spreadsheet to trigger the macro instantly.
Investing five minutes into setting up this OpenOffice Calc file importer will save you hours of administrative headaches down the road.
If you want to tailor this macro to your specific workflow, let me know:
Do your source files have blank rows or varying column structures?
Would you prefer to select the folder dynamically using a pop-up window instead of typing the path into the code?
I can help modify the script to fit your exact business needs.
Leave a Reply