I am trying to export my MySQL db to Excel. I wrote a PHP script to format a txt file as:
$res = mysql_query("select Data1, Data2 FROM my Table");
while ($row = mysql_fetch_assoc($res)) {
// Remove tabs chars
$row["Data1"] = str_replace("\t","", $row["Data1"]);
$row["Data2"] = str_replace("\t","", $row["Data2"]);
// Output to file
echo "\"" . $row["Data1"] . "\" \t \"" . $row["Data2"] . "\"\n";
}
I copy the output and save it as a txt file, which I then import to Excel using "tab" as the delimiter.
However, since both Data1
and Data2
fields contain newlines chars it seems like Excel treats it like a new cell instead of creating a new line in the current cell.
Anyway I can import the file so both fields will have new lines and still be on one cell?
EDIT: Even when trying to import this simple text file:
"hello","bye
now"
Excel creates a row with two columns: "hello" , "bye" - and then a new row with "now"
Thanks!
Joel