954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

append/write data from a text file into an excel sheet without using database

Hi all

I want to append a text file data to an already existing excel file.the text file will be of the following format:

BARCODE|TITLE|PRICE|CUSTOMER_FIRST_NAME|CUSTOMER_LAST_NAME|CITY|STATE|ZIP|PURCHASE DATE
111111868167|Dead North Friday Night OCT 10th |18.5|Amber|Follensbee|Windsor|VT|05089|08/07/08 11:30am
111111868177|Dead North Friday Night OCT 10th |18.5|Amber|Follensbee|Windsor|VT|05089|08/07/08 11:30am
111111868187|Dead North Friday Night OCT 10th |18.5|Amber|Follensbee|Windsor|VT|05089|08/07/08 11:30am
111111868197|Dead North Friday Night OCT 10th |18.5|Amber|Follensbee|Windsor|VT|05089|08/07/08 11:30am
111111868207|Dead North Friday Night OCT 10th |18.5|Amber|Follensbee|Windsor|VT|05089|08/07/08 11:30am
112120127382|Dead North Friday Night OCT 10th |25|Heather|Davio|St. Johnsbury|VT|05819|09/14/08 05:19pm


excel sheet will have same columns.

another problem is to change data or overwrite a cell value in excel sheet.

Please help me...it will be a graet help

thanks in advance
jyoti

jyotiu
Light Poster
33 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

I say you parse it into an array, then work with that, when you are finished just overwrite it.

<?
$columnheaders = explode("|", "BARCODE|TITLE|PRICE|CUSTOMER_FIRST_NAME|CUSTOMER_LAST_NAME|CITY|STATE|ZIP|PURCHASE DATE");
$excelfile = file("/path/to/tile.csv");
for($i = 0; $i < count($excelfile); $i++)
{
	$row = explode("|", $excelfile[$i]);
	foreach($columnheaders as $columnheader)
	{
		$excelfile[$i][$columnheader] = $row[0];
		array_shift($row);
	}
}

/*
The excel or csv file will be converted into this for each row

$excelfile = array(0=>array("BARCODE"=>"BARCODE", "TITLE"=>"TITLE", "PRICE"=>"PRICE", "CUSTOMER_FIRST_NAME"=>"CUSTOMER_FIRST_NAME", "CUSTOMER_LAST_NAME"=>"CUSTOMER_LAST_NAME", "CITY"=>"CITY", "STATE"=>"STATE", "ZIP"=>"ZIP", "PURCHASE DATE"=>"PURCHASE DATE"));
*/
?>


Then you can just use array functions to search through the array and you can overwrite different cells of the array and then when you are done just loop through it and overwrite the file.

I will even bet that if you are creative enough and you have the time on your hands that you can create a class that will parse standard select, update and insert statements so that when you do finally decide to move to a database, there won't be much effort involved

R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You