Nook Schreier
10-10-2006, 02:51 PM
I submitted this into PHP Tips & Code Snippets, but I guess they didn't want to approve it for some reason. Anyway, I implemented a Wikimedia site at work, but our users aren't very computer-savvy, especially when they have to use markup of any kind. One of the biggest troubles seemed to be with making tables, so I started writing an Excel-to-Wiki converter in ASP. That is, until I tried to get file uploading to work. Before I started tearing my hair out because of Microsoft's incompetence, I decided to try PHP, since uploading a file takes just 3-4 lines of HTML/PHP. Then I found a piece of LGPL'ed code on SourceForge.net called (aptly) PHP-ExcelReader. It's not very advanced, in that it won't show bold/italics/color/etc, although it does handle merged cells, which is very handy.
So anyway, starting with that, I made the Wiki table maker. Of course, people wanted to be able to see their table before copying & pasting the code into WikiMedia, so I also incorporated HTML table creation, which displays just above the Wiki code after submitting.
It's pretty simple, but I think it could be useful for others. On the first page it simply has a browse button to upload the file, and some input boxes:
Worksheet: in case the desired spreadsheet is not in the first worksheet of the file
Title Row: Wiki's "caption"; it searches this row# for the first text & makes it the title
Column Headers Row: Table column headers (TH cells)
First Data Row: some people like to insert blank rows. This way they will be ignored
And then the optional ones, like background color, text color, padding, spacing, and border size.
I also included a drop-down box to let them select centered, float left/right, or no explicit positioning.
There are a couple of shortcomings, mostly in style. Also, it handles horizontally merged cells and vertically merged cells, but if a cell is merged over multiple rows AND columns, some cells on the right disappear (they get buried under a colspan somehow).
Anyway, take a look. If you see any bugs or improvements, let me know, I'd like to make this as useful as possible. Since PHP-ExcelReader is LGPL, I suppose I should do the same to my code, so basically do what you want with it.
PHP-ExcelReader is reader.php & oleread.inc and are unmodified from their original form, index.php is my own file.
So anyway, starting with that, I made the Wiki table maker. Of course, people wanted to be able to see their table before copying & pasting the code into WikiMedia, so I also incorporated HTML table creation, which displays just above the Wiki code after submitting.
It's pretty simple, but I think it could be useful for others. On the first page it simply has a browse button to upload the file, and some input boxes:
Worksheet: in case the desired spreadsheet is not in the first worksheet of the file
Title Row: Wiki's "caption"; it searches this row# for the first text & makes it the title
Column Headers Row: Table column headers (TH cells)
First Data Row: some people like to insert blank rows. This way they will be ignored
And then the optional ones, like background color, text color, padding, spacing, and border size.
I also included a drop-down box to let them select centered, float left/right, or no explicit positioning.
There are a couple of shortcomings, mostly in style. Also, it handles horizontally merged cells and vertically merged cells, but if a cell is merged over multiple rows AND columns, some cells on the right disappear (they get buried under a colspan somehow).
Anyway, take a look. If you see any bugs or improvements, let me know, I'd like to make this as useful as possible. Since PHP-ExcelReader is LGPL, I suppose I should do the same to my code, so basically do what you want with it.
PHP-ExcelReader is reader.php & oleread.inc and are unmodified from their original form, index.php is my own file.