Tuesday, June 30, 2009

Export Vonage Call Log using IronPython and WatiN

Here is another IronPython script that shows how to use the WatiN testing framework, which is great for testing web pages in Internet Explorer, and it is starting to support Google Chrome and Firefox too. We use WatiN at work for testing the full stack on an ASP.Net website, and it works very well even for AJAX sites. This example will login to Vonage and export all of a user's call data to a CSV format.

Enjoy!

Monday, June 8, 2009

IronPython Date Selector: Pick a date... any date...

Another quick IronPython snipet that shows how to use the Windows.Form.MonthCalendar control to create a simple date selector.

image002

Works well for selecting singe dates, and could be modified to support selecting a date range if desired. I prefer having a Start Date and End Date, and selecting each separately. Full code can be downloaded here.

Enjoy!

IronPython Excel COM Automation: Pivot this!

I have been playing around with IronPython recently while creating spreadsheets in Resolver One. So far I have been having a lot of fun, but I haven't really been doing anything that would be useful in a work setting. The main reason for this is because most of the spreadsheet work that I do revolves around pivot tables and Auto Filter, which are immensely helpful for visually analyzing data. I thought I might try and use Excel's COM Automation to add Pivot Charts and Auto Filter to any system with IronPython, and here is the code that I have come up with so far:
UPDATE 7/13/2009: After releasing the initial code, I found that there was a problem with the HideToolbars function causing the Excel toolbars to be disabled permanently. Also, the code would not work if the user's Region was set to something other than "en-US" due to this known bug. I updated the code to disable the HideToolbars function and use Reflection and the InvokeMember method to force the Culture to be "en-US". If you want to view the old "en-US" only code, you can download it here.

The code should be pretty straight forward. The Reload() method is helpful for reloading the whole module when testing from a console. The Run() method shows the steps to load a new spreadsheet. The ExcelManager static class is the core of the logic and provides an entry point for interacting with the spreadsheet.
There is not a lot of debuging code, so if something goes wrong it is just going to throw an exception, but this should be enough to help get things started. I did fix some funky problems with importing DateTime, where they kept getting converted into integers. Should work fine now, but anything other than Datetime, numerical types or strings will probably not get imported correctly.
If anyone else needs to do Excel Interop with IronPython, feel free to use the code, which can be downloaded here.
Enjoy!

Monday, June 1, 2009

Simple-Talk article about SQL FOR XML usage

I read a great article from Simple-Talk today about how to use the FOR XML option in Microsoft SQL server. I usually would passively post these to a shared RSS reader feed or star them for future reference, but I found the article through the Red Gate Newsletter and I don't really want to add the entire feed just to share one article. I do however suggest signing up for the newsletter if you are interested in MSSQL, .NET, or Exchange as they often have a lot of good articles about coding in or managing these systems.

Simple-Talk is a service from Red Gate, which creates tools for Exchange, SQL Server and .NET including the .NET Reflector, which is an invaluable tool for anyone using the .NET framework. I use it all the time to help with testing and debugging or when using .NET libraries that have poor user documentation. It even includes add-ins for changing code in .NET assemblies or adding an embedded IronPython console for playing around with objects and methods. Very handy indeed!

Blog.TheG2.Net - Your guide to life in the Internet age.