|
 |
|
อยากเอา text file มาสร้างเป็นตารางใน excel ครับต้องทำยังไง |
|
 |
|
|
 |
 |
|
text file -> จัด format -> datatable -> excel
|
 |
 |
 |
 |
Date :
2014-10-25 09:20:12 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
require_once 'ClassExcel/PHPExcel.php';
include 'ClassExcel/PHPExcel/IOFactory.php';
include 'ClassExcel/PHPExcel/Writer/Excel2007.php';
$excel=new PHPExcel();
$excel->getProperties()->setCreator("Chaidhanan Pisalsenadhanachote");
$excel->getProperties()->setLastModifiedBy("Chaidhanan Pisalsenadhanachote");
$excel->getProperties()->setTitle("TextFile2XLSX");
$excel->getProperties()->setSubject("TextFile");
$excel->getProperties()->setDescription("Test convert TEXT File to Office 2007 XLSX, generated using PHPExcel classes.");
////////////////////////////////////////////////////////////////////////////////
$excel->setActiveSheetIndex(0);
////////////////////////////////////////////////////////////////////////////////
$ln=1;
$excel->getActiveSheet()->SetCellValue('A'.$ln, 'Sample');
$excel->getActiveSheet()->SetCellValue('B'.$ln, 'ID');
$excel->getActiveSheet()->SetCellValue('C'.$ln, 'Conc');
$excel->getActiveSheet()->SetCellValue('D'.$ln, '%RSC');
$excel->getActiveSheet()->SetCellValue('E'.$ln, 'ABS1');
$excel->getActiveSheet()->SetCellValue('F'.$ln, 'ABS2');
$excel->getActiveSheet()->SetCellValue('G'.$ln, 'ABS3');
$excel->getActiveSheet()->SetCellValue('H'.$ln, 'ABS4');
////////////////////////////////////////////////////////////////////////////////
$ln=2;
$eng=array(
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ'
);
$fl=file('text.txt');
foreach( $fl as $k=>$txt){
$ar_txt = explode(' ', $txt);
$j=0;
foreach($ar_txt as $k1=>$vl){
$excel->getActiveSheet()->SetCellValue($eng[j].$ln, $vl); $j++;
}
$ln++;
}
/////////////////////////////////////////////////////////////////////////////////
$excel->getActiveSheet()->setTitle('TEST');
$fileName = 'test_'.date('YmdHis').'.xlsx';
$objWriter = new PHPExcel_Writer_Excel2007($excel);
$objWriter->save($fileName);
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename=' . $fileName );
header('Content-Length: ' . filesize($fileName));
header('Content-Transfer-Encoding: binary');
ob_clean();
flush();
readfile($fileName);
unlink($fileName);
?>
พอดีมีตัวอย่างเอาไว้ เลยมาปรับให้นิดหน่อย
ส่วน format อะไรอยา่งไร ก็ดูเอาเองนะครับ ผมไม่เกียวแล้วนะครับ 5555555
|
 |
 |
 |
 |
Date :
2014-10-25 09:41:23 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับตอนนี้ผมติดที่ว่าผมจะแยก
ค่าแต่ละแถวออกจากกันยังไงอย่าง
Zn0.50 mg/L 0.517 mg/L 0.4 0.3281 0.0125 0.3268 0.3278 0.3275
0.3301
คืออยากให้เรียงเป็น
Zn0.50 0.517 0.4 0.3268 0.3278 0.3275 0.3301
ต้องแยกยังไงครับ
|
 |
 |
 |
 |
Date :
2014-10-25 10:15:06 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ปกติ text file ถ้าเป็นคอลัมแล้วพอก๊อบไปวางใน excel ก็จะแยกคอลัมให้เลยครับ
แต่ไฟล์นี้พอก๊อบไปวางใน excel มันไม่แยกเป็นคอลัมให้ก็เลยต้องมาทำเอง
|
 |
 |
 |
 |
Date :
2014-10-25 10:21:56 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2014-10-26 17:25:48 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|