本文整理汇总了PHP中Spreadsheet_Excel_Reader::setUTFEncoder方法的典型用法代码示例。如果您正苦于以下问题:PHP Spreadsheet_Excel_Reader::setUTFEncoder方法的具体用法?PHP Spreadsheet_Excel_Reader::setUTFEncoder怎么用?PHP Spreadsheet_Excel_Reader::setUTFEncoder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spreadsheet_Excel_Reader
的用法示例。
在下文中一共展示了Spreadsheet_Excel_Reader::setUTFEncoder方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: TestBackupExcel
function TestBackupExcel()
{
$filename = 'products_test.xls';
$this->p_ex->DownloadIdMot = 1;
// We will create file with articles, that are connected with id_mot=1
$this->p_ex->DownloadRubriques = array(1);
// We will create file with articles, that lie in rubrique 1
$this->p_ex->BackupExcel($filename);
$full_path = $this->p_ex->GetTmpDir() . $filename;
$this->assertTrue(file_exists($full_path), 'Excel file hasn\'t been created!');
$reader = new Spreadsheet_Excel_Reader();
$reader->setUTFEncoder('iconv');
$reader->setOutputEncoding('UTF-8');
$reader->read($full_path);
$this->assertEqual(1, count($reader->sheets));
// Document must contain 1 sheet
$rows = $reader->sheets[0]["cells"];
$this->assertEqual(3, count($rows));
// Document must contain 1 heading + 1 data = 2 rows
if (file_exists($full_path)) {
unlink($full_path);
}
}
示例4: importAction
public function importAction()
{
$result = array('success' => true, 'info' => '导入成功');
$request = $this->getRequest()->getParams();
$now = date('Y-m-d H:i:s');
if (isset($_FILES['csv'])) {
$now = date('Y-m-d H:i:s');
$user_session = new Zend_Session_Namespace('user');
$user_id = $user_session->user_info['user_id'];
$file = $_FILES['csv'];
$file_extension = strrchr($file['name'], ".");
$h = new Application_Model_Helpers();
$tmp_file_name = $h->getMicrotimeStr() . $file_extension;
$savepath = "../temp/";
$tmp_file_path = $savepath . $tmp_file_name;
move_uploaded_file($file["tmp_name"], $tmp_file_path);
$plist = new Product_Model_Productlist();
// 读取文件
require_once LIBRARY_PATH . "/Excel/reader.php";
$reader = new Spreadsheet_Excel_Reader();
$reader->setOutputEncoding('UTF-8');
$reader->setUTFEncoder('mb');
$reader->setRowColOffset(1);
$reader->read($tmp_file_path);
error_reporting(E_ALL ^ E_NOTICE);
$data = array();
for ($i = 1; $i <= $reader->sheets[0]['numRows']; $i++) {
$row = array();
for ($j = 1; $j <= $reader->sheets[0]['numCols']; $j++) {
$row[] = $reader->sheets[0]['cells'][$i][$j];
}
$data[] = $row;
}
// 数据校验
if (count($data) <= 1) {
$result['success'] = false;
$result['info'] = "文件中无数据!";
echo Zend_Json::encode($result);
exit;
}
$cols = array("sn", "code", "step", "description", "is_bom_exists", "bom_apply_time", "bom_archive_time", "product_code", "bosa", "bosa_supply", "tosa", "tosa_supply", "rosa", "rosa_supply", "pcb", "pcba", "dg02", "dg01", "product_label", "barcode_label", "label_print_rule", "tooling_model", "sample_send_time", "pra", "trial_produce_qa1", "pmr", "dl", "ipa", "cri", "ds", "dd", "pl", "pes", "pcb_file", "icd", "smt", "mp", "sqr", "dvs", "dvp", "dvr", "dvt", "rtr", "emr", "mtb", "tsq", "sqc", "ed", "pts", "sp", "ep", "fep", "fsp", "ld", "pd", "pg", "nfc", "frm", "pfc", "wi", "other", "create_time", "create_user", "update_time", "update_user");
for ($i = 1; $i < count($data); $i++) {
$num = $i + 1;
$row = $data[$i];
if (count($row) < 2 || !$row[1]) {
continue;
}
$code = $row[1];
if (!$this->checkExists($code)) {
$insertData = array();
$k = 0;
foreach ($cols as $c) {
$insertData[$c] = $row[$k];
$k++;
}
try {
$plist->insert($insertData);
} catch (Exception $e) {
$result['result'] = false;
$result['info'] = $e->getMessage();
echo Zend_Json::encode($result);
exit;
}
} else {
$errors[] = $code;
}
}
$result['error'] = $errors;
}
echo Zend_Json::encode($result);
exit;
}
示例5: extract_text
//.........这里部分代码省略.........
}
else if($retval > 128 && $retval < 255) {
$message = " Fatal error code $retval";
printDocReport($message, $cl);
}
else if($retval == 255) {
$message = " Exit status out of range. Exit takes only integer range 0 – 255.";
printDocReport($message, $cl);
} else {
$message = " Unknown error code $retval.";
printDocReport($message, $cl);
}
}
*/
}
// for PPT files enter here
} else {
if ($source_type == 'ppt') {
// currently unsupported,as a failure was encountered for large PowerPoint presentations
$a = '';
/*
$command = $catppt_path." -s $charset_int -d utf-8 $filename";
$a = exec($command, $result, $retval);
*/
// for XLS spreadsheets enter here
} else {
if ($source_type == 'xls') {
$error = '';
require_once "" . $converter_dir . "/xls_reader.php";
$data = new Spreadsheet_Excel_Reader();
if ($mb == '1') {
// if extention exists, change 'iconv' to mb_convert_encoding:
$data->setUTFEncoder('mb');
}
// set output encoding.
$data->setOutputEncoding('UTF-8');
// read this document
$data->read($filename);
$error = $data->_ole->error;
if ($error == '1') {
printStandardReport('xlsError', $command_line, $no_log);
$result = 'ERROR';
} else {
$result = '';
$boundsheets = array();
$sheets = array();
$boundsheets = $data->boundsheets;
// get all tables in this file
$sheets = $data->sheets;
// get content of all sheets in all tables
if ($boundsheets) {
foreach ($boundsheets as &$bs) {
$result .= "" . $bs['name'] . ", ";
// collect all table names in this file
}
if ($sheets) {
foreach ($sheets as &$sheet) {
$cells = $sheet['cells'];
if ($cells) {
// ignore all empty cells
foreach ($cells as &$cell) {
foreach ($cell as &$content) {
$result .= "" . $content . ", ";
// collect content of all cells
}
示例6: xls2Array
public static function xls2Array($file, $DOCUMENT_ROOT, $setOutput = false)
{
mb_internal_encoding("ISO-8859-1");
require_once $DOCUMENT_ROOT . '/vendor/excel/excel_reader2.php';
$data = new Spreadsheet_Excel_Reader();
if ($setOutput) {
$data->setOutputEncoding('CP-1251');
}
$data->setUTFEncoder('mb');
$data->read($file);
$arStrings = $data->sheets;
return $arStrings[0]["cells"];
}
示例7: array
$file = "{$url_path}{$file}";
$short_desc = '';
$title = '';
$required = '';
$disallowed = '';
$can_leave_domain = '';
$parent_num = "0";
$lines = array();
// read .xls files into an array
if (stristr($file, ".xls")) {
$error = '';
require_once "" . $converter_dir . "/xls_reader.php";
$data = new Spreadsheet_Excel_Reader();
if ($mb == '1') {
// if extention exists, change 'iconv' to mb_convert_encoding:
$data->setUTFEncoder('mb');
}
// set output encoding.
$data->setOutputEncoding('UTF-8');
// read this document
$data->read($file);
$error = $data->_ole->error;
if ($error == '1') {
printStandardReport('xlsError', $command_line, $no_log);
$result = 'ERROR';
} else {
$result = ' ';
$boundsheets = array();
$sheets = array();
$boundsheets = $data->boundsheets;
// get all tables in this file
示例8: uploadAction
public function uploadAction()
{
error_reporting(E_ALL);
$this->_initLayoutMessages('core/session');
$messages = Mage::getSingleton("customer/session")->getMessages();
$post_data = Mage::app()->getRequest()->getPost();
$uploadFiletype = $post_data['type'];
$redirectUrl = $post_data['admin_url'];
$file_name = $_FILES["file"]["name"];
$file_type = $_FILES["file"]["type"];
// File Type check
if ($file_type == 'application/vnd.ms-excel') {
// Code for File upload
if (isset($_FILES['file']['name']) && $_FILES['file']['name'] != "") {
$uploader = new Varien_File_Uploader("file");
$uploader->setAllowedExtensions(array('xls'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir("media") . DS . "upload" . DS;
$uploader->save($path);
}
$excel_reader_path = Mage::getBaseDir("media") . DS . "Excel" . DS;
$file_sourece = $path . $_FILES['file']['name'];
require_once $excel_reader_path . 'excel_reader2.php';
$excel_reader = new Spreadsheet_Excel_Reader();
$excel_reader->setUTFEncoder('iconv');
$excel_reader->setOutputEncoding('CP1251');
$file = $excel_reader->read($file_sourece, "UTF-16");
$file_row = 3;
$column_count = $excel_reader->sheets[0]['numCols'];
$row_count = $excel_reader->sheets[0]['numRows'];
$row_check = 0;
for ($file_row; $file_row <= $excel_reader->sheets[0]['numRows']; $file_row++) {
@($data1 = addslashes($excel_reader->sheets[0]['cells'][$file_row][1]));
@($data2 = addslashes($excel_reader->sheets[0]['cells'][$file_row][2]));
@($data3 = addslashes($excel_reader->sheets[0]['cells'][$file_row][3]));
@($data4 = $excel_reader->sheets[0]['cells'][$file_row][4]);
@($data5 = addslashes($excel_reader->sheets[0]['cells'][$file_row][5]));
@($data6 = addslashes($excel_reader->sheets[0]['cells'][$file_row][6]));
$pincode = $data4;
$collection = Mage::getModel('fileupload/fileupload')->getCollection();
$collection->addFieldToFilter('pincode', array('like' => '%' . $pincode . '%'));
$getDatas = $collection->getData();
/* echo "<pre>";
print_r($getDatas);
echo "Count ".count($getDatas);
echo "</pre>";
exit;*/
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
$connection->beginTransaction();
$sql = 'INSERT INTO fileupload (`location`, `branch_detail`, `served_by`, `pincode`, `area`, `file_type`, `state`) VALUES("' . $data1 . '","' . $data2 . '","' . $data3 . '","' . $data4 . '","' . $data5 . '","' . $uploadFiletype . '", "' . $data6 . '")';
$sql;
$checkData = $connection->query($sql);
$connection->commit();
$row_check++;
}
$this->_redirect('fileupload/adminhtml_fileupload/index/key/' . $redirectUrl . '?fstatus=1&data_cnt=' . $row_check);
} else {
$this->_redirect('fileupload/adminhtml_fileupload/index/key/' . $redirectUrl . '?fstatus=2');
}
}
示例9: updateProductsFromExcel
//.........这里部分代码省略.........
if (!$id_rubrique) {
$id_rubrique = intval($product_id_rubrique);
if (!$id_rubrique) {
$id_rubrique = $id_reserv;
}
// to do make reserv
}
$rubrique = $this->rubrique_mdl->select_by_id($id_rubrique);
if (!$rubrique) {
$rubrique = $this->rubrique_mdl2->get_rubric_by_id_import($id_rubrique);
$id_rubrique = $rubrique['id_rubrique'];
}
if (!$rubrique) {
continue;
}
$article_data['id_rubrique'] = $id_rubrique;
$article_data['id_secteur'] = $rubrique['id_secteur'];
// Update product
if (!$this->product_mdl->update_by_id($id_article, $product_data)) {
throw new Exception("Error while updating product #" . $id_article);
}
// Update article
if (!$this->article_mdl->update_by_id($id_article, $article_data)) {
throw new Exception("Error while updating article #" . $id_article);
}
}
}
$i++;
spip_log("{$i}", 'excel.' . _LOG_ERREUR);
}
fclose($fd);
} else {
$reader = new Spreadsheet_Excel_Reader();
$reader->setUTFEncoder('iconv');
$reader->setOutputEncoding('UTF-8');
$reader->read($file_path);
spip_log("EXCEL IMPORT START", 'excel.' . _LOG_ERREUR);
foreach ($reader->sheets as $k => $data) {
// $reader->boundsheets[$k]['name']; // Sheet name
foreach ($data["cells"] as $row_num => $row) {
if ($row_num == 1 || $row_num == 2) {
spip_log($row_num, 'excel.' . _LOG_ERREUR);
spip_log('row_0' . $row[0], 'excel.' . _LOG_ERREUR);
spip_log('row_1' . $row[1], 'excel.' . _LOG_ERREUR);
spip_log('row_2' . $row[2], 'excel.' . _LOG_ERREUR);
spip_log('row_3' . $row[3], 'excel.' . _LOG_ERREUR);
spip_log('row_4' . $row[4], 'excel.' . _LOG_ERREUR);
spip_log('row_5' . $row[5], 'excel.' . _LOG_ERREUR);
spip_log('row_6' . $row[6], 'excel.' . _LOG_ERREUR);
spip_log('row_7' . $row[7], 'excel.' . _LOG_ERREUR);
}
if ($row_num == 1) {
continue;
}
//omit first row
$id_article = false;
$primary_val = $row["{$col_primary}"];
// First cell has index 1!
//if ($primary_val) {
$product_data = array();
$product_data['sku'] = $row["2"];
//$product_data['titre'] = $row["4"];
$product_data['quantity'] = $row["6"];
$product_data['price'] = $row["7"];
$product_data['priceold'] = $row["8"];
$article_data = array();
示例10: importAction
/**
* импорт товаров
*/
function importAction()
{
if ($_POST) {
// коннектим функцию
require_once ADMIN_PATH . '/plagin/excel/reader.php';
// ExcelFile($filename, $encoding);
$data = new Spreadsheet_Excel_Reader();
// Set output Encoding.
$data->setOutputEncoding('UTF8');
$data->setUTFEncoder('mb');
$data->read($_FILES['file1']['tmp_name']);
error_reporting(E_ALL ^ E_NOTICE);
$_str = array();
// С отключением товара
if ($_POST['type_import'] == 0) {
// обнуляем склад
$_sql = "UPDATE `catalog` SET `sklad`='0' WHERE (`supplier`='" . $_POST['supplier'] . "')";
$result = mysql::just_query($_sql, 0);
}
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
$_str[] = $data->sheets[0]['cells'][$i][$j];
}
$_sql = "SELECT * FROM `catalog` WHERE (`artikul`='" . $_str[0] . "')";
$result_artikul = mysql::query_one($_sql, 0);
if ($result_artikul) {
// работаем с ценой
if ($_str[2] == "") {
$_sql = "UPDATE `catalog` \n\t\t\t\t\t\t\t\tSET `name`='" . $_str[1] . "', `sklad`='2'\n\t\t\t\t\t\t\t\tWHERE (`artikul`='" . $_str[0] . "')";
$result = mysql::just_query($_sql, 0);
} else {
$_sql = "UPDATE `catalog` \n\t\t\t\t\t\t\t\tSET `name`='" . $_str[1] . "', `sklad`='1'\n\t\t\t\t\t\t\t\tWHERE (`artikul`='" . $_str[0] . "')";
$result = mysql::just_query($_sql, 0);
}
// C обновленимем цены
if ($_POST['type_import1'] == 0) {
$_sql = "UPDATE `catalog` \n\t\t\t\t\t\t\t\tSET `cost`='" . $_str[3] . "'\n\t\t\t\t\t\t\t\tWHERE (`artikul`='" . $_str[0] . "')";
$result = mysql::just_query($_sql, 0);
}
} else {
// товара нет на сайте
if ($_str[2] == "") {
$_sklad = 2;
} else {
$_sklad = 1;
}
$_sql = "INSERT INTO `catalog` (`artikul`, `name`, `cost`, `id_parent`, `status`, `created_at`, `sklad`, `supplier`) \n\t\t\t\t\t\t\tVALUES ('" . $_str[0] . "', '" . $_str[1] . "', '" . $_str[3] . "', '1', '1', '" . date('Y-m-d') . "', '" . $_sklad . "', '" . $_POST['supplier'] . "')";
$result = mysql::just_query($_sql, 0);
}
$_str = "";
}
}
// строим запрос
$_sql = 'SELECT * FROM `supplier` where status=1 order by sort';
// выполняем запрос + при необходимости выводим сам запрос
$select = mysql::query($_sql, 0);
return system::show_tpl(array('msg' => $this->msg, 'tpl_folder' => $this->tpl_folder, 'select' => $select), $this->tpl_folder . '/import.php');
}