40 18 | Though I try to avoid it, I occasionally have to open a CSV file in Excel. When I do, it formats columns containing numbers, which makes them useless for my purposes. As far as I can tell, the only way to prevent this from happening on import is to rename the file so the extension isn't .csv and use the import wizard to specify the format of each column individually. For files with 50-60 columns, this is impractical. Since every answer for this oft-asked question on the internet suggests either some means of converting the formatted numbers back once the file is open (which won't work for me - I want to solve the general problem, not a few specific cases) or manually selecting the format type of each column (which I don't want to do), I'm looking for a way to set a global preference or style such that all columns of all CSV files opened are always formatted as text. I know about "armoring" the numbers with quotes, too, but the files I get don't come like that and I was hoping to avoid having to pre-process the files so Excel doesn't screw them up. Is there a way to do specifically this: Always format all columns in opened CSV files as text, without manually selecting each column every time during import? I'm using Excel 2003, but I'll take answers for 2007 if that's what you know. | ||||
migrated from stackoverflow.com Jul 7 '11 at 6:21This question came from our site for professional and enthusiast programmers. | |||||
|
7 | This works:
Usage:
Comma-separated file is now open as Excel sheet with all columns formatted as text. Note that @Wetmelon's wizard solution works just fine, but if you're opening many files then you may, like me, grow weary of, each time, scrolling to column 60 in order to Shift-Click it. EDIT @GSerg claims in the comment below that this "doesn't work" and "eats spaces and leading zeroes". I'll just quote the comment to the question, which is more descriptive:
So the code above "works", but gets killed by this ridiculous Excel behaviour. Whichever way you cut it, you're stuck having to change the extension to something other than ".csv", sorry! After that, you're home free. | ||||||||||||||||||||
|
39 | How to open CSVs in ExcelBest way
Worst way
Best way (for VBA)
Worst way (for VBA)
Additional methods
Excel Add-In to open CSVs and import all values as textThis is a Excel Plug-in (Import CSV) to simplify CSV Import actions.
Installation
PowerShell script to open CSVs direct from Windows ExplorerUse a Powershell script to open a CSV with a Double-Click from within the Windows Explorer and preserve all values as text in Excel. This method is also available for Windows XP if you install Powershell manually.
Voila, from now on every time you double click a CSV it will be opened by Excel and all values are still formatted as text. How does the script work?
|
'상식과 지식' 카테고리의 다른 글
은퇴에 대한 인식 & 은퇴 번복 (0) | 2016.03.31 |
---|---|
고령화 사회로 인한 은퇴 연령의 문제 (0) | 2016.03.31 |
액셀(Excel)에서 CSV 파일을 정상적으로 불러오기 (0) | 2016.03.28 |
지카바이러스의 음모론 (0) | 2016.03.22 |
지카바이러스로인한 국가적 손해 (0) | 2016.03.22 |