i have data from a csv file. One Column contains Text like "0.2.11" which i need to reformat to "00.02.0011", the leading zeroes and the length of the dot seperated parts are crucial. These are no dates, just random Numbers. How can i reformat those?
Thanks.
I know that this is an insanely long formula, but I believe it will do what you're looking for:
=IF(LEN(IF(ISERR(FIND(".",A1)),A1,LEFT(A1,FIND(".",A1)-1)))=2,IF(ISERR(FIND(".",A1)),A1,LEFT(A1,FIND(".",A1)-1)),"0"&IF(ISERR(FIND(".",A1)),A1,LEFT(A1,FIND(".",A1)-1)))&"."&IF(RIGHT(MID(A1,FIND(".",A1)+1,2))<>".",MID(A1,FIND(".",A1)+1,2),"0"&LEFT(MID(A1,FIND(".",A1)+1,2),1))&"."&IF(LEN(RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))))=4,RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))),IF(LEN(RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))))=3,"0"&RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))),IF(LEN(RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))))=2,"00"&RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))),"000"&RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))))))
It's probably long enough that you'd have to save this in one of the new Excel formats like .xlsx or .xlsm for it to save. If you have trouble with it let me know, I also have the formula broken out into several cells (or steps) if you need it that way.
There is a shorter (but still ugly) Excel formula using TEXT function for formatting:
=TEXT(MID(A1,1,FIND(".",A1)-1),"00") &"."& TEXT(MID(A1,FIND(".",A1)+1,FIND(".",A1,FIND(".",A1)+1)-FIND(".",A1)-1),"00") &"."& TEXT(RIGHT(A1,LEN(A1)-FIND(".",A1,FIND(".",A1)+1)),"0000")
I would like to point out there are other methods of solving the same problem. If you have lots of big csv files you might consider preprocessing before importing into Excel. For example, doing the same job in awk is trivial:
BEGIN {
while(getline < "e.csv") {
split($1,a,".");
printf("%02d.%02d.%04d\n",a[1],a[2],a[3]);
}
}
Gawk works well with Windows. After installing, you can run it on the Windows or PowerShell command line as .\awk -f x.awk where x.awk is the above code in a text file.
Related
I used python to write some text to csv but it is stored in funny format.
output data is saved here:example data
for example, it is read as the below in csv excel
text shown in CSV
when i copy it to other platforms(notepad, word, web application) it turns into something else
after copy
I tried a numerous method include formatting with the CSV but it just wont work.
Could someone please help me.
With thanks,
Iverson
It's hard to guess what you mean...
Your file has TABs between many characters. But every line starts and ends in a double quote ("). So the whole line is one value (cell).
i am exporting data from database to file, which can Excel read and save.
(CSV) I generate csv, with default format (according to RFC 4180, comma delimeter). As expected, stupid excel read all data and place it to one cell.
(CSV with semicolon delimeter), this one excel read fine, but after change some value and press save (CTRL+S), stupid excel saved it to unreadable file (well done!). No delimeters, no string separators. Ok, so i tried to save it as (CSV format with SEMICOLON delimeter), saved file looks ok, but after opening it with excel, error message was showed - INCORRECT FORMAT - no cell found :D really?!
Generating .xsl file in php. It take too much RAM (about 2GB), so it cant be used.
Do you know any good format, which can excel easily open and easily save?
Thanks a lot!
This question is off-topic, but IMHO Excel 2002/2003 XML Format would be the best choice in your circumstances.
The reason for this is that the data in this format is typed - so you will not see numbers misinterpreted as dates, or phone numbers with leading zeros stripped. I am not aware of the kind of problems you describe, so I cannot say for sure how those will be affected.
I have a single Excel containing many sheets as sheet1, sheet2, sheet3, etc. I need to split this Excel into individual CSVs, i.e.
sheet1--->file1.csv
sheet2-->file2.csv
sheet3-->file3.csv
and so
on...
I need to do this either using PERL or UNIX. I also want to know the record count from each of the individually generated CSVs.
Since I am a beginner in Unix, I spent much time in writing the code and it doesn't seem working.
Please give your suggestions. Thanks in advance.
I was facing the same issue, I guess this post (link) should help you.Batch split xls sheets to csv -
This contains a js code which you just have to put inside the folder where you have all the xls files.It will split the sheets into separate csv and name them following this syntax: {file_name}-{worksheet_name}.csv
Hope this helps.
You can either use the csvkit program:
in2csv --write-sheets "-" -f Masterfile.xlsx
which will generate as many files as they are sheets
Masterfile_0.csv Masterfile_1.csv ...
or you can also use the ssconvert tool from the Gnumeric project:
ssconvert -S Masterfile.xlsx split_file.csv
but the naming scheme is less convenient as each file have the sheet number prepended (they need to be renamed):
split_file.csv.0 split_file.csv.1
After running a model in fortran (95) I end up with some result arrays (and one result matrix). I'd like to move these into excel for reporting purposes. What's the easiest way to do this?
As S. Lott said before me, CSV format is probably the best choice, but actually Excel is pretty clever about file formats. It will usually work with tab separated or space separated data, or even HTML tables. Try copy-and-pasting your data into Excel to see whether it can work it out, before worrying too much about the format.
Fix your Fortran output to be in CSV format. This is easily imported into a spreadsheet.
You can also write your data into a text file with the below code and then copy paste its contents to excel
before working with these data you must run "paste special wizard" to separate columns of the data in the excel
dimension a(100)
open (25,'output.txt')
do i=1,100
write(25,*) a(i)
end do
I have been trying to import this excel file my mysql database, and it has been rough.
There are around 7,000 rows in the .xls file, but when I export it to .csv and parse it with PHP I get one of two issues:
Excel does not escape anything, ie. the commas in each row split the data
When I change all commas to * then export for some reason excel changes a whole bunch of lines to a bunch of pound signs #####.
(Is there a reason it does this?)
I can upload the .xls somewhere if need be.
As a suggestion, if you are dealing with cells that do contain commas which are widespread, an easy solution would be to export from Excel in a Tab-Delimited format (TXT), or yet alone any format that contains a character you would not normally encounter.
I've found it to be a pretty simple way to take care of many of the troubles associated with exporting from Excel and importing into a database medium.
Figured it out!
Turns out it was Excel's fault. I checked the .xls before opening it in Excel, not ###.
But after saving it in Excel they appeared.
So I opened it in Numbers (part of iWork), changed all , to *, and all quotes to % (these never appeared in any line. Exported it to .csv, then changed them back when importing with PHP.
Worked great. :-)