Convert Fixed Width Text to Any File MS Excel Can Save As

If you have trouble running these examples see Using the Command Line and Helpful Hints For Creating a Command Line.

Converting from a fixed width text file to anything MS Excel can save to requires a two step conversion process since MS Excel does not natively know how to interpret a fixed width text file. First we'll use the 'Convert XLS' conversion method to convert from a fixed width text file to an Excel file. From there, we'll use the 'MS Excel' conversion method to convert the Excel file to anything MS Excel can 'Save As'.

The first example shows how to convert from a fixed width text file to a dBase IV (*.DBF) file. To convert to anything else change the /C11 to the desired output file type. See Excel Conversion File Type Constants for all possible values for /C.

All the examples below use an 8 bit ANSI/ASCII text file for the input file. To convert Unicode text files, swap out /F21 with /F42 in the examples.

Each switch shown in blue is described in detail below the examples given. It is highly recommended you review each switches description before implementing the example, thereby giving you the full power of 'Convert XLS'.

Example 1: Convert a Fixed Width Text File To HTML

First specify your fixed width text profile (column widths) using the Fixed Width Text Profile Editor and name your profile MyColWidths. To convert a fixed width text file (c:\in\input.txt) whose columns widths are defined within the MyColWidths profile to a dBase IV file c:\out\out.DBF, the following syntax would be used:

ConvertXLS.EXE /S"C:\in\input.TXT" /T "C:\out\temp.XLS" /C-4143 /F21 /M2 /N"^^^2^MyColWidths" /V

ConvertXLS.EXE /S"C:\out\temp.XLS" /T "C:\out\out.DBF" /C11 /F-4143 /M1 /V

Next we show how to convert a whole folder (and sub-folders /R) of text files (C:\abc\*.txt) to DBF files located in the same folder. The following syntax would be used for such a case:

 

ConvertXLS.EXE /S"C:\abc\*.TXT" /T "C:\abc\*.XLS" /C-4143 /F21 /M2 /N"^^^2^MyColWidthds" /R /V

ConvertXLS.EXE /S"C:\abc\*.XLS" /T "C:\abc\*.DBF" /C11 /F-4143 /M1 /R /V

 

The /G switch can be used to tell 'Convert XLS' to place each output file in the same folder as each input file. Therefore the command line above is equivalent to the command line below:

 

ConvertXLS.EXE /S"C:\abc\*.TXT" /G /C-4143 /F21 /M2 /N"^^^2^MyColWidthds" /R /V

ConvertXLS.EXE /S"C:\abc\*.XLS" /G /C11 /F-4143 /M1 /R /V

 

Building on the last example, say you want to specify a range, say A1:B10 within the input text file. No problem, modify the /N switch as shown below:

 

ConvertXLS.EXE /S"C:\abc\*.TXT" /G /C-4143 /F21 /M2 /N"^ A1:B10^^2^MyColWidthds" /R /V

ConvertXLS.EXE /S"C:\abc\*.XLS" /G /C11 /F-4143 /M1 /R /V

 

Specifying ranges can be very powerful.

 

Sheet: Not useful in these examples. Use "*" or "" for all sheets. You can use names of sheets, or the numeric index. If using numeric indices, you can specify ranges of sheets (i.e. "1,4,10-20" and "4-10,9" etc.).

Range: You could optionally specify a range; say if you only wanted to convert a portion of the input file. Use the same syntax as an Excel range (e.g. A1:B10, B:B). Once converted to an XLS file, you could then use special process 101 to move the data to any cell range.

DelimChar: Not useful in these examples. It is for specifying the ASCII value of the delimitation character used in a CSV file. 44 for comma, 124 for Bar "|", 9 for the tab etc.

FixedWidth: 'Convert XLS' Conversion Method only (/M2). Here you can specify how to import/export a fixed width text file. The following numeric values are valid:

0 = Auto size column widths to fit all data (Default)

1 = Use same widths as specified in the Excel file

2 = Use widths specified by the Profile. Widths can be specified in the user interfaces the Fixed Width Text Profile Editor.

Profile = If you are specifying a fixed width text profile to use do it with this parameter. Use the Fixed Width Text Profile Editor to generate a profile. The full path to the txt file could be used. As an example if you want to specify to convert sheets called 'Apples' and 'Oranges', and use the range "A2:B20" and a fixed width text file profile named MyColWidths you would do so like this:

/N"Apples,Oranges^A2:B20^^2^MyColWidths"

Note: It is highly encouraged that you use the Verbose (/V) switch initially to see what the status of your conversion is and to help you perfect your command line. When in verbose mode the program will tell you what went wrong or right with your command line using message boxes.