Opening CSV file - excel

I am generating CSV files. My first row it is column names, and it looks like
User ID;First Name;Last Name;Email;...
But if I will change User ID to ID, MS office cannot open this CSV and shows me error
Cannot read record(number of record)
But this file opens correctly on, Notepad++. I am using Excel 2013. Any ideas what is wrong?

You can solve the problem by inserting the following simple text at the beginning (the first line) of your .csv file:
sep=;
This will not be seen when the file is opened in Excel. What it will do - it will explicitly tell Excel that the delimiter is ;, and values will be separated into separate cells. Also, you will be able to use ID as the title of a column. Unfortunately, I cannot answer why Excel does not like it when you use this title at the beginning of the file.

Related

Microsoft Excel creating a tab delimeted file

So, in my software program I need a comma separated file. Hence, I created one using Microsoft excel entering the data. But, my software program gave error saying its not a comma separated. Hence, I just copy pasted some cell in notepad and it came out to be Tab separated.
Right now :
Owner Latitude Longitude LocationInfo
I want :
Owner,Latitude,Longitude,LocationInfo
Excel has its own special proprietary file format.
If you copy and past from an Excel sheet, what you get has no bearing on the format when you click save.
What you need to do is SaveAs and then in the popup where you can browse for a location and edit the file name, there is also a drop down (below the file name text box) where you can select various file extensions. When you pick one of those Excel will intelligently format your file for the chosen extension. Just find the one that is .csv (it may be called CSV).

Automatically convert csv file into Excel table?

I generate some csv files using a script. Next I manually convert those csv files into excel tables using the import wizard in excel based on:
https://www.youtube.com/watch?v=z5Pxil4jVO4
Is it possible to do this automatically - e.g. by calling an excel importer from command line - so I don't need to open excel and do all the manual work?
I can open the csv file directly in Excel but its not formatted as a table. E.g. this csv file:
a,b,c
a,b,c
results in this Excel sheet:
I would like each letter to be in a separate column.
I have looked at this:
https://social.technet.microsoft.com/Forums/windowsserver/en-US/370ee470-f2cd-4f30-a167-b106dd51d47a/powershell-convert-csv-to-xlsx?forum=winserverpowershell
but its an awful lot of boiler plate code from create a simple table.
Add an extra line to your CSV file to tell Excel what the seperator is. Add the following line to the top of your CSV file:
sep=,
The easiest way, without close and edit your file - you can choose which separator you want in Excel 2010-2016 go to DATA, Text To Columns, choose Delimited, then choose your separator Comma (or other) and you will see changes immediately in the "Data preview", then click FInish.
Once you have the format you wanted, you simply save the document and it will be permanent.

Outputting to CSV via .txt --looking for more elegant solution

I've recently written a few python scripts that count the number of words in a csv file and then print as output two columns: "Prefix" and "Count" where prefix is the first word in a name in a row and count is the sum of all occurences of that name.
My question is that if I try to output to a .csv file directly, everything gets put in one column and it doesn't look nice. However, if I output first to a .txt file, and then open that file in excel such that it asks me to make a space delimiter, it looks correct. I bet the answer is pretty basic, but I'm just wondering if there is a simpler way to do this than saving as a .txt and then re-opening as a .csv. Additionally, why can I open a new excel file and open the .txt file from there and it works, whereas if I try to just "open with" the .txt file directly into excel it does not work (and instead gives me the old result with everything in one column)?
Much thanks for any help you can provide!
EDIT:
Output looks like the following when I open the .txt file as a csv with the "open with" button:
Word Count
the 333
Family 54
When I open a new excel file and open the .txt file from there and use the delimiter options that come up before the file opens, it looks correctly like this:
Word, Count
the, 333
Family, 54
CSV = comma separated values
You need to output the data separated by comma and not space. You can save this as .csv and double-click to open in excel. Then the data appears in two columns.
Additionally, why can I open a new excel file and open the .txt file from there and it works, whereas if I try to just "open with" the .txt file directly into excel it does not work (and instead gives me the old result with everything in one column)
Same reason. If you open a .txt file in excel, it will just open as text. It doesn't know how to interpret this data (what goes into which columns). When you "open a new excel file and open the .txt file from there", you are "importing" the data and you tell excel to interpret the data as two columns with space as delimiter, so it works.
You can also open the .txt file directly in excel using "open with" and then use the "Text to Columns" feature to remodel the data in a spreadsheet-friendly way.

Excel and Tab Delimited Files Question

I am encountering what I believe to be a strange issue with Excel (in this case, Excel 2007, but maybe also Excel 2003, but don't have access to it as I write this).
I can reliably convert some server data over into a tab-delimited format (been doing this for years) and then open it using Excel - no issue.
However, what seems to be happening is if I have an html <table> inside one of the fields, it looks like Excel 2007 thinks it should be converting the table into rows and columns inside Excel (not what I want). As you might imagine, this throws off the entire spreadsheet.
So question is, is there any way to set up excel to NOT do this (perhaps some setting in Excel that pertains to reading tab delimited files), or am I missing something?
Thanks.
Save your file as .txt
Now open the file in excel using Drag and Drop (rather than double clicking your hookey .xls)
Slightly more work to open the file, but your tab text formatting will now be respected.
When you open the tab-delimited file, you are shown an import mapping dialog that lets you pick each columns' data type (date, text, currency, etc.). For the columns that have HTML data present, choose text. This will tell it basically to import as-is and not try to automatically parse the data into a derived format.
Excel 2003 does the same. I don't think there is a way to do it with a config because Excel finds delimiters in the html table and breaks the html in cells and columns as it does for the other columns.
If the column containing html is always the same, you can use JYelton suggestion of renaming the file as csv and record a small VBA macro to load the file selecting automatically the html column as text in the import mapping dialog and you load the file calling the macro instead of double-clicking on the file.
If nothing else, import it into OpenOffice.org Calc, save as an .xls file, then open in Excel.

import text file containing line breaks into excel

I have a plain text file looking like this:
"some
text
containing
line
breaks"
I'm trying to talk excel 2004 (Mac, v.11.5) into opening this file correctly. I'd expect to see only one cell (A1) containing all of the above (without the quotes)...
But alas, I can't make it happen, because Excel seems to insist on using the CR's as row delimiters, even if I set the text qualifier to double quote. I was sort of hoping that Excel would understand that those line breaks are part of the value - they are embedded in double quotes which should qualify them as part of the value. So my Excel sheet has 5 rows, which is not what I want.
I also tried this Applescript to no avail:
tell application "Microsoft Excel"
activate
open text file filename ¬
"Users:maximiliantyrtania:Desktop:linebreaks" data type delimited ¬
text qualifier text qualifier double quote ¬
field info {{1, text format}} ¬
origin Macintosh with tab
end tell
If I could tell Excel to use a row delimiter other than CR (or LF), well, I'd be a happy camper, but excel seems to allow the change of the field delimiter only, not the row delimiter.
Any pointers?
Thanks,
Max
Excel's open
Looks like I just found the solution myself. I need to save the initial file as ".csv". Excel honors the line breaks properly with CSV files. Opening those via applescript works as well.
Thanks again to those who responded.
Max
The other option is to create a macro to handle the opening. Open the file for input, and then read the text into the worksheet, parsing as you need, using a Range object.
If your file has columns separated by list separators (comma's, but semicolons for some non-English region settings), rename it to .csv and open it in Excel.
If your file has columns separated by TABs, rename it to .tab and open it in Excel.
Importing (instead of opening) a csv or tab file does not seem to understand line feeds in between text delimiters. :-(
Is it just one file? If so, don\'t import it. Just copy paste the content of your text file into the first cell (hit f2, then paste).
If you absolutely must script this, Excel actually uses only one of those two chars (cr, lf) as the row delimiter, but I'm not sure which. Try first stripping out the lf's with an external util (leave the cr's) and then import it... if that does't work, strip out the cr's (leave the lf's) and thenimport it.

Categories

Resources