Looking into it further, it seems that neither the Perl nor Python modules are capable of writing to an existing worksheet.
There is a Ruby module that purportedly can accomplish this. I'm not familiar with it, but has anyone used this? I'm having trouble finding documentation on it.
[EDIT]
I got it. The Ruby module is the only thing I could find that allows you to both read a .xls file and make changes to it. Other modules allowed you to do both separately, but the objects for each did not seem to be compatible (the Python module could with an additional utilities package which I couldn't find in the repos).
What it doesn't do is allow you to write back to the original file. So, I had to perform a little trickery, renaming the original file then writing a new file with the original name before deleting the original.
If anyone's interested, here's what I came up with:
Code:
#!/usr/bin/env ruby
require 'spreadsheet'
row, col, val, file = ARGV
temp = file.split('.')
temp[temp.length-2] = temp[temp.length-2]+'_(' +(0...8).map{65.+(rand(25)).chr}.join + ')'
until !(File::exists?(temp.join('.')))
temp[temp.length-2] = temp[temp.length-2].slice[0,temp[temp.length-2].length-10]
temp[temp.length-2] = temp[temp.length-2]+'_(' +(0...8).map{65.+(rand(25)).chr}.join + ')'
end
File.rename(file, temp.join('.'))
book = Spreadsheet.open temp.join('.')
sheet = book.worksheet 0
sheet[Integer(row)-1,Integer(col)-1] = Integer(val)
book.write file
File.delete(temp.join('.'))
It requires libspreadhseet-ruby1.9.1 (there's also a 1.8 in the repos, but I didn't test it with that). It can only handle integer values at the moment (sufficient for my immediate purpose).
Also, this is only suitable for updating a single cell, or perhaps a small number. It takes a while to run due to the file I/O, and only performs one change, so trying to use this in a larger loop will take a long time.
Bookmarks