Stop Excel from automatically converting certain text values to dates

前端 未结 30 2602
别跟我提以往
别跟我提以往 2020-11-22 04:16

Does anyone happen to know if there is a token I can add to my csv for a certain field so Excel doesn\'t try to convert it to a date?

I\'m trying to write a .csv fil

相关标签:
30条回答
  • 2020-11-22 05:10

    2018

    The only proper solution that worked for me (and also without modifying the CSV).

    Excel 2010:

    1. Create new workbook
    2. Data > From Text > Select your CSV file
    3. In the popup, choose "Delimited" radio button, then click "Next >"
    4. Delimiters checkboxes: tick only "Comma" and uncheck the other options, then click "Next >"
    5. In the "Data preview", scroll to the far right, then hold shift and click on the last column (this will select all columns). Now in the "Column data format" select the radio button "Text", then click "Finish".

    Excel office365: (client version)

    1. Create new workbook
    2. Data > From Text/CSV > Select your CSV file
    3. Data type detection > do not detect

    Note: Excel office365 (web version), as I'm writing this, you will not be able to do that.

    0 讨论(0)
  • 2020-11-22 05:10

    This issue is still present in Mac Office 2011 and Office 2013, I cannot prevent it happening. It seems such a basic thing.

    In my case I had values such as "1 - 2" & "7 - 12" within the CSV enclosed correctly within inverted commas, this automatically converts to a date within excel, if you try subsequently convert it to just plain text you would get a number representation of the date such as 43768. Additionally it reformats large numbers found in barcodes and EAN numbers to 123E+ numbers again which cannot be converted back.

    I have found that Google Drive's Google Sheets doesnt convert the numbers to dates. The barcodes do have commas in them every 3 characters but these are easily removed. It handles CSVs really well especially when dealing with MAC / Windows CSVs.

    Might save someone sometime.

    0 讨论(0)
  • 2020-11-22 05:12

    What I have done for this same problem was to add the following before each csv value: "=""" and one double quote after each CSV value, before opening the file in Excel. Take the following values for example:

    012345,00198475
    

    These should be altered before opening in Excel to:

    "="""012345","="""00198475"
    

    After you do this, every cell value appears as a formula in Excel and so won't be formatted as a number, date, etc. For example, a value of 012345 appears as:

    ="012345"
    
    0 讨论(0)
  • 2020-11-22 05:15

    None of the solutions offered here is a good solution. It may work for individual cases, but only if you're in control of the final display. Take my example: my work produces list of products they sell to retail. This is in CSV format and contain part-codes, some of them start with zero's, set by manufacturers (not under our control). Take away the leading zeroes and you may actually match another product. Retail customers want the list in CSV format because of back-end processing programs, that are also out of our control and different per customer, so we cannot change the format of the CSV files. No prefixed'=', nor added tabs. The data in the raw CSV files is correct; it's when customers open those files in Excel the problems start. And many customers are not really computer savvy. They can just about open and save an email attachment. We are thinking of providing the data in two slightly different formats: one as Excel Friendly (using the options suggested above by adding a TAB, the other one as the 'master'. But this may be wishful thinking as some customers will not understand why we need to do this. Meanwhile we continue to keep explaining why they sometimes see 'wrong' data in their spreadsheets. Until Microsoft makes a proper change I see no proper resolution to this, as long as one has no control over how end-users use the files.

    0 讨论(0)
  • 2020-11-22 05:15

    I have jus this week come across this convention, which seems to be an excellent approach, but I cannot find it referenced anywhere. Is anyone familiar with it? Can you cite a source for it? I have not looked for hours and hours but am hoping someone will recognize this approach.

    Example 1: =("012345678905") displays as 012345678905

    Example 2: =("1954-12-12") displays as 1954-12-12, not 12/12/1954.

    0 讨论(0)
  • 2020-11-22 05:16

    An alternate method:

    Convert the format of the column you want to change to 'Text'. Select all the cells you want to preserve, copy. Without deselecting those columns, click "Edit > Paste Special > As values"

    Save as CSV. Note that this has to be the last thing you do to the file because when you reopen it, it will format itself as dates since cell formats cannot be saved in CSV files.

    0 讨论(0)
提交回复
热议问题