本文整理汇总了PHP中Spreadsheet_Excel_Reader::setOutputEncoding方法的典型用法代码示例。如果您正苦于以下问题:PHP Spreadsheet_Excel_Reader::setOutputEncoding方法的具体用法?PHP Spreadsheet_Excel_Reader::setOutputEncoding怎么用?PHP Spreadsheet_Excel_Reader::setOutputEncoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spreadsheet_Excel_Reader
的用法示例。
在下文中一共展示了Spreadsheet_Excel_Reader::setOutputEncoding方法的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: 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;
}
示例3: 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>";
}
示例4: xlsToArray
/**
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: 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;
}
示例6: localUploadSNExcel
public function localUploadSNExcel()
{
$return = $this->localUpload(array('xls'));
if ($return['error']) {
$this->error($return['msg']);
} else {
$data = new Spreadsheet_Excel_Reader();
// 设置输入编码 UTF-8/GB2312/CP936等等
$data->setOutputEncoding('UTF-8');
$data->read(str_replace('http://' . $_SERVER['HTTP_HOST'], $_SERVER['DOCUMENT_ROOT'], $return['msg']));
chmod(str_replace('http://' . $_SERVER['HTTP_HOST'], $_SERVER['DOCUMENT_ROOT'], $return['msg']), 0777);
//
$sheet = $data->sheets[0];
$rows = $sheet['cells'];
if ($rows) {
$i = 0;
foreach ($rows as $r) {
if ($i != 0) {
$db = M('Lottery_record');
$where = array('token' => $this->token, 'lid' => intval($_POST['lid']), 'sn' => trim($r[1]));
$check = $db->where($where)->find();
if (!$check) {
$where['prize'] = intval($r['2']);
$db->add($where);
}
}
$i++;
}
}
$this->success('操作完成');
}
}
示例7: 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>";
}
示例8: 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();
//成功提交
}
示例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: 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();
}
示例11: array
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);
}
}
示例12: popola
function popola($file, $id_associazione)
{
$data = new Spreadsheet_Excel_Reader();
//$data->setOutputEncoding('CP1251'); //UTF-8
$data->setOutputEncoding('UTF-8');
$data->read($file);
error_reporting(E_ALL ^ E_NOTICE);
$counter = 0;
$counterP = 0;
$log_error = new log();
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
$counterP++;
echo $counterP . " ";
if ($counterP % 100 == 0) {
echo "\n Processati: " . $counterP . "\n";
}
ob_flush();
flush();
$query = "INSERT into soci (nome,mail) values ";
$query .= "(";
echo $data->sheets[0]['cells'][$i][1] . " ... \n";
$actual_element = trim($data->sheets[0]['cells'][$i][1], " \t\n\r\v,;");
echo $actual_element;
$actual_element = mysql_real_escape_string($actual_element);
$actual_element2 = trim($data->sheets[0]['cells'][$i][2], " \t\n\r\v,;");
$mail = mysql_real_escape_string($actual_element2);
$query .= "'" . $actual_element . "','" . $mail . "'";
// Aggiungi user e password
//$query.="'".(($email=="") ? getUniqueCode(10) : $email)."','".getUniqueCode(10)."',$id_associazione";
$query .= ")";
//validate email
if (!Swift_Validate::email($actual_element2)) {
//validate email, log error
$log_error->scrivi_popola($actual_element . "\t" . $mail);
} else {
//insert into DB
$result = mysql_query("SELECT id FROM soci WHERE mail='" . $mail . "'");
if ($riga = mysql_fetch_assoc($result)) {
//if the mail is already in the database
$int_id = $riga['id'];
} else {
if (!mysql_query($query)) {
//insert new record
echo "ti è andata male ";
echo $query;
return false;
}
$int_id = mysql_insert_id();
$counter++;
}
if ($id_associazione > 0) {
mysql_query("INSERT into interessi_soci (id_socio,id_interesse) values ('{$int_id}','{$id_associazione}')");
}
}
}
$log_error->close_popola();
//return $data->sheets[0]['numRows']-1;
return "<BR>Letti " . $counterP . " e inseriti (non duplicati) " . $counter;
}
示例13: get_student_schedule
function get_student_schedule($filename, $teacherSchedule)
{
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('UTF8');
$data->setUTFEncoder('mb');
$data->read($filename);
return get_result_student($data, $teacherSchedule);
}
示例14: readxlsmain
function readxlsmain($file)
{
$d = new Spreadsheet_Excel_Reader();
$d->setOutputEncoding('utf-8');
$d->read($file);
$data = array();
$data['boundsheets'] =& $d->boundsheets;
$data['sheets'] =& $d->sheets;
return $data;
}
示例15: process_file
function process_file($filename, &$tempname)
{
global $_SGLOBAL;
$isfile = 1;
$data = new Spreadsheet_Excel_Reader();
//exit('adsf');
$data->setOutputEncoding('gbk');
$data->read($filename);
$tempname = date("Y-m-d") . '_download_' . rand() . '.xls';
$filedownload = S_ROOT . './plugin/invite/download/' . $tempname;
//初始化一个反馈结果的文件
require_once S_ROOT . './plugin/invite/phpwritexcel/Writer.php';
$workbook = new Spreadsheet_Excel_Writer($filedownload);
$worksheet =& $workbook->addWorksheet('Sheet1');
$worksheet->setInputEncoding('utf-8');
$format_column =& $workbook->addformat(array('Size' => 9, 'Bold' => 1));
//读取结果文件的信息
$rows = 0;
$recordindex = array('realname', 'sex', 'birthday', 'otheremail', 'academy', 'collegeid', 'class', 'mobile', 'unit');
$record = array('好友姓名(必填)', '好友性别', '生日(8位)', '邮箱(必填)', '学院', '学号', '班别', '手机(必填)', '所在单位', '备注');
$dataindexinfo = array();
encode_record(&$record);
input_downloadfile($worksheet, $rows, $record, $format_column);
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
//以下注释的for循环打印excel表数据
$datainfo = array();
//$datainfo = array('name', 'sex', 'birthday', 'otheremail', 'academy', 'collegeid', 'class', 'mobile', 'unit');
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
$datainfo[$j - 1] = $data->sheets[0]['cells'][$i][$j];
$dataindexinfo[$recordindex[$j - 1]] = $data->sheets[0]['cells'][$i][$j];
}
//var_dump($datainfo[0]);
//检查记录的正确性
$nopass = checkinfo($datainfo[0], $datainfo[2], $datainfo[3], $datainfo[7], $isfile);
if (!empty($nopass)) {
//没有通过的记录加入到一个新文件中
$datainfo[$j - 1] = $nopass;
encode_record(&$datainfo);
//var_dump($datainfo);
//var_dump($rows);
input_downloadfile($worksheet, &$rows, $datainfo, $format_column);
continue;
}
//邀请处理
//var_dump($dataindexinfo);
inserttable('baseprofile', $dataindexinfo, 1);
//var_dump($datainfo);
invite_alumni($datainfo);
}
$workbook->close();
return $rows;
}