Tuesday, April 17, 2007

Convert Excel files to simple Wikimedia and HTML tables

I recently installed a Wiki at work, but our users aren't exactly computer experts, and Wiki experts even less so. So I wanted to make a tool to allow them to upload an Excel file and have it spit out Wiki code for a table. I started in ASP, but just uploading a file and reading other form values at the same time was enough to make me tear my hair out. (Yes, I looked at the ASP upload posts here, but most of it was far too complicated for what I was doing)Since Wikimedia is in PHP anyway, I figured I'd see if someone had created an Excel reader in PHP, and lo & behold, I found the aptly-named PHP-ExcelReader on Sourceforge.net. It works quite well, most of the bugs have been fixed, and it's pretty easy to use.The first page has a simple form and instructions. It allows the user to select their file, the rows that contain a title, header rows, and the first data row. I also added some optional style selections, such as positioning (none/center/float left/float right), font/bg colors, cell padding, cell spacing, and border width. After clicking "Next," the Wikimedia table code is displayed, along with a rendition of the table itself (in HTML, of course). Note: if you decide to modify this to create HTML code and strip out the Wiki part, the positioning/floating is not included (for my purposes, the HTML table is only to allow the user to see roughly what it will look like by itself).So far, it handles vertically or horizontally merged cells; however if a cell is merged over multiple rows and columns, data starts disappearing. That is a problem I couldn't figure out within the time I alotted myself (I have plenty of REAL work to do ). I had some trouble displaying dates correctly, but I'm not sure if the problem was with PHP-ExcelReader, my server, or something in my code (don't think so). Also, if a column is used and later all cells emptied, it seems to think it's still a used cell, despite the lack of any data.It does NOT, however, use any style or formatting from the Excel file: just data. No bold/italics, no font size changes, no charts or images (of course), and it does not know how wide the columns are.So it is very simple and not feature-rich, but I thought others might find it somewhat useful, even if just as an example of how to use PHP-ExcelReader. I'd be interested to know if anyone finds it useful or notices any obvious bugs.The attached ZIP file contains three PHP files: index.php contains my code, while reader.php and oleread.inc are the files from PHP-ExcelReader (unmodified). In index.php there are two fields that may need to be edited for your use. $thisfile can be changed if you don't want your file called indes.php, and $dropdir needs to be writeable by your web server.The file I uploaded disappeared. Here is a link to the file from another post
__________________www.Rhymezilla.com

No comments: