Tag: PHP的

使用PHPExcel和Codeigniter读取excel文件并写入数据库

我想在excel文件中写入一些信息到我的数据库。 excel文件看起来像这样。 ID123 | subj1 | 50 ID456 | subj2 | 60 ID786 | subj3 | 70 这是触发控制器中的function的function。 <a href="http://localhost/SEP/index.php/con_test/readExcel"> Click me </a> 这是控制器中的代码。 public function readExcel(){ $inputFileName = 'C:\wamp\www\SEP\uploads\Format.xlsx'; // Read your Excel workbook try { $inputFileType = PHPExcel_IOFactory::identify($inputFileName); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($inputFileName); } catch(Exception $e) { die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage()); […]

无法导出为.xlsx格式

我试图将我的表格导出为.xlsx格式。 但是没有做到这一点。 到目前为止我做了这个: header('Content-type: application/octet-stream'); header('Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); //should be a correct mimetype header('Content-Disposition:attachment; filename="contoh-1.xlsx"'); 下面是错误: 这是我如何生成数据。 控制器: public function kategori_excel(){ $paramKategori = $this->input->get('CategoryCode'); $get_url_kategori = $this->ws_url->GetUrl('CategoryRetrieve?CategoryCode='.$paramKategori); $get_json_kategori = json_decode(file_get_contents($get_url_kategori), true); $data['itemKategoriToExcel'] = $get_json_kategori['Kategoris']; $this->load->view('kategori_excel', $data); } 这里是观点: <table border='1' width="100%"> <tr> <th>Kode</th> <th>Nama</th> <th>Definisi</th> <th>Unsur Abstrak</th> <th>Alias</th> <th>Sumber Definisi</th> <th>Tanggal</th> <th>Tipe Tanggal</th> <th>Edisi</th> <th>Role</th> <th>Other Citation […]

将MySQLi查询导出到XLS

我创build了这个小脚本,用于在一些教程的帮助下将MySQLi查询导出到.xls。 本教程使用MySQL,但我使用MySQLi。 该文件成功导出并可读,但将数据放在第二行。 这是我的代码: <?php include 'connectToDB.php'; $table = "users"; $filename = "users_export"; $sql = "Select * from $table"; $result = mysqli_query($conn,$sql) or die("Couldn't execute query:<br>" . mysqli_error(). "<br>" . mysqli_errno()); $file_ending = "xls"; header("Content-Type: application/xls"); header("Content-Disposition: attachment; filename=$filename.xls"); header("Pragma: no-cache"); header("Expires: 0"); $sep = "\t"; $names = mysqli_fetch_fields($result) ; foreach($names as $name){ print ($name->name […]

电子表格ExcelReader在parsing时不显示秒数

我有一个Excel文件,显示date格式dd/mm/yyyy hh:mm:ss 。 当我parsing该表并在网页上打印结果时,Spreadsheet excelReader以这种格式显示一个date: yyyy-mm-dd hh:mm 。 在99%的时间里,这不是一个问题,但在这种情况下,我还需要显示秒。 我试图修改configuration文件,但没有改变。 以下是关于该文件的一些信息: * A class for reading Microsoft Excel Spreadsheets. * * Originally developed by Vadim Tkachenko under the name PHPExcelReader. * (http://sourceforge.net/projects/phpexcelreader) * Based on the Java version by Andy Khan (http://www.andykhan.com). Now * maintained by David Sanders. Reads only Biff 7 and Biff 8 […]

PHP的Excel读取器读取数字不正确

我正在尝试读取和xlsx文件批量导入到MySQL数据库。 我可以成功地读取文本字段,但是当涉及到大数字时,会给出错误的结果。 我从github使用nuovo / spreadsheetreader SpreadsheetReader.php SpreadsheetReader_XLSX.php 的index.php $Reader = new SpreadsheetReader($orgFilename); $count = count($Reader); foreach ($Reader as $Row) { echo $Row[0] . '<br>'; } 这是我的Excel数据 690835388.737296 -553772409.572704 16983999.9999999 16983999.9999999 -904762663.342704 0.439514518724299 89055169.9716966 171930071.634401 35291999.9999995 1151681063.10099 输出是 690835388.7373 -553772409.5727 16984000 16984000 -904762663.3427 0.4395145187243 89055169.971697 171930071.6344 35291999.999999 1151681063.101 有谁知道这是为什么发生?

从.ods格式文件读取数据,代码不工作

我已经写了这个代码,但没有得到任何输出: require_once 'SpreadsheetReaderFactory.php'; $spreadsheetsFilePath = 'data.ods'; $reader = SpreadsheetReaderFactory::reader($spreadsheetsFilePath); $sheets = $reader->read($spreadsheetsFilePath); print_r($sheets);

格式excel使用php

在这里,我试图使用PHP-Spreadsheet / Excel / Writer.php来格式化Excel,一旦它被下载,我看到在Excel中坠毁的数据。下面是图像的屏幕截图。我已经search并尝试了几个解决scheme。 任何人都可以帮助我找出解决scheme <?PHP session_start(); include_once('database/Insert.php'); include_once('database/Select.php'); header("Content-Type: application/vnd.ms-excel"); header('Cache-Control: max-age=0'); $filter= $_SESSION['filter']; function vendor($crdid){ $contract_renewal_data = array(); $getVendor= new Select; //echo $crdid; $crdidarray=explode(",",$crdid); $string=""; for($d=0;$d<count($crdidarray);$d++){ $contract_renewal_data = $getVendor->selectWhere('contract_renewal_data','crdid',$crdidarray[$d]); if($contract_renewal_data != null){ if(count($crdidarray)>$d+1){ $string .= "".str_replace(",",".",$contract_renewal_data[0]['vendor'])." ; "; }else{ $string .= "".str_replace(",",".",$contract_renewal_data[0]['vendor']).""; } //echo $string; } } return $string; } require_once 'Spreadsheet/Excel/Writer.php'; […]

在使用PHP进行编码和数据库插入之前,将复杂数据存储到MySQL BLOB中以检索处于相同状态的数据

我正在构build一个将复杂数据插入到MySQL表中的函数,用作创buildCSV文件的队列。 没有进入明确的细节,我想要的只是简单地使用json_encode将数组转换为序列化格式,使用预处理语句将其插入到MySQL表中,然后检索数据json_decode,并将原始数据以完全相同的格式它是在插入之前。 代码如下所示: // Array data previously created foreach ( $array as $key => $element ) { $array[$key] = htmlspecialchars($element,ENT_QUOTES); } $this->db->query("UPDATE `table` SET `blob_field` = '".$this->db->escape($array)."' WHERE `id` = '".(int)$id."'"); 然后我使用以下方法检索数据: $decoded_array = $this->db->query("SELECT `blob_field` FROM `table` WHERE `id` = '".(int)$id."'")->row['blob_field']; $decoded_array = json_decode($decoded_array); $decoded_array = array_map('htmlspecialchars_decode',$decoded_array); // Add to CSV using fputcsv standard […]

PHPExcel_IOFactory :: load($ target_file)在本地主机上工作,但不在服务器上

在将excel文件导入到服务器时,它将不起作用或不会给出任何错误。 在这里,究竟发生了什么事情,首先是在导入excel文件的时候,首先我将该file upload到服务器,然后我使用该文件将数据导入数据库。 文件正确地上传到服务器,但它不会继续工作。 我有debugging该文件,并知道这一点 PHPExcel_IOFactory::load($target_file); is not working 请帮忙。谢谢 代码在这里: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript"> function closeWin() { myWindow.close(); } </script> </head> <body> <?php session_start(); function GetFileExtension($imagetype) { if (empty($imagetype)) return false; switch ($imagetype) { case 'xlsx': return '.xlsx'; case 'xls': return '.xls'; default: return false; } } libxml_use_internal_errors(true); //include […]

包含图像的Excel文件正从Amazon S3中正确下载

我有一个Web应用程序,显示一些用户的数据在一个choropleth,我提供了导出到Excel文件的选项。 直到最近,我们只是在本地存储了图像,然后是Excel文件,并提供了一个链接到服务器上的文件供用户下载,并且工作正常。 最近我们决定把我们的系统切换到使用S3存储文件供用户下载并遇到问题。 当用户下载文件时,显示的图像不是文件(第一个图像)中的内容,而是带有问号的文本框(第二个图像)。 有谁知道为什么S3没有妥善保存在Excel文件中的图像或如何保存它,以便它的工作? 我正在使用PHPExcel库在PHP5.4上首先生成文件。