Page 1 of 1

Load excel spreadsheet as xml format

Posted: Thu Feb 19, 2009 10:27 am
by clarance
Hello,

I'm trying to load an xml spreadsheet 2003 file into php and then be able to work with it and eventually store it in my MySQL database.

But first things first I get an error:

Fatal error: Call to undefined function: load() in /home/diabilal/public_html/stats/stats.php on line 36

and not exactly sure why... as you can see i am trying to display the info from each cell in the spreadsheet.

here is the php code


1 <?php
2 $data = array();
3
4 function add_person( $games, $min, $_2pm, $_2pa, $_2pp, $_3pm, $_3pa, $_3PP, $ftm, $fta, $ftp, $or, $dr, $tr, $ass, $to, $ass_to, $pf, $st, $bs, $pts, $eff)
5 {
6 global $data;
7
8 $data []= array(
9 'games' => $first,
10 'min' => $min,
11 '_2pm' => $_2pm,
12 '_2pa' => $_2pa,
13 '_2pp' => $_2pp,
14 '_3pm' => $_3pm,
15 '_3pa' => $_3pa,
16 '_3pp' => $_3pp,
17 'ftm' => $ftm,
18 'fta' => $fta,
19 'ftp' => $ftp,
20 'or' => $or,
21 'dr' => $dr,
22 'tr' => $tr,
23 'ass' => $ass,
24 'to' => $to,
25 'ass_to' => $ass_to,
26 'pf' => $pf,
27 'st' => $st,
28 'bs' => $bs,
29 'pts' => $pts,
30 'eff' => $eff
31 );
32 }
33
34 if ( $_FILES['file']['tmp_name'] )
35 {
36 $dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
37 $rows = $dom->getElementsByTagName( 'Row' );
38 $first_row = true;
39 foreach ($rows as $row)
40 {
41 if ( !$first_row )
42 {
43 $games = "";
44 $min = "";
45 $_2pm = "";
46 $_2pa = "";
47 $_2pp = "";
48 $_3pm = "";
49 $_3pa = "";
50 $_3PP = "";
51 $ftm = "";
52 $fta = "";
53 $ftp = "";
54 $or = "";
55 $dr = "";
56 $tr = "";
57 $ass = "";
58 $to = "";
59 $ass_to = "";
60 $pf = "";
61 $st = "";
62 $bs = "";
63 $pts = "";
64 $eff = "";
65
66 $index = 1;
67 $cells = $row->getElementsByTagName( 'Cell' );
68 foreach( $cells as $cell )
69 {
70 $ind = $cell->getAttribute( 'Index' );
71 if ( $ind != null ) $index = $ind;
72
73 if ( $index == 1 ) $games = $cell->nodeValue;
74 if ( $index == 2 ) $min = $cell->nodeValue;
75 if ( $index == 3 ) $_2pm = $cell->nodeValue;
76 if ( $index == 4 ) $_2pa = $cell->nodeValue;
77 if ( $index == 5 ) $_2pp = $cell->nodeValue;
78 if ( $index == 6 ) $_3pm = $cell->nodeValue;
79 if ( $index == 7 ) $_3pa = $cell->nodeValue;
80 if ( $index == 8 ) $_3pp = $cell->nodeValue;
81 if ( $index == 9 ) $ftm = $cell->nodeValue;
82 if ( $index == 10 ) $fta = $cell->nodeValue;
83 if ( $index == 11 ) $ftp = $cell->nodeValue;
84 if ( $index == 12 ) $or = $cell->nodeValue;
85 if ( $index == 13 ) $dr = $cell->nodeValue;
86 if ( $index == 14 ) $tr = $cell->nodeValue;
87 if ( $index == 15 ) $ass = $cell->nodeValue;
88 if ( $index == 16 ) $to = $cell->nodeValue;
89 if ( $index == 17 ) $ass_to = $cell->nodeValue;
90 if ( $index == 18 ) $pf = $cell->nodeValue;
91 if ( $index == 19 ) $st = $cell->nodeValue;
92 if ( $index == 20 ) $bs = $cell->nodeValue;
93 if ( $index == 21 ) $pts = $cell->nodeValue;
94 if ( $index == 22 ) $eff = $cell->nodeValue;
95
96 }
97 $index += 1;
98 add_person( $games, $min, $_2pm, $_2pa, $_2pp, $_3pm, $_3pa, $_3PP, $ftm, $fta, $ftp, $or, $dr, $tr, $ass, $to, $ass_to, $pf, $st, $bs, $pts, $eff );
99 }
100 $first_row = false;
101 }
102 }
103 ?>
<html>
<body>
<table>
<tr>
<th>First</th>
<th>Middle</th>
<th>Last</th>
<th>Email</th>
</tr>
<?php foreach( $data as $row ) { ?>
<tr>
<td><?php echo( $row['games'] ); ?></td>
<td><?php echo( $row['min'] ); ?></td>
<td><?php echo( $row['_2pm'] ); ?></td>
<td><?php echo( $row['_2pa'] ); ?></td>
<td><?php echo( $row['_2pp'] ); ?></td>
<td><?php echo( $row['_3pm'] ); ?></td>
<td><?php echo( $row['_3pa'] ); ?></td>
<td><?php echo( $row['_3pp'] ); ?></td>
<td><?php echo( $row['ftm'] ); ?></td>
<td><?php echo( $row['fta'] ); ?></td>
<td><?php echo( $row['ftp'] ); ?></td>
<td><?php echo( $row['or'] ); ?></td>
<td><?php echo( $row['df'] ); ?></td>
<td><?php echo( $row['tr'] ); ?></td>
<td><?php echo( $row['ass'] ); ?></td>
<td><?php echo( $row['to'] ); ?></td>
<td><?php echo( $row['ass_to'] ); ?></td>
<td><?php echo( $row['pf'] ); ?></td>
<td><?php echo( $row['st'] ); ?></td>
<td><?php echo( $row['bs'] ); ?></td>
<td><?php echo( $row['pts'] ); ?></td>
<td><?php echo( $row['eff'] ); ?></td>
</tr>
<?php } ?>
</table>
</body>
</html>



Here is my script for the uplaod page:

<html>
<body>
<form enctype="multipart/form-data"
action="stats.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
<table width="600">
<tr>
<td>Names file:</td>
<td><input type="file" name="file" /></td>
<td><input type="submit" value="Upload" /></td>
</tr>
</table>
</form>
</body>
</html>



Please if you have any idea can you help me out please?