brent123456 Posted November 14, 2008 Share Posted November 14, 2008 Hi, I am trying to parse this excel document it is opening the document and printing it fine. What I can't figure out is how to make sure that if there are less then 15 cells (like 10 fill cells then 3 empty cells then 2 full cells) in the row to stop it from adding them in the wrong column. Basically if there are only 12 rows it will insert them under the wrong table heading and just insert "null" and "null" and "null" in the last three columns of the table. I am trying to get it to skip over the columns with no value and just print "null" in them. Thanks $data = array(); function add_computer( $location, $tagnumber, $manufactur, $model_num, $serial_num, $description, $short_def, $oid_1, $product, $serialnum, $processor, $ghz, $memory, $size, $purchase_year ) { global $data; $data []= array( 'location' => $location, 'tagnumber' => $tagnumber, 'manufactur' => $manufactur, 'model_num' => $model_num, 'serial_num' => $serial_num, 'description' => $description, 'short_def' => $short_def, 'oid_1' => $oid_1, 'product' => $product, 'serialnum' => $serialnum, 'processor' => $processor, 'ghz' => $ghz, 'memory' => $memory, 'size' => $size, 'purchase_year' => $purchase_year ); } if ( $_FILES['file']['tmp_name'] ) { $dom = DOMDocument::load($_FILES['file']['tmp_name']); $rows = $dom->getElementsByTagName( 'Row' ); $first_row = true; foreach ($rows as $row) { if ( !$first_row ) { $location = ""; $tagnumber = ""; $manufactur = ""; $model_num = ""; $serial_num = ""; $description = ""; $short_def = ""; $oid_1 = ""; $product = ""; $serialnum = ""; $processor = ""; $ghz = ""; $memory = ""; $size = ""; $purchase_year = ""; $index = 1; $cells = $row->getElementsByTagName( 'Cell' ); foreach( $cells as $cell ) { $ind = $cell->getAttribute( 'Index' ); if ( $ind != null ) $index = $ind; if ( $index == 1 ) $location = $cell->nodeValue; if ( $index == 2 ) $tagnumber = $cell->nodeValue; if ( $index == 3 ) $manufactur = $cell->nodeValue; if ( $index == 4 ) $model_num = $cell->nodeValue; if ( $index == 5 ) $serial_num = $cell->nodeValue; if ( $index == 6 ) $description = $cell->nodeValue; if ( $index == 7 ) $short_def = $cell->nodeValue; if ( $index == 8 ) $oid_1 = $cell->nodeValue; if ( $index == 9 ) $product = $cell->nodeValue; if ( $index == 10 ) $serialnum = $cell->nodeValue; if ( $index == 11 ) $processor = $cell->nodeValue; if ( $index == 12 ) $ghz = $cell->nodeValue; if ( $index == 13 ) $memory = $cell->nodeValue; if ( $index == 14 ) $size = $cell->nodeValue; if ( $index == 15 ) $purchase_year = $cell->nodeValue; $index += 1; } add_computer( $location, $tagnumber, $manufactur, $model_num, $serial_num, $description, $short_def, $oid_1, $product, $serialnum, $processor, $ghz, $memory, $size, $purchase_year ); } $first_row = false; } } ?> Quote Link to comment Share on other sites More sharing options...
flyhoney Posted November 14, 2008 Share Posted November 14, 2008 I would use phpExcelReader. download is here: http://sourceforge.net/project/showfiles.php?group_id=99160 And more info here: http://forums.codewalkers.com/pear-packages-47/spreadsheet-excel-reader-852965.html Quote Link to comment Share on other sites More sharing options...
brent123456 Posted November 16, 2008 Author Share Posted November 16, 2008 It seems to be working ok as far as reading the sheet I think it is just something broken in my loop. Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted November 16, 2008 Share Posted November 16, 2008 I'd use PHPExcel Quote Link to comment Share on other sites More sharing options...
brent123456 Posted November 17, 2008 Author Share Posted November 17, 2008 I have checked this out. Does anyone know any good tutorials on using these classes. Didn't find much on the website itself. Would be every helpful. Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted November 17, 2008 Share Posted November 17, 2008 If you download PHPExcel, you'll find a number of examples in the /Tests subdirectory demonstrating how to read and write workbooks. You're only interested in reading, but there's still a few examples there. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.