473,219 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,219 software developers and data experts.

Creating Excel CSV

Hi

I am trying to create a MS Excel format CSV but I can't figure out how
to get the line feed/carriage return/new record working properly.

I am nding each line/record with these characters: "\r\n" but the
Excel file just loads all the field in one row as if it doesn't
recognise these characters.

These are the headers I am using to create the file:

header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment;
filename=production_boards.csv");
header("Pragma: no-cache");
header("Expires: 0");

Any ideas why the file won't open properly in Excel?

Thanks

Jeremy
Jul 17 '05 #1
6 6989
I'm not sure how CSV's are supposed to be formatted, but you could
always try to each of the following till something works:
"\r\n"
"\r"
"\n"

If nothing works it'd be safe to say that at least that isn't the problem

--Jeff

Jeremy Langworthy wrote:
Hi

I am trying to create a MS Excel format CSV but I can't figure out how
to get the line feed/carriage return/new record working properly.

I am nding each line/record with these characters: "\r\n" but the
Excel file just loads all the field in one row as if it doesn't
recognise these characters.

These are the headers I am using to create the file:

header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment;
filename=production_boards.csv");
header("Pragma: no-cache");
header("Expires: 0");

Any ideas why the file won't open properly in Excel?

Thanks

Jeremy


Jul 17 '05 #2
oops, throw "\n\r" in there too
Jeff Smick wrote:
I'm not sure how CSV's are supposed to be formatted, but you could
always try to each of the following till something works:
"\r\n"
"\r"
"\n"

If nothing works it'd be safe to say that at least that isn't the problem

--Jeff

Jeremy Langworthy wrote:
Hi

I am trying to create a MS Excel format CSV but I can't figure out how
to get the line feed/carriage return/new record working properly.

I am nding each line/record with these characters: "\r\n" but the
Excel file just loads all the field in one row as if it doesn't
recognise these characters.

These are the headers I am using to create the file:

header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment;
filename=production_boards.csv");
header("Pragma: no-cache");
header("Expires: 0");

Any ideas why the file won't open properly in Excel?

Thanks

Jeremy


Jul 17 '05 #3
Jeremy Langworthy wrote:
Hi

I am trying to create a MS Excel format CSV but I can't figure out how
to get the line feed/carriage return/new record working properly.

I am nding each line/record with these characters: "\r\n" but the
Excel file just loads all the field in one row as if it doesn't
recognise these characters.

These are the headers I am using to create the file:

header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment;
filename=production_boards.csv");
header("Pragma: no-cache");
header("Expires: 0");

Any ideas why the file won't open properly in Excel?


If the file loads in Excel, then it's not your headers. How are you
getting the data for each line? Do you have the field delimiter after
each item (comma, sem-colon, or whatever you are using)?

If your are using fwrite with a semi-colon for a delimiter, it should
look something like this:

<?php
$fp = fopen("csv.txt", "a");
fwrite($fp,stripslashes("$name;"));
fwrite($fp,stripslashes("$address;"));
fwrite($fp,stripslashes("$city;"));
fwrite($fp,stripslashes("$state;\n"));
fclose($fp);
}
?>

Then Excel should have no problem handling it.
Jul 17 '05 #4
JDJones <se******@sprynet.com> wrote in message news:<Ddd%b.406368$xy6.2317200@attbi_s02>...
Jeremy Langworthy wrote:
Hi

I am trying to create a MS Excel format CSV but I can't figure out how
to get the line feed/carriage return/new record working properly.

I am nding each line/record with these characters: "\r\n" but the
Excel file just loads all the field in one row as if it doesn't
recognise these characters.

These are the headers I am using to create the file:

header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment;
filename=production_boards.csv");
header("Pragma: no-cache");
header("Expires: 0");

Any ideas why the file won't open properly in Excel?


If the file loads in Excel, then it's not your headers. How are you
getting the data for each line? Do you have the field delimiter after
each item (comma, sem-colon, or whatever you are using)?

If your are using fwrite with a semi-colon for a delimiter, it should
look something like this:

<?php
$fp = fopen("csv.txt", "a");
fwrite($fp,stripslashes("$name;"));
fwrite($fp,stripslashes("$address;"));
fwrite($fp,stripslashes("$city;"));
fwrite($fp,stripslashes("$state;\n"));
fclose($fp);
}
?>

Then Excel should have no problem handling it.


Thanks JD but I think the problem is a delimiter one. I have tried
every combination of \n and \r and nothing seems to work. Is there
another way I should be delimiting the records so that Excel can read
them?

Thanks Guys
Jul 17 '05 #5
"Jeremy Langworthy" <gr****@8legs.co.nz> wrote in message
news:c7**************************@posting.google.c om...
JDJones <se******@sprynet.com> wrote in message

news:<Ddd%b.406368$xy6.2317200@attbi_s02>...
Jeremy Langworthy wrote:
Hi

I am trying to create a MS Excel format CSV but I can't figure out how
to get the line feed/carriage return/new record working properly.

I am nding each line/record with these characters: "\r\n" but the
Excel file just loads all the field in one row as if it doesn't
recognise these characters.

These are the headers I am using to create the file:

header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment;
filename=production_boards.csv");
header("Pragma: no-cache");
header("Expires: 0");

Any ideas why the file won't open properly in Excel?


If the file loads in Excel, then it's not your headers. How are you
getting the data for each line? Do you have the field delimiter after
each item (comma, sem-colon, or whatever you are using)?

If your are using fwrite with a semi-colon for a delimiter, it should
look something like this:

<?php
$fp = fopen("csv.txt", "a");
fwrite($fp,stripslashes("$name;"));
fwrite($fp,stripslashes("$address;"));
fwrite($fp,stripslashes("$city;"));
fwrite($fp,stripslashes("$state;\n"));
fclose($fp);
}
?>

Then Excel should have no problem handling it.


Thanks JD but I think the problem is a delimiter one. I have tried
every combination of \n and \r and nothing seems to work. Is there
another way I should be delimiting the records so that Excel can read
them?

Thanks Guys


Jeremy,

Try posting the code you are using to create the .csv file, so we can see if
there is a gotcha in how it is being written.

Also, What o/s are you creating the file under - Windoze, Linux, Unix, OsX
....?

Finally, exactly how is the file getting from the place where it is created
to the innards of Excel? Are you creating it in-situ where it will be opened
by Excel, or are you doing an FTP or similar to move it from producer
directory to consumer directory?

It sounds like a file conversion issue, but we need to know more about the
environment.

Cheers,
Doug
--
Remove the blots from my address to reply
Jul 17 '05 #6
Jeremy Langworthy wrote:
I am trying to create a MS Excel format CSV but I can't figure out how
to get the line feed/carriage return/new record working properly.

I am nding each line/record with these characters: "\r\n" but the
Excel file just loads all the field in one row as if it doesn't
recognise these characters.
(...)
Any ideas why the file won't open properly in Excel?


Excel always does that when You directly open a csv file which does not
have a schema.ini.

Open Excel first, then open the csv file via the open dialog -- bingo.

Rudi
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Guy Incognito | last post by:
Hello, I've written an asp.net application that creates Excel documents. It works by creating an excel document in XML format. But I wonder if I'm reinventing the wheel. I know that there are...
9
by: Paul | last post by:
Hi all Arggghhh........... The problem.....I want the user to be able to create an excel document and name particular cells in the document where they want the data to be placed and then save...
17
by: Ange T | last post by:
Hi there, I'm having pain with the VB behind an Access form. The form is used to create reports in Excel based on the details entered in the form. This has always worked without error on my...
3
by: A.M | last post by:
Hi, Using ASP.NET/VB.NET and SQL Server backend, I need to return calculation results to user as an Access MDB file or Excel XLS sheet. What would be the best way to create a MDB or XLS file...
1
by: Jack M | last post by:
I am creating an excel spreadsheet from a data grid, there are more than 255 columns (approx 660), and so I need to create threee tabs or sheets. I have done this in VB6 but could use some help in...
2
by: leeedw | last post by:
Hi everyone, I use the following code whenever I export to Excel from VB.NET objExcel = New Excel.Application() objWorkBooks = objExcel.Workbooks objWorkBook = objWorkBooks.Add objWorkSheet...
7
by: Paul | last post by:
Hi I have created an excel file download feature within a .net application using Microsoft Office XP primary interop assembly for excel. I was just wondering if anyone knows if you can also embed...
1
by: vijay | last post by:
HI all, I have done a C#.net windows application and used Microsoft Excel 11.0 object library.My problem is while creating setup of my project it include Excel.exe which has big size.But...
1
by: amarnathreddy | last post by:
#!/usr/bin/perl -w use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; my $Excel = Win32::OLE->new('Excel.Application', 'Quit'); my $Book =...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.