Thursday 26 October 2017

microsoft excel - Transform Fixed Width to CSV?


I have a whole bunch of data files with different content but identical layout. I need to convert them to CSV before importing them into a CRM application.


I usually open the tab-delimited file in Excel, which prompts me to manually define the tab stops using the Text Import Wizard. Once I have the file opened I convert it to CSV.


Problem is I have a bunch of these files (say 20-30) and Excel doesn't remember what one does in the Text Import Wizard and for reasons too lengthy to explain here I can't just combine them all into one mass file - even though the data structure is identical.


I'm wondering if there is a program or process out there that will allow me to save a "template" of the data file structure, and then apply it against each file so I don't have to recreate it manually?



Answer



For this I would normally use a batch process in a scripting language


For example, this is AutoIt:


$getfile = FileOpenDialog("Choose a file",@ScriptDir, "*.tsv",7)
If StringInSTr($getfile,"|") = 0 Then
$split = StringSplit($getfile,"|")
For $i = 2 to $split[0]
$file = FileOpen($split[$i])
StringReplace($split[$i],@TAB,",")
FileClose($split[$i])
Next
Else
$file = FileOpen($getfile)
StringReplace($file,@TAB,",")
FileClose($file)
EndIf

This would be just as easy in VBScript, Batch, Python or Perl.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...