本文整理汇总了PHP中Spreadsheet_Excel_Reader类的典型用法代码示例。如果您正苦于以下问题:PHP Spreadsheet_Excel_Reader类的具体用法?PHP Spreadsheet_Excel_Reader怎么用?PHP Spreadsheet_Excel_Reader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Spreadsheet_Excel_Reader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
public function main($UrlAppend = NULL, $get = NULL, $post = NULL)
{
if ($this->_isPost()) {
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('utf-8');
$file = $this->_upload();
$data->read($file["path"]);
$keyArr = array();
for ($a = 1; $a < 1000; $a++) {
if ($data->sheets[0]['cells'][1][$a] != "") {
array_push($keyArr, $data->sheets[0]['cells'][1][$a]);
}
}
$dataList = array();
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
$valueArr = array();
for ($b = 0; $b < count($keyArr); $b++) {
if ($keyArr[$b] == "key") {
$key = $data->sheets[0]['cells'][$i][$b + 1];
} else {
$valueArr[$keyArr[$b]] = $data->sheets[0]['cells'][$i][$b + 1];
}
}
$dataList[$key] = $valueArr;
}
$this->_f($_POST["FileName"], $dataList);
}
return $this->_assign;
}
示例2: excelreader
public function excelreader()
{
$this->load->library('Spreadsheet_Excel_Reader.php');
$data = new Spreadsheet_Excel_Reader("./data/example01.xls");
// $data = json_decode('{$data}',true);
echo $data->dump(true, true);
}
示例3: getAll
function getAll()
{
$reader = new Spreadsheet_Excel_Reader();
$reader->setUTFEncoder('iconv');
$reader->setOutputEncoding('UTF-8');
$reader->read($this->filename);
$data = array();
$index_row = 1;
if ($this->have_header) {
$index_row = 2;
}
$iterator = -1;
for ($i = $index_row; $i <= $reader->sheets[$this->sheet_index]['numRows']; $i++) {
$iterator++;
$data[$iterator] = array();
for ($j = 1; $j <= $reader->sheets[$this->sheet_index]['numCols']; $j++) {
if ($this->have_header) {
$data[$iterator][$this->headers[$j - 1]] = $reader->sheets[0]['cells'][$i][$j];
} else {
$data[$iterator][$j - 1] = $reader->sheets[0]['cells'][$i][$j];
}
}
}
return $data;
}
示例4: fileToArray
/**
Helper for xls files. See fileToArray()
*/
public static function xlsToArray($filename, $limit)
{
if (!class_exists('Spreadsheet_Excel_Reader')) {
include_once dirname(__FILE__) . '/../../src/Excel/xls_read/reader.php';
}
$data = new \Spreadsheet_Excel_Reader();
$data->setOutputEncoding('ISO-8859-1');
$data->read($filename);
$sheet = $data->sheets[0];
$rows = $sheet['numRows'];
$cols = $sheet['numCols'];
$ret = array();
for ($i = 1; $i <= $rows; $i++) {
$line = array();
for ($j = 1; $j <= $cols; $j++) {
if (isset($sheet['cells'][$i]) && isset($sheet['cells'][$i][$j])) {
$line[] = $sheet['cells'][$i][$j];
} else {
$line[] = '';
}
}
$ret[] = $line;
if ($limit != 0 && count($ret) >= $limit) {
break;
}
}
return $ret;
}
示例5: import
public function import($file)
{
try {
$users = array();
$params = array(1 => 'user_name', 'user_password', 'user_first_name', 'user_last_name', 'user_email', 'user_group', 'user_vhost');
$excel = new Spreadsheet_Excel_Reader($file);
$rows = $excel->rowcount($sheet_index = 0);
$cols = $excel->colcount($sheet_index = 0);
for ($row = 2; $row <= $rows; $row++) {
if ($cols == 7) {
for ($col = 1; $col <= $cols; $col++) {
$users[$row][$params[$col]] = $excel->val($row, $col);
$users[$row]['user_vhost'] = explode(',', $excel->val($row, 7));
$users[$row]['user_group'] = '';
}
}
}
$this->userimport = new userimport();
$users = $this->userimport->import($users);
$_SESSION['message'] = $this->userimport->get_message();
return $users;
} catch (Exception $e) {
display_page_error();
}
}
示例6: import
/**
* Importa la nomina de estudiantes desde una hoja excel
*/
public function import($archivo)
{
include_once 'system/application/libraries/excel_reader2.php';
$excel = new Spreadsheet_Excel_Reader("system/excel/alumnos/{$archivo}");
$i = 2;
$this->db->trans_start();
while (intval($excel->val($i, 1))) {
$codigo = intval($excel->val($i, 1));
$arr = array();
foreach ($this->columnas as $col => $pos) {
$arr[$col] = $excel->val($i, $pos);
}
$arr['sexo'] = intval($arr['sexo']) == 1 ? 'M' : 'F';
if ($alumno = $this->alumnoExiste($codigo)) {
// Actualizar
$arr['id'] = $alumno['id'];
$this->update($arr);
} else {
// Crear
$this->create($arr);
}
$i++;
}
$this->db->trans_complete();
}
示例7: do_upload
function do_upload()
{
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'php|txt|xls|xml';
$config['max_size'] = '1000000';
//$config['max_width'] = '1024';
//$config['max_height'] = '768';
$this->load->library('upload', $config);
if (!$this->upload->do_upload()) {
$error = array('error' => $this->upload->display_errors());
//$this->load->view('header');
$this->load->view('upload_view', $error);
//$this->load->view('footer');
} else {
$data = array('upload_data' => $this->upload->data());
$this->load->library('Excel/spreadsheet_Excel_Reader');
//require_once 'Excel/reader.php';
// ExcelFile($filename, $encoding);
$excel = new Spreadsheet_Excel_Reader();
// Set output Encoding.
$excel->setOutputEncoding('CP1251');
//lecture du fichier excel
//chmod('./upload/' . $data['upload_data']['file_name'], 0777);
$excel->read('./upload/' . $data['upload_data']['file_name']);
//$liste = array($excel->sheets[0]['numRows'],2);
$array = $excel->sheets[0]['cells'];
$temp = array_shift($array);
var_dump($array);
//$this->data_model->insert_entry($array);
$this->load->view('upload_success', $data);
}
}
示例8: ABSSAV
function ABSSAV()
{
$inFile = $_REQUEST['inFile'];
echo "Filename is: {$inFile}<br>";
require_once 'Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251');
$data->read($inFile);
error_reporting(E_ALL ^ E_NOTICE);
$Target_Database = 'binawan';
$Target_Table = $Target_Database . '.ruang';
$Target_KodeID = "BINAWAN";
$s = "TRUNCATE TABLE {$Target_Table}";
$r = _query($s);
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
$w = array();
$w['RuangID'] = trim($data->sheets[0]['cells'][$i][2]);
$w['Nama'] = trim($data->sheets[0]['cells'][$i][3]);
$w['Kapasitas'] = trim($data->sheets[0]['cells'][$i][4]);
$w['KapasitasUjian'] = trim($data->sheets[0]['cells'][$i][4]);
$w['KolomUjian'] = trim($data->sheets[0]['cells'][$i][5]);
$w['KampusID'] = trim($data->sheets[0]['cells'][$i][6]);
$w['Lantai'] = trim($data->sheets[0]['cells'][$i][7]);
$w['RuangKuliah'] = trim($data->sheets[0]['cells'][$i][8]);
$s = "insert into {$Target_Table}\r\n (RuangID, Nama, Kapasitas, KapasitasUjian, KolomUjian, KampusID, Lantai, KodeID, RuangKuliah, UntukUSM\r\n\t )\r\n values\r\n ('{$w['RuangID']}', '{$w['Nama']}', '{$w['Kapasitas']}', '{$w['KapasitasUjian']}', '{$w['KolomUjian']}', '{$w['KampusID']}', '{$w['Lantai']}', 'BINAWAN', '{$w['RuangKuliah']}', '{$w['RuangKuliah']}'\r\n\t )";
$r = _query($s);
}
echo "<script>window.location = '?{$mnux}={$_SESSION['mnux']}'</script>";
}
示例9: doimport
function doimport()
{
$file_name = $_GET['province_id'] . ".xls";
if ($file_name != '') {
//$ext = pathinfo($_FILES['filename']['name'], PATHINFO_EXTENSION);
//echo $file_name = 'nursery.'.$ext;
$uploaddir = 'import/tmp/';
$fpicname = $uploaddir . $file_name;
///move_uploaded_file($_FILES['filename']['tmp_name'], $fpicname);
require_once 'include/Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('UTF-8');
$data->read($fpicname);
error_reporting(E_ALL ^ E_NOTICE);
$index = 0;
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
$amphur = new Amphur();
$amphur = $amphur->where(" amphur_name ='" . trim($data->sheets[0]['cells'][$i][1]) . "'")->get();
$import[$index]['province_id'] = $_POST['province_id'];
$import[$index]['amphur_id'] = $amphur->id;
$import[$index]['name'] = trim($data->sheets[0]['cells'][$i][2]);
$index++;
if ($amphur->id > 0) {
$_POST['province_id'] = $_GET['province_id'];
$_POST['amphur_id'] = $amphur->id;
$_POST['name'] = trim($data->sheets[0]['cells'][$i][2]);
$nursery = new Nursery_Tmp();
$nursery->from_array($_POST);
$nursery->save();
}
}
}
}
示例10: insertUpdateNotas
/**
* Realiza la inserción o actualización de notas de un estudiante
* @param string
* @param integer
*/
function insertUpdateNotas($archivo, $anio)
{
include_once 'system/application/libraries/excel_reader2.php';
$excel = new Spreadsheet_Excel_Reader("system/excel/notas/{$archivo}");
$alumnos = $this->loadModel('Alumno_model')->getList(array('labelField' => 'id', 'valueField' => 'codigo'));
$materias = $this->loadModel('Materia_model')->getList(array('labelField' => 'id', 'valueField' => 'nombre'));
$i = 2;
$this->errors = array();
$this->db->trans_start();
while (trim($excel->val($i, 1)) != '') {
$codigo = trim($excel->val($i, 1));
if (!isset($alumnos[$codigo])) {
array_push($this->errors, "No existe un alumno con código \"{$codigo}\" fila {$i} del archivo excel");
$i++;
continue;
}
$alumno_id = $alumnos[$codigo];
$materia_nombre = trim($excel->val($i, 2));
if (!isset($materias[$materia_nombre])) {
array_push($this->errors, "No existe la materia \"{$materia_nombre}\" en la fila {$i} del archivo excel");
$i++;
continue;
}
$materia_id = $materias[$materia_nombre];
$this->setNota($alumno_id, $materia_id, $excel, $anio, $i);
$i++;
}
$this->db->trans_complete();
return $this->errors;
}
示例11: add_in_mysql
public function add_in_mysql()
{
if (!empty($_FILES['efile']['name'])) {
$exname = strtolower(substr($_FILES['efile']['name'], strrpos($_FILES['efile']['name'], '.') + 1));
$uploadfile = $this->getnames($exname);
//上传后文件所在的路径
@move_uploaded_file($_FILES['efile']['tmp_name'], $uploadfile);
}
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('utf-8');
$data->read($uploadfile);
//读取要导入数据库的文件
error_reporting(E_ALL ^ E_NOTICE);
$Stu = D("Stu");
//$User->startTrans();//启动事务;
$filed = C("excle");
//获取字段对应的列
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
$col = $data->sheets[0]['cells'][$i];
$arr = array("stuno" => $col[$filed["stuno"]], "stuname" => $col[$filed["stuname"]], "password" => $col[$filed["password"]], "sex" => $col[$filed["sex"]], "idcard" => $col[$filed["idcard"]], "classno" => $col[$filed["classno"]], "college" => "1");
$Stu->create($arr);
echo $Stu->getError() . "<br/>";
if (!$Stu->add()) {
$Stu->rollback();
//不成功,回滚
echo "导入失败回滚";
return;
}
echo $arr["stuno"] . "导入成功<br/>";
}
$Stu->commit();
//成功提交
}
示例12: readRoom
function readRoom($file, $table, $pos)
{
require_once "conn.php";
$sql = "TRUNCATE TABLE {$table}";
if ($mysqliObj->query($sql)) {
echo "truncate success" . "</br>";
}
require_once 'Excel/reader.php';
// ExcelFile($filename, $encoding);
$data = new Spreadsheet_Excel_Reader();
// Set output Encoding.
// $data->setOutputEncoding('CP936');
$data->setOutputEncoding('gbk');
$data->read($file);
error_reporting(E_ALL ^ E_NOTICE);
//$data->sheets[0]['numRows']
for ($i = $pos; $i <= $data->sheets[0]['numRows']; $i++) {
$msg1 = $data->sheets[0]['cells'][$i][1];
$msg2 = $data->sheets[0]['cells'][$i][2];
$msg3 = $data->sheets[0]['cells'][$i][3];
$sql = "INSERT INTO {$table} (`roomId` ,`type` ,`price` )\n\t\t\t\tVALUES ('{$msg1}', '{$msg2}', '{$msg3}')";
if (!is_null($data->sheets[0]['cells'][$i][1])) {
$mysqliObj->query($sql);
}
}
$mysqliObj->close();
}
示例13: ABSSAV
function ABSSAV()
{
$inFile = $_REQUEST['inFile'];
require_once 'Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251');
$data->read($inFile);
error_reporting(E_ALL ^ E_NOTICE);
$Target_Database = 'binawan';
$Target_Table = $Target_Database . 'mhsw';
$Target_KodeID = "BINAWAN";
$s = "TRUNCATE TABLE ";
$r = _query($s);
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
$w = array();
$w['MhswID'] = trim($data->sheets[0]['cells'][$i][1]);
$w['TahunID'] = trim($data->sheets[0]['cells'][$i][2]);
$w['Nama'] = trim($data->sheets[0]['cells'][$i][3]);
$w['Kelamin'] = trim($data->sheets[0]['cells'][$i][4]);
$w['TempatLahir'] = trim($data->sheets[0]['cells'][$i][5]);
$w['TanggalLahir'] = trim($data->sheets[0]['cells'][$i][6]);
$w['Agama'] = trim($data->sheets[0]['cells'][$i][7]);
$w['Alamat'] = trim($data->sheets[0]['cells'][$i][8]);
$s = "insert into {$Target_Database}\r\n (MhswID, Login, LevelID, Password, PMBID, \r\n\t\t TahunID, KodeID, Nama, \r\n\t\t Foto, StatusMhswID, ProgramID, ProdiID, KelasID,\r\n\t\t Kelamin, TempatLahir, TanggalLahir, Agama, Alamat, \r\n\t\t Kota, RT, RW, KodePos, Propinsi, Negara, \r\n\t\t Telepon, Handphone \r\n\t )\r\n values\r\n ('{$w['MhswID']}', '{$w['Login']}', '120', '{$w['Password']}', '{$w['PMBID']}', \r\n\t\t '{$w['TahunID']}', '{$Target_KodeID}', '{$w['Nama']}', \r\n\t\t '{$w['Foto']}', '{$w['StatusMhswID']}', '{$w['ProgramID']}', '{$w['ProdiID']}', '{$w['KelasID']}',\r\n\t\t '{$w['Kelamin']}', '{$w['TempatLahir']}', '{$w['TanggalLahir']}', '{$w['Agama']}', '{$w['Alamat']}', \r\n\t\t '{$w['Kota']}', '{$w['RT']}', '{$w['RW']}', '{$w['KodePos']}', '{$w['Propinsi']}', '{$w['Negara']}', \r\n\t\t '{$w['Telepon']}', '{$w['Handphone']}' \r\n\t )";
$r = _query($s);
}
echo "<script>window.location = '?{$mnux}={$_SESSION['mnux']}'</script>";
}
示例14: updateDB
function updateDB($startIndex, $endIndex)
{
//need to copy the code that does the excel reading
$analysisData = new Spreadsheet_Excel_Reader();
// Set output Encoding.
$analysisData->setOutputEncoding('CP1251');
$inputFileName = 'ReverseGeoCodingForStopsVerification.xls';
$analysisData->read($inputFileName);
error_reporting(E_ALL ^ E_NOTICE);
$numRows = $analysisData->sheets[0]['numRows'];
$numCols = $analysisData->sheets[0]['numCols'];
//echo $numRows.",".$numCols;
$strRoute = '<Routes>';
for ($i = $startIndex; $i <= $endIndex; $i++) {
$stopId = $analysisData->sheets[0]['cells'][$i][1];
$StopName = $analysisData->sheets[0]['cells'][$i][2];
$Buses = $analysisData->sheets[0]['cells'][$i][3];
$latitude = $analysisData->sheets[0]['cells'][$i][4];
$longitude = $analysisData->sheets[0]['cells'][$i][5];
$strRoute = $strRoute . '<Route>';
$routeDetails = htmlentities(trim($StopName)) . ":" . $latitude . ":" . $longitude;
//echo $routeDetails."<br/>";
$strRoute = $strRoute . '<RouteDetails>' . $routeDetails . '</RouteDetails>';
$strRoute = $strRoute . '</Route>';
}
$strRoute = $strRoute . '</Routes>';
echo $strRoute;
}
示例15: getDataFromExcel
function getDataFromExcel($filename)
{
$uimap = new Spreadsheet_Excel_Reader();
$uimap->read($this->path . "\\data\\uimap\\" . $filename . ".xls");
$s = 0;
foreach ($uimap->boundsheets as $ar) {
$i = 2;
while ($i <= $uimap->sheets[$s]['numRows']) {
if (!empty($uimap->sheets[$s]['cells'][$i][2]) && !empty($uimap->sheets[$s]['cells'][$i][3]) && strtolower($ar['name']) != 'datamap') {
$this->sheets[strtolower($ar['name'])][strtolower($uimap->sheets[$s]['cells'][$i][2])] = $uimap->sheets[$s]['cells'][$i][3];
} elseif (!empty($uimap->sheets[$s]['cells'][$i][2]) && strtolower($ar['name']) == 'datamap') {
$datafile = new Spreadsheet_Excel_Reader();
$datafile->read($this->path . "\\" . $uimap->sheets[$s]['cells'][$i][3]);
$j = 2;
while ($j <= $datafile->sheets[0]['numRows']) {
if (!empty($datafile->sheets[0]['cells'][$j][2])) {
if (empty($datafile->sheets[0]['cells'][$j][4])) {
$this->datamap[strtolower($datafile->sheets[0]['cells'][$j][2])] = $datafile->sheets[0]['cells'][$j][3];
} else {
$y = 3;
while (!empty($datafile->sheets[0]['cells'][$j][$y])) {
$this->datamap[strtolower($datafile->sheets[0]['cells'][$j][2])][] = $datafile->sheets[0]['cells'][$j][$y];
$y++;
}
}
}
$j++;
}
}
$i++;
}
$s++;
}
$this->uimap = $this->sheets;
}