473,408 Members | 2,734 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,408 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 6996
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 =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.