DOS Batch to Convert Text File with Rows & Columns to Excel Worksheet


By: sburtchin
February 8, 2012

Delineate your column information with tabs in your text file (eg. "MyDoc.txt").


Step 1. Open your text file in Notepad (double-click the text file in File Manager).

Step 2. Select Edit -> Replace... from the menu.

Step 3. Type two spaces in the "Find what:" field and one space in the "Replace with:" field.

Step 4.
Then click on "Replace All" repeatedly until no more replacements are made.

Step 5.
Now type only one space in the "Find what:" field and only a tab in the "Replace with:" field.

Step 6. Click on the "Find Next" button.

Step 7. Then click on "Replace" or "Replace All" as appropriate until tabs have been inserted everywhere you want to begin a new column (in each row).

Step 8. Then select File -> Save, then File -> Exit (to exit Notepad).

Create Excel worksheet using a DOS Batch File.


Step 1. Create the batch file (eg. "TextToExcel.bat").

Step 1a. Create a document in Notepad with the following contents:

@echo off

copy %1 %1.xls > nul 
excel %1.xls 

Step 1b. Then select File -> Save As..., change the filename extension from ".txt" to ".bat", then click on the Save button.

Step 1c. Then File -> Exit (to exit Notepad).

Step 2. Run your batch file to create the Excel worksheet.

Step 2a. Click on Start -> Run..., or alternatively Start -> Programs -> Accessories -> Command Prompt.

Step 2b. Type "[d1:][path1]TextToExcel [d2:][path2]MyDoc.txt" and hit Enter.

NOTE: Substitute the appropriate (optional) drives and paths as applicable.

NOTE: If you copy your batch file to a directory that is in the path statement, "d1:" and "path1" will not be needed.


Need more help?
Describe your Problem
Example: Hard Drive Not Detected on My PC

Ask Question