csv文件导入导出
2013-03-29 14:50
471 查看
<?php class CSV_Import_Export { private function export_term_user(){ header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="学员成绩.csv"'); header('Cache-Control: max-age=0'); $fp = fopen('php://output', 'a'); $thead = '编号,学员,培训时间,最后成绩'."\n"; fputs($fp, $this->expChangeCode($thead)); $row = array(1,'Mike','2013/12/01',90); $tbody = join(',', $row)."\n"; fputs($fp, $this->expChangeCode($tbody)); ob_flush(); flush(); } private function expChangeCode($str) { $str = iconv('UTF-8', 'gb18030//IGNORE', $str); return $str; } private function importScores($file){ $handle = fopen($file['tmp_name'],'r'); $this->checklines($handle); fclose($handle); } private function getline($handle) { if($line = fgetcsv($handle)) { /*此处如果用fgets(),当遇上csv表格里面有换行就有问题了*/ foreach ($line as &$v){ $v = iconv( 'gb18030//IGNORE', 'UTF-8', $v); } return $line; } else return false; } private function checklines($handle){ while($line = $this->getline($handle)){ var_dump($line); } } public function __construct(){ if($_REQUEST['action'] == 'export') { $this->export_term_user(); } elseif ($_REQUEST['action'] == 'import') { $this->import_term_user(); } } } new CSV_Import_Export();
相关文章推荐
- C++导入导出CSV文件
- PostgreSQL 导入和导出 CSV 文件
- 使用VBA导入导出csv文件
- MySql csv文件导入导出
- mysql导入导出csv文件
- 使用PHP导入和导出CSV文件
- php实现CSV文件导入和导出
- Laravel 5使用Laravel Excel实现Excel/CSV文件导入导出的功能详解 3ff8
- C++导入导出CSV文件
- Java对CSV文件加密后导入导出功能小结
- 使用PHP导入和导出CSV文件
- 在 Laravel 5 中使用 Laravel Excel 实现 Excel/CSV 文件导入导出功能
- java 实现csv文件导入导出
- [转]PL/SQL Developer 导入导出csv文件
- 用php导入10W条+ 级别的csv大文件数据到mysql。导出10W+级别数据到csv文件
- PHP批量导出导入CSV文件实现原码
- 使用PHP导入和导出CSV文件
- JAVA操作csv文件(导入导出)
- 在 Laravel 5 中使用 Laravel Excel 实现 Excel/CSV 文件导入导出功能
- 在 Laravel 5 中使用 Laravel Excel 实现 Excel/CSV 文件导入导出功能(转)