Wednesday 23 February 2011

Lorem No More?

I'm quite fond of using the Lorem Ipsum website to generate Greeking when I'm doing a website or application, but have recently discovered Fillerati.

Basically, instead of filling in (dead) Latin text, it gives me random text from random classic books to use instead!


As the Monkey King finished his story Dorothy looked down and saw the green, shining walls of the Emerald City before them. She wondered at the rapid flight of the Monkeys, but was glad the journey was over. The strange creatures set the travelers down carefully before the gate of the City, the King bowed low to Dorothy, and then flew swiftly away, followed by all his band.

"That was a good ride," said the little girl.

"Yes, and a quick way out of our troubles," replied the Lion. "How lucky it was you brought away that wonderful Cap!"

The four travelers walked up to the great gate of Emerald City and rang the bell. After ringing several times, it was opened by the same Guardian of the Gates they had met before.

"What! are you back again?" he asked, in surprise.

"Do you not see us?" answered the Scarecrow.

"But I thought you had gone to visit the Wicked Witch of the West."

"We did visit her," said the Scarecrow.

"And she let you go again?" asked the man, in wonder.

"She could not help it, for she is melted," explained the Scarecrow.

..

See? Made this look like a long post!

Profanity in commit messages

I loved this post about people swearing in the comments as they check-in their code.

Word Automation: Table Autofit

After struggling with trying to get a table in Open XML auto-fit itself to its contents, I gave up. I believe that the auto-fit properties are busted, and that it's the clients that are doing the auto-fit based on having rendered the contents of the columns & rows, rather than it being a property of the document itself.

Since my application requires the document to be opened in Word (in order to save it as an XPS document), I decided to go with auto-fitting the contents during the Word automation.


var wordApp = new Microsoft.Office.Interop.Word.Application();
var docPath = @"C:\temp\MyDocument.docx";
var doc = wordApp.Documents.Add(docPath);
AutoFitTables(doc);

private void AutoFitTables(_Document wordDoc)
{
foreach (Microsoft.Office.Interop.Word.Table table in wordDoc.Tables)
{
table.AutoFitBehavior(WdAutoFitBehavior.wdAutoFitContent);
table.Columns.AutoFit();
AutoFitTables(table);
}
}

private void AutoFitTables(Microsoft.Office.Interop.Word.Table table)
{
foreach (Microsoft.Office.Interop.Word.Table subTable in table.Tables)
{
subTable.AutoFitBehavior(WdAutoFitBehavior.wdAutoFitContent);
subTable.Columns.AutoFit();
AutoFitTables(subTable);
}
}

This auto-fits every table in my document, which is probably not what you want, but it's what I wanted. Well, not every table - it didn't auto-fit the table in my header, which again, is exactly what I wanted.