kahodges Posted September 4, 2009 Share Posted September 4, 2009 I'm running a php script I found for exporting Excel files, and have it working on one table on MySQL. I've formatted it to work with another table, and all I can get it to produce is gibberish on the screen. Here's the code in the script: <?php include 'includes/config.php'; require_once 'Spreadsheet/Excel/Writer.php'; $query = "SELECT date, 13-52, 13-53, 19-50, 19-54, 19-55, 19-56, 19-57, 19-58, 24-228, 24-237, 24-281 FROM equip_idle_grinders ORDER BY `date` "; $result = mysql_query($query) or die('Error, query failed'); $num_rows = mysql_num_rows($result); if($num_rows > 0){ $row_count = 1; while($row = mysql_fetch_array($result)){ if($row_count == 1){ // Creating a workbook $workbook = new Spreadsheet_Excel_Writer(); $format_bold =& $workbook->addFormat(); $format_bold->setBold(); // sending HTTP headers $workbook_name = $row['equip_idle_grinders'] . 'grinders_idle_list.xls'; $workbook->send($workbook_name); // Creating a worksheet $worksheet =& $workbook->addWorksheet('equip_idle_grinders'); // The actual data $worksheet->setColumn(0,0,12); $worksheet->setColumn(1,1,10); $worksheet->setColumn(2,2,10); $worksheet->setColumn(3,3,10); $worksheet->setColumn(4,4,10); $worksheet->setColumn(5,5,10); $worksheet->setColumn(6,6,10); $worksheet->setColumn(7,7,10); $worksheet->setColumn(8,8,10); $worksheet->setColumn(9,9,10); $worksheet->setColumn(10,10,10); $worksheet->setColumn(11,11,10); $worksheet->write(0, 0, 'date', $format_bold); $worksheet->write(0, 1, '13-52', $format_bold); $worksheet->write(0, 2, '13-53', $format_bold); $worksheet->write(0, 3, '19-50', $format_bold); $worksheet->write(0, 4, '19-54', $format_bold); $worksheet->write(0, 5, '19-55', $format_bold); $worksheet->write(0, 6, '19-56', $format_bold); $worksheet->write(0, 7, '19-57', $format_bold); $worksheet->write(0, 8, '19-58', $format_bold); $worksheet->write(0, 9, '24-228', $format_bold); $worksheet->write(0, 10, '24-237', $format_bold); $worksheet->write(0, 11, '24-281', $format_bold); } $worksheet->write($row_count, 0, $row['date']); $worksheet->write($row_count, 1, $row['13-52']); $worksheet->write($row_count, 2, $row['13-53']); $worksheet->write($row_count, 3, $row['19-50']); $worksheet->write($row_count, 4, $row['19-54']); $worksheet->write($row_count, 5, $row['19-55']); $worksheet->write($row_count, 6, $row['19-56']); $worksheet->write($row_count, 7, $row['19-57']); $worksheet->write($row_count, 8, $row['19-58']); $worksheet->write($row_count, 9, $row['24-228']); $worksheet->write($row_count, 10, $row['24-237']); $worksheet->write($row_count, 11, $row['24-281']); $row_count++; } } // Let's send the file $workbook->close(); // ?> Here's a MySQL dump of the table: CREATE TABLE IF NOT EXISTS `equip_idle_excavator` ( `date` varchar(11) COLLATE utf8_unicode_ci DEFAULT NULL, `22-176` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-252` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-260` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-262` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-270` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-271` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-273` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-277` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-279` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, `22-282` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, KEY `date` (`date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; Help would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/173160-exporting-xls/ Share on other sites More sharing options...
bundyxc Posted September 4, 2009 Share Posted September 4, 2009 Please post said-gibberish. Link to comment https://forums.phpfreaks.com/topic/173160-exporting-xls/#findComment-912702 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.