magicianiam
magicianiam

Reputation: 1579

convert .xls to tab delimited text file using php

is it possible to convert excel file to tab delimited text file using php?

is this even possible? if not then thank you for your time :)

I am exporting a CSV or excel file file and want tp convert it to tab delimited text file to be uploaded to google merchant. since manually converting it might be time consuming.

Upvotes: 0

Views: 5647

Answers (2)

Mark Baker
Mark Baker

Reputation: 212412

require_once 'PHPExcel/IOFactory.php';
$objPHPExcel = PHPExcel_IOFactory::load("myExcelFile.xlsx");

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
$objWriter->setDelimiter("\t");
$objWriter->save('myOutputFile.csv');

Upvotes: 5

Steve
Steve

Reputation: 1963

Am I right thinking that a tab delimited text file is identical to CSV just with tabs in place of commas?

If so...

If there are no commas within your data, they are only separating the values, then a simple string replace should do it for you.

$tab_delimited = str_replace(",", "\t", $csv_text);

Otherwise preg_replace will be able to help you.

Upvotes: 1

Related Questions