Converting csv to excel PHP - php

I'm generating a csv file through JSON in my application. But when I open it, it's not formatted.
Is there any script available in PHP to convert from csv to Excel?
My output now is:
,"12","1","1","","","","","","","","","","0","0","0","0","0","","","0","","","","0","0","0"2121","0","","1","1","","","non","210,"0","0","0","0","07:00","","","0","","",

Just open the csv in Excel....
You should be all fine and dandy ^_^
No need to "convert" it.

Related

How to decode unicode text data back to excel file with or without php?

Hello I'm trying to convert the encoded text data back to excel file.
I have an excel file(.xlsx), when it is opened in notepad, it show encoded text data. And I'm getting the data in the encoded text which I need to convert back to excel file.
I have an excel- file which when I tried to open in notepad it looks like: (excel_file_txt.txt)
PK ! ¤Y€¼ h ¥ xl/worksheets/sheet1.xmlœ½[“ý¸qåû~>…
¢ßµE7Â!{bÔU¬[ĉs}î‘Ú–b$µCÝÏ|ûá®]õWe&2mIÑ’øC,®
XL ¿ý/ÿó/þÕÿøño?
ÿ駿þãwëmùîW?þõ÷?ýáOý—üîÿýŽ_ïßýêç_~øë~øóOýñ¿û_?
þüÝù§ÿã·ÿþÓßþûÏüñÇ_~užà¯?ÿãwüå—ý‡ßüæçßÿñÇ¿üðóí§ýñ¯'ùçŸþö—~9ÿïßþå7?
ÿëß~üáïAùóo¶e‰¿ùËúëwÏ3üÃß®œã§þç?ýþÇ—Ÿ~ÿoùñ¯¿<Oò·ÿüÃ/çåÿüÇ?
ýëÏßýÓoÿð§“=þž_ýíÇþÇïþëú#8÷Ýoþé·ïuÿúñßþò¿õËÿíÿþñÏ?þþ—ÿpÞï~õøÓþÛO?
ý÷,ç¡åú{¼_Öÿù·_ýáÇþáßþüËÿõÓ¿ßüÓ¿üñ—ó$áòûŸþüóû?õ—?ýõýÌùá>køÓ~ùã
£Ø-­Kv)<îñÿúóïð÷ÿöó/?ýåÿÿ(òq
I tried to save this text file as using SAVEAS excelfile.xlsx & encoding as "UNICODE" (I even tried other encodings like UTF-8, ANSII.).
But when opened in excel it shows as: (excel_file_txt_encode_save.xlsx)
However, the original excel files looks like: (excel_file.xlsx)
Can someone help me to get back the excel file from the encoded text data or another way to get it done.

PHP - How can I write data from a <table></table> to an excel file using file_put_contents()?

PHP - How can I write data from a <table></table> to an excel file using file_put_contents()?
You have 2 options:
save the spreadsheet as a CSV, then use PHP's built-in CSV functions:
http://php.net/manual/en/function.fgetcsv.php
or use external libraries:
http://phpexcel.codeplex.com/

Change font style with fputcsv

I need to change the text of header from lighter to bold of the csv . I am using fputcsv() of php to generate to csv file.
fputcsv($output,array('Report','Entitlement Report'));
This is the basic code which I am using to print the header of my csv file . Any idea to accomplish this or any example
Thanks in advance
You can't achieve this because CSV file doesn't support the font style.
PS: CSV file could be opened with Excel, but it is not Excel file format, doesn't support any style.
XLS / XLSX format supports visual styles.
List of libraries for xls reading/writing.
And PHPExcel, of course.

Sanitizing data in PHP for excell xml

I am currently using the "excel xml" PHP library (Marin Crnković, version 0.9) to write data from the database as an .xls file. The problem is that the database contains data that is not legal, and this causes Microsoft Excel to give me errors when opening this file. (The document cannot be opened because there are problems with the contents)
Samples of bad data that is causing Excel display errors instead of opening the file:
!(()&&!|||
'"()&%1prompt(918861)
'&cat /etc/passwd&'
'&dir&'
"&cat /etc/passwd&"
email&n921923=v950402
Is there a recommended function to sanitize the data before inserting the data into the Excel file?
It might be that you need to escape/encode the ampersands before using them for the Excel spreadsheets (as the new formats are XML-based). With PHP, you could perhaps try something like:
$value = str_replace('&', '&', $value);

is it possible to export data using php in iif format?

is it possible to export data in iif format using php? like we export data in csv or excel format?
Thanks
This answer suggests that IIF isn't supported any more but that there are libraries available to read/write similar formats.
Yes, you need to build a script that does this though.
See this page for the format you need to output.
Basically you would do something similar to this:
// Open the file for writing...
$fp = fopen("myiiffile.iif", "w");
//Loop through the records writing out the data in the proper format...
fwrite($fp, $inputstring);
//Close the file...
fclose($fp);

Categories