Using OpenOffice to edit DB entries (via TSV export)
OpenOffice is a great open source (i.e. free) office software suite. It includes a text editor, a drawing software that's useful for creating diagrams, a presentation software and, most importantly for modding, a spreadsheet editor. Today, I want to show you how you can edit TSV (tab-separated value) files exported from PFM in OpenOffice, which is how I imagined they would be used when writing the export mechanism.
A TSV file is a text table representing a database table. In this, the different columns of the table are separated by tabs and the rows correspond to the lines. In principle, you can use a text editor to edit TSV files but they quickly become unwieldy if the column width differs between rows, such as when editing text. Therefore, editing them in a spreadsheet program is much to be preferred.
Requirements and Preparation
I will assume that you know how to use PFM to open and edit pack files, and that you know how to set up a mod with a modding pack that you can use for examples.
If you don't have it yet, download and install OpenOffice. To do this, go to this site and follow the green arrow. It will take a bit of setting up like entering your details, etc.
Now, create a mod pack with an example mod file you want to edit - the best choice for this tutorial is a file you know well. OpenOffice is most useful for files that are very large (for example localisation.loc), where you need to do a lot of copy&paste (for example unit_stats when creating new units), or where you want to use formulas to calculate something.
1. Exporting from PFM
First, open your mod pack file in PFM and navigate to the DB file you want to edit. I'll use the units table. Then, click on the Export TSV button highlighted below. This will open a dialog asking you where to save the file. Save it somewhere with the default name (units.tsv in my case) and remember the location (the data directory for example).
2. Opening a TSV file
Fire up OO Calc via the start menu and you should arrive at a screen that looks like this:
To open your TSV file, open an explorer window, navigate to your working directory, then drag&drop the file into your OpenOffice Calc window. Using the File->Open dialog is possible but in this case you have to rename your file from units.tsv to units.txt so I typically prefer the drag&drop. When you open a TSV file, OO will ask you how it should handle the file format:
You have to make two adjustments in this dialog. Firstly, you have to select UTF-8 as encoding in the Character Set dropbox. The easiest way to do this is to hit the "u" key on your keyboard three times after the dialog opens. The second change is to remove the Text Delimiter (usually a quotation mark). Afterwards, the dialog should look like this:
Click OK to continue and OpenOffice will open your file.
3. Editing, saving and re-importing
Don't edit the first two lines which are internal settings for PFM. Editing the third line with the column descriptions is fine but the changes won't show up in PFM. Do any changes you'd like to make, then hit save (ctrl+s). OpenOffice will by default ask you if you want to save in the current format or in ODS format (the native OpenOffice format). Click on "Keep Current Format"; if you like you can uncheck the checkbox so OO won't ask you about this again.
Now, unfortunately, due to OpenOffice including a file locking mechanism, you have to close the OO table to re-import the file into PFM. So close it, switch to your open PFM window, select the file you're editing again if it's not selected anymore, and hit "Import TSV". Check your changes worked and you're done.
Thank you for your attention.
How to create a mod by Erasmus