473,779 Members | 2,089 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=produc tion_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 7024
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=produc tion_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=produc tion_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=produc tion_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,stri pslashes("$name ;"));
fwrite($fp,stri pslashes("$addr ess;"));
fwrite($fp,stri pslashes("$city ;"));
fwrite($fp,stri pslashes("$stat e;\n"));
fclose($fp);
}
?>

Then Excel should have no problem handling it.
Jul 17 '05 #4
JDJones <se******@spryn et.com> wrote in message news:<Ddd%b.406 368$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=produc tion_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,stri pslashes("$name ;"));
fwrite($fp,stri pslashes("$addr ess;"));
fwrite($fp,stri pslashes("$city ;"));
fwrite($fp,stri pslashes("$stat e;\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.c o.nz> wrote in message
news:c7******** *************** ***@posting.goo gle.com...
JDJones <se******@spryn et.com> wrote in message

news:<Ddd%b.406 368$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=produc tion_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,stri pslashes("$name ;"));
fwrite($fp,stri pslashes("$addr ess;"));
fwrite($fp,stri pslashes("$city ;"));
fwrite($fp,stri pslashes("$stat e;\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
3387
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 ways to read and write Excel files with ADO, but as far as I can tell, it doesn't provide the flexibility I need. I need to be able to generate tabs, cell formatting, formulas, etc.
9
8900
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 this out of an XML file or Excel Template file. Next I need to convert a dataset to xml and try and transform this data into the users xml file..........i've seen a few things on this but havent had much success...
17
27285
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 machine (NT4, Access 2k), however as soon as I attempt to create anything on another machine (NT4, Access 2k) which most users will be working from, I receive an automation error. The problem line with the code is:
3
1862
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 inside a .NET program? Thanks, Ali
1
1479
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 .Net. I dimension objExcel as a new excel application, but when I type .sheets my only option is 'Get Type'. I have tried several combinations but I hit a wall everytime. Any help will be appreciated. Thanks Jack
2
2186
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 = objExcel.ActiveWorkbook.ActiveSheet The problem is that every time I need to export, it results in creating
7
2701
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 excel formulas in the excel download, for example a running total on a column, thanks. -- Paul G Software engineer.
1
1620
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 client machine already have excel.so how i can remove Excel.exe while creating setup. pls help me out
1
1655
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 = $Excel->Workbooks->Open("c:/file_excel.xls"); my $Sheet = $Book; I am new to perl.I am trying to create an excel file with the above code, but i am not getting it.Can you help in creating an excel file.
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10139
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9931
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.