Monday, November 01, 2010For some time now I have been wanting to evaluate how FlexCel .NET behaves in other platforms. Not just plain Mono running in a Linux server (that's boring, we have always supported that), but some more fun possibilities.
That's why I decided to try two different technologies this weekend: MonoTouch and CrossTalk. (I will speak about Cross Talk in a separate post).
As you might know, we have been really busy here at FlexCel development, both in VCL (porting all features from FlexCel .NET back to FlexCel VCL) and in .NET (adding the missing xlsx support bits). So I had not too much time to play before going back to "real" coding. I allocated 5 hours in the weekend to test each one; if I couldn't have something working when time was due, I would give up.
And if I have to be sincere I was completely expecting to give up. Even when most of FlexCel code is non visual, it is over 100,000 lines of complex non visual code, and I didn't imagine I was going to have something compiling, let's not say working, in 5 hours. You are a smart reader, and you know I actually got something to show or I wouldn't be writing this post, but I didn't know that while I was waiting for MonoTouch to download. That's why I want to emphasize how impressed I was.
So I installed MonoTouch, launched MonoDevelop, and added all the files from the "Core" FlexCel namespace to a new project. I pressed the little "compile all" button; the project compiled and reported "0 errors". What? 0 Errors?? Something had to be wrong, and indeed it was. No file had been generated. Tried to compile a couple of times, and always the same result. Finally when trying to change some options to make it compile, MonoDevelop crashed and dissapeared.
Not what I would call a good start, and it set my expectations even lower. I wasn't going to be able to do anything nice in my 4.5 hours left. But well, I still had time, so I tried it again from zero; created a new project, added just one file and compiled it. And finally I got some errors! Encouraged by that small victory, I tried again to put the full "Core" namespace in the project, and this time it compiled and gave a gazillon of errors. Looking at them, most were about some missing classes, repeated once and again. No "System.Drawing.Font". No "System.Drawing.Image" And again. And again. But I did find some similar classes "MonoTouch.UIKit.UIFont" and "MonoTouch.UIKit.UIImage", that looked like good replacements.
Next step was then to start writing at the beginning of each file:
(Semi-Related-Note: You can't image how I miss the Delphi type aliases in C#... in Delphi this would have been a single
#if(MONOTOUCH) using Font = MonoTouch.UIKit.Font; using Image = MonoTouch.UIKit.Image; #endif
in a single file, not in every file)
type Font = MonoTouch.UIKit.Font;
Bit well, after that things started to look good. Now my issue was with different methods, for example "System.Drawing.Font" has a "FromArgb(a,r,g,b)" method, while "MonoTouch.UIKit.Font" has a "FromRGBA(r,g,b,a)". To fix that I created some extension methods that extended the MonoTouch classes to have similar interface to what FlexCel expected. I had no such luck with properties, since C# doesn't allow extension properties. So I had to change things like Color.R to Color.R() in code, and create an extension method "R()" that will return the property "R" in normal framework and the equivalent in MonoTouch.
Finally after one hour, the "Core" namespace was compiling. At this time I had forgotten about my first bad impression, and was very excited to see everything compiling. I didn't really believe it would actually work, but just seeing it compiling was great. After that it took me other 30 minutes to compile "XlsAdapter" namespace (the actual xls engine). I had to remove xlsx support because some missing classes in the framework, and I didn't even try to compile the rendering engine (as it has more visual stuff, and I expect it to be a little harder)
Now two hours had gone, and I already had something that compiled and looked like I could actually use. So now I went to make a small test application. I have zero experience in mac development, but I could get a form with some labels and buttons relatively fast. And now comes what really impressed me. Everything worked! At first try! I had a working calculator in 3 hours.
I was so happy that I created a little screencast to show how it to some friends. My idea was to create a more "professional" one for this post, (where I would even try to correctly pronounce "button"), but I feel the original one is more authentic and probably funnier to watch. Of course the screencast has no script, I just pressed "record" and started babbling things in an impossible to understand pseudo English. Not that I am any better doing a speech in Spanish, but that's off topic.
You can get the screencast here:
After I recorded that I tested some other things, and everything went incredible smooth. For example creating a 60,000 rows x 20 cols (8.5mb) spreadsheet from the iPhone simulator just took seconds, in fact Excel was slower opening the file than the iPhone simulator creating it. Wow. Mono has always been outstanding technology, but what they did with MonoTouch is just incredible.
So there you have it. From void to a fully working app in 3 hours. Just so we can compare, I am still trying to port FlexCel to Windows phone 7. So much stuff missing and changed in wp7 that I would need many other blog posts to enumerate them all. And in the meantime, MonoTouch just worked, in a platform that is designed around compiled obj-c, not .NET, not even a JITter allowed. Some serious magic is going on here.
Now, I am not really sure on what we are going to do with this. Is it really interesting to have support for reading and writing Excel files from a phone? Would you use it? Do we leave this as a "cool experiment" or do we keep working on it? Please let us know in the comments, or email me directly at firstname.lastname@example.org
This blog post has received 5 comments.
Previous | Next | Index