Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

You could probably fill every field with spaces till it was a predetermined size. But I guess that it would still depend on where you are opening the CSV file. Anyway, I don't think it's considered a good practice to do this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top