Archive for the ‘OpenOffice.org’ Category

Finding the width of a column in a table in OpenOffice.org writer is a bit of a black art, because the widths aren't stored anywhere, just the relative widths in arbitrary units. And if cells have been combined, then the object model has no concept of "columns" and there is no way to find the widths of cells. But, based on the table tutorial, I've written this function:

function colwidth (table, index) ' index is 0-based
	' need the table to be oriented (http://api.openoffice.org/servlets/ReadMsg?list=dev&msgNo=12552) 
	table.horiOrient = com.sun.star.text.HoriOrientation.LEFT_AND_WIDTH
	' tricks from http://wiki.services.openoffice.org/wiki/API/Samples/Java/Writer/TextTable
	dim n
	n = table.columns.count
	if index >= n then
		colwidth = 0
	elseif n = 1 then ' single column table
		colwidth = table.width
	else
		dim ratio as double
		ratio = table.width / table.tableColumnRelativeSum
		dim pos
		pos = table.tableColumnSeparators
		if index = 0 then
			colwidth = pos(0).position * ratio
		elseif index = n-1 then ' last column
			colwidth = (table.tableColumnRelativeSum - pos (ubound(pos)).position) * ratio
		else
			colwidth = (pos(index).position - pos(index-1).position) * ratio
		end if
	end if
end function

OOo controls have a Struct FontDescriptor that contains all the information about the text (font name, point size, etc.) so one would hope that to make an editbox have the same font as the containing text range, all you would have to do is

textField.fontDescriptor = textRange.fontDescriptor

but no such luck. FontDescriptors apply to everything but actual text; text has all those properties as part of the CharacterProperties service, so each property has to be accessed separately:

fontDescriptor = textField.fontDescriptor
fontDescriptor.name = textRange.CharFontName
fontDescriptor.height = textRange.CharHeight
' etc.
textField.fontDescriptor = fontDescriptor

Note that you can't do textField.fontDescriptor.name = textRange.CharFontName, because Structs are always copied. Even if it makes no sense.textField.fontDescriptor.name creates a temporary copy of textField.fontDescriptor and modifies its name, leaving the original textField.fontDescriptor untouched

There's a great tutorial on exporting from OpenOffice.org Writer to PDF, but as far as I can tell it's orphaned on the openoffice.org website; there's no link from the tutorials page. It documents all the properties of the export filter and goes through the process in great detail. Hopefully the link from this blog will help keep it from staying orphaned.

Some of the first things I needed to get straight to move from Microsoft Office scripting to Open Office scripting:

  • The BASIC isn't quite compatible: I know the object model is completely different, but even the underlying language isn't quite the same. I wanted to use the InStrRev function, but it wasn't there! Then I found option VBASupport 1 which puts it in. It's (as far as I can tell) undocumented but mentioned all over on the web. I'm not sure what else it changes (again, in the language, not the object model).
  • The name of the program is OpenOffice.org; evidently Open Office is trademarked by someone else. I'll do my best to comply.
  • Sizes are in hundredths of a millimeter (dekamicrons? abbreviated as daµ; I can't find anyone using a better abbreviation), so my code has a lot of x = y * 2540/72: 2540 mm per inch, 72 points per inch.
  • Inserting control elements is more complicated than I would have thought; the object model divides them into "model" and "view" and figuring out which properties belong to which takes some searching and experimenting:
    	Dim rng as com.sun.star.text.TextRange, checkModel, checkbox
    	checkModel = doc.createInstance("com.sun.star.form.component.CheckBox")
    	checkView = doc.createInstance("com.sun.star.drawing.ControlShape")
    	checkView.control = checkModel
    	rng.Text.insertTextContent(rng, checkView, True)
    

My hospital isn't fully electronic yet; they use a hybrid system where doctors notes and orders are written on paper, to be scanned into the electronic chart at the end of the patient's stay. Everything else (nurse's notes, labs, radiology results) are electronic. It actually works pretty well, with most of the advantages of an EMR (Electronic Medical Record) without forcing the older doctors to use the computer. That's coming, of course, but it won't be pretty.

But those of us for whom the computer is mother's milk, and whose handwriting is somewhere between chicken scratch and Linear A, we'd rather do it all online. I've been writing my admission notes for a few years with a Microsoft Word template, printing them out and putting them in the chart, with nary a problem. And the medical records department clearly used PDF's for the pages, both the blank order sheets and the preprinted, fill-in-the-blanks "standard orders" since they were available on the hospital intranet. So let's create PDF's with actual editable text boxes and check boxes (these are mockups, but they look right):

physician order sheetgastroenteritis order sheet

Continue reading ‘Diving into OpenOffice.org’ »