Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ถาม php กับ excel ตัวอย่างการ Export Excel to XML ตัวอย่างไฟล์ excel.xls นะครับ



 

ถาม php กับ excel ตัวอย่างการ Export Excel to XML ตัวอย่างไฟล์ excel.xls นะครับ

 



Topic : 031563



โพสกระทู้ ( 381 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook



ตัวอย่างไฟล์ excel.xls นะครับ
[img]http://spic.uploadd.com/2032/I75/small/152E8A1405MQKYF8[HL5VFNIS7LJ7Iexcel.jpg[/img]

Excel to XML
<?php

	function writeXML($xml)
	{
		$fp = fopen('ExcelToXML.xml', 'w+');
		fwrite($fp,$xml);
		fclose($fp);
	}

	//*** Get Document Path ***//
	$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
	$OpenFile = "excel.xls";
	
	//*** Create Exce.Application ***//
	$xlApp = new COM("Excel.Application");
	$xlBook = $xlApp->Workbooks->Open("$strPath/$OpenFile");
	$xlBook = $xlApp->Workbooks->Open(realpath($OpenFile));
	$xlSheet1 = $xlBook->Worksheets(1);	

	$xml = new DOMDocument( "1.0", "utf-8" );  // "Create" the XML document.

	$xml_root = $xml->createElement( "People" ); // Create Root Node.

	for($i=2;$i<=6;$i++)
	{
		$xml_person = $xml->createElement( "Person");  // สร้าง Node ของบุคคลแต่ละคน

		//ดึงข้อมูลจากไฟล์ Excel
		$xml_id = $xlSheet1->Cells->Item($i,1);
		$xml_name = $xlSheet1->Cells->Item($i,2);
		$xml_lastname = $xlSheet1->Cells->Item($i,3);
		$xml_address = $xlSheet1->Cells->Item($i,4);
		$xml_tel = $xlSheet1->Cells->Item($i,5);
		$xml_mail = $xlSheet1->Cells->Item($i,6);

		//Create Child  Node ของ Person
		$id = $xml->createElement("id",$xml_id);
		$name = $xml->createElement("name",$xml_name);
		$lastname = $xml->createElement("lastname",$xml_lastname);
		$address = $xml->createElement("address",$xml_address);
		$tel = $xml->createElement("tel",$xml_tel);
		$mail = $xml->createElement("mail",$xml_mail);

		// Append Child Node ของ Person
		$xml_person->appendChild( $id );
		$xml_person->appendChild( $name );
		$xml_person->appendChild( $lastname );
		$xml_person->appendChild( $address );
		$xml_person->appendChild( $tel );
		$xml_person->appendChild( $mail );

		// Append Person Node
		$xml_root->appendChild( $xml_person );
	}
	
	//*** Close & Quit ***//
	$xlApp->Application->Quit();
	$xlApp = null;
	$xlBook = null;
	$xlSheet1 = null;

	
	$xml->appendChild( $xml_root ); //Append Root Node
	$text = $xml->saveXML();	//Parse and Save the XML.

	// Write File XML
	writeXML($text); 
?>
Export Excel to XML


เป็นตัวอย่างละกันครับ เห็นหลายๆ ท่านโพสต้องการ Code
ตัวอย่างนี้เป็นการ Export ของ PHP5 นะครับ ซึ่งอยู่ใน extension ของ DOM/XML API

*หมายเหตุ Code บางส่วนผมตัดของคุณวินในบทความการ export excel to database มานะครับ
Link :: https://www.thaicreate.com/php/php-excel.application-read-xls.html



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-09-10 11:51:44 By : extenser View : 3030 Reply : 1
 

 

No. 1



โพสกระทู้ ( 381 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ตัวอย่างไฟล์ excel.xls นะครับ
Excel to XML






Date : 2009-09-10 11:55:11 By : extenser
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ถาม php กับ excel ตัวอย่างการ Export Excel to XML ตัวอย่างไฟล์ excel.xls นะครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่