Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 5th, 2002, 11:40 AM
dave981 dave981 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: Minneapolis, MN
Posts: 48 dave981 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 53 sec
Reputation Power: 9
Send a message via ICQ to dave981
Unhappy CSV File Export Gets distorted by Excel

This question didn't really fit in any other forum thread in particular, but I'm sure other people have probably encountered this (and may not even know it), with Excel and other SpreedSheet applications.

I have an app that allows users to export a report of products that they have ordered.

Some products have unique identifiers of the form:

01-06
02-2005
etc.

The problem that I am encountering is that when this information is exported to a CSV it shows up as:
"01-06"
"02-2005"
etc.

Now, when you Import this information into Excel, it likes to convert this information to:
6-Jan
Feb 2005

If i try to convert these cells back to just Text, i end up with:
37262.00
38384.00

The number of days since Jan. 1st 1900 (I _think_)

Does anyone have any ideas how to prevent this from happening?

Is there a way to turn off AUto Formatting in Excel?
Is there an Escape Character to use in a CSV file to force the Spreedsheet application to recognize data as text only?

Thanks,
Dave

Reply With Quote
  #2  
Old August 5th, 2002, 01:48 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
not sure if this is also true for CSV, but excel uses the apostroph (') as fist character for marking text fields...
give it a try and post the results here, plz.
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #3  
Old August 5th, 2002, 02:37 PM
dave981 dave981 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: Minneapolis, MN
Posts: 48 dave981 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 53 sec
Reputation Power: 9
Send a message via ICQ to dave981
If i place single quotes around the items that Excel is misformatting, like follows:

"Order ID","Line Item No.","Product ID","Ship To Identifier","Cost Center","Extended Price",
"ciu-JoAnn","0",'01-26',"Sault Saint Marie-CIU","CIU","$3.46",
"ciu-JoAnn","1",'09-08',"Sault Saint Marie-CIU","CIU","$11.92",

the cell then shows up in Excel w/ the single ' contained within, on both sides of the data:
'01-26'
'09-08'

If i instead do this:

"'09-08" (Note the single quote inside the double quotes)

then recieve '09-08 in the cell, but if i double click within the cell, and press enter, then the cell is formatted correctly.

It seems as though there should be some way in order to get Excel 2000 to _not_ perform its auto formatting to dates. (If anyone can tell me the steps to disable this feature I would appreciate it).

Dave

Reply With Quote
  #4  
Old August 5th, 2002, 04:37 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
i donīt know of an easy solution. a workaround:
- either make a macro that you run after importing to remove the '
- or import using VBA instead. this will work 100%

Reply With Quote
  #5  
Old August 5th, 2002, 11:18 PM
Ctb's Avatar
Ctb Ctb is offline
An Ominous Coward
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Jan 2002
Posts: 4,425 Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 10 h
Reputation Power: 0
I've had similar problems with Excel's auto-formatting and had to do macros (I hate macros). Isn't it amazing how the more someone tries to make things easier, the harder things get?

Reply With Quote
  #6  
Old August 6th, 2002, 06:14 AM
ghatzhat ghatzhat is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 361 ghatzhat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 5 sec
Reputation Power: 7
another (poor) work around...

export as .txt, then open with excel... you get to choose the delimiter and then on the final screen you can select columns and decree their data type - choose text and your examples come out okay.

this might help you if you're doing a one-off export, however, it doesn't sound user-friendly enough for your situation... thought i'd contribute anyway...
__________________
Little more than a playground for the bugs that live beneath us...

Reply With Quote
  #7  
Old April 3rd, 2003, 10:43 AM
RussellCurtis RussellCurtis is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 1 RussellCurtis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
MS really does make it difficult!!

Came across this (amongst others) when trying to do something similar myself.

Put an equals sign at the front of the field and MS appears to present the data 'as-is' (in most cases!)

i.e.
"colA text","717-213",="717-213"

column A is text so that's ok
column B gets calculated (u do the maths) - cheers excel!
column C is as is (at last)

enjoy,

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > CSV File Export Gets distorted by Excel


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway