Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSV resize columns depending on the content

I wonder if it is possible to set the size of columns based on the content they contain. I would like when you open the CSV once it has been directly generate columns are the right size.

For write in the CSV I have this code :

$csvFile = fopen(CSV_FILE, $writeMode);
            $searchStr = array(";");
            $replaceStr = array(",");
            foreach ($csvArray as $csvArrayRow) {
                fwrite($csvFile, iconv("UTF-8", "Windows-1252",str_replace($searchStr, $replaceStr, html_entity_decode($csvArrayRow["title"], ENT_HTML401 | ENT_QUOTES, "UTF-8")).";"));
                fwrite($csvFile, iconv("UTF-8", "Windows-1252",str_replace($searchStr, $replaceStr, html_entity_decode($csvArrayRow["author"], ENT_HTML401 | ENT_QUOTES, "UTF-8")).";"));
                fwrite($csvFile, $csvArrayRow["date"].";"."\n");
            }
            fclose($csvFile);

            echo json_encode(array(count($csvArray)));

            exit;

It is possible to add something to resize columns or is it somewhere else?

like image 970
mortiped Avatar asked Jan 29 '14 10:01

mortiped


1 Answers

CSV files do not contain any information about column width at all, which is why even if you open a file, set the column width and then save it as a CSV file, the next time you open them it won't have saved the width you set it to. So no, you can't set the width of the column for when they open.

like image 183
Styphon Avatar answered Sep 19 '22 13:09

Styphon