How to Convert TXT Files to Excel Spreadsheets Quickly

2025-09-10 01:49:21 zaki zou

Install with Maven

Install-Package Spire.XLS

Related Links

cover page of converting txt to excel with c#

Page Content:

Intro

Working with plain text files (.txt) is common, but when it comes to managing large datasets, TXT files often lack structure and usability. By converting TXT to Excel, you can take advantage of Excel's features such as filtering, formulas, pivot tables, and data visualization. In this guide, you'll learn three effective methods to convert TXT files into Excel (XLSX or CSV) format—using Microsoft Excel, a free online TXT to Excel converter, and Python programming.

Differences Between TXT, CSV, and Excel Files

Before starting the conversion, it's important to understand the differences between these formats:

  • TXT files – Store unstructured or plain text, often separated by spaces, tabs, or custom delimiters.
  • CSV files – A structured form of text file where data is separated by commas, making it easier to import into spreadsheets or databases.
  • Excel files (XLS/XLSX) – Native Microsoft Excel formats that support advanced data manipulation features, including formulas, charts, and multiple worksheets.

Converting TXT to Excel allows you to transform raw text data into a structured and interactive format.

Method 1. Import Text to Microsoft Excel and Save as Excel Format

For users who prefer not to rely on external tools, Excel itself provides a reliable method to convert TXT files into structured spreadsheets. With this method, you have no need to download any other APIs or software. As long as you can get access to Microsoft Excel, you can manage the conversion in seconds.

Follow the steps below to get started:

Step 1. Open Microsoft Excel and go to File > Open > Browse to open your TXT file.

open txt file with microsoft excel

Step 2. A window will pop out to let you select file. The default file format contains excel files only, so you should adjust the file format from the right bottom corner to "All Files" or "Text files".

adjust file format to open the target txt file on computer

Step 3. The Text Import Wizard will appear. Choose the file type (Delimited or Fixed width).

choose file type of delimited or fixed width

Select the correct delimiter (such as tab, space, or comma).

adjust correct delimiter like tab space and coma

Adjust column data formats if needed, then click Finish.

adjust column data formats to finish conversion setting

Step 4. Save the file as .xlsx or .csv.

save the file into xlsx or csv format

Method 2. Convert TXT to Excel Format with C#

For developers or advanced users handling large amounts of data, code provides a reliable way to automate TXT to Excel conversion. Let me introduce Spire.XLS for .NET to you, a professional Excel library designed for developers to create Excel files, read, edit, convert, and print Excel files within .NET applications without relying on Microsoft Excel.

Spire.XLS for .NET supports both XLS and XLSX formats along with CSV, ODS, PDF, HTML, and other file types, making it a flexible solution for handling spreadsheet data. With its rich feature set—including formula calculation, chart creation, pivot tables, data import/export, and advanced formatting. It helps developers automate Excel-related tasks efficiently while ensuring high performance and ease of integration.

Now, follow the steps below to convert your TXT files to Excel format with Spire.XLS for .NET:

Step 1. Install Spire.XLS DLL on your computer with NuGet using the following code or download from the official website.

Step 2. Copy the following code and don't forget to customize according to your specific file needs:

using Spire.Xls;
using System.IO;
using System.Collections.Generic;

class TxtToExcelConverter
{
    static void Main()
    {
        // Open a text file and read all lines in it
        string[] lines = File.ReadAllLines("Data.txt");

        // Create a list to store the data in text file
        List data = new List();

        // Split data into rows and columns and add to the list
        foreach (string line in lines)
        {
            data.Add(line.Trim().Split('\t')); // Adjust delimiter as needed
        }

        // Create a Workbook object
        Workbook workbook = new Workbook();

        // Get the first worksheet
        Worksheet sheet = workbook.Worksheets[0];

        // Iterate through the rows and columns in the data list
        for (int row = 0; row < data.Count; row++)
        {
            for (int col = 0; col < data[row].Length; col++)
            {
                // Write the text data in specified cells
                sheet.Range[row + 1, col + 1].Value = data[row][col];

                // Set the header row to Bold
                sheet.Range[1, col + 1].Style.Font.IsBold = true;
            }
        }

        // Autofit columns
        sheet.AllocatedRange.AutoFitColumns();

        // Save the Excel file
        workbook.SaveToFile("TXTtoExcel.xlsx", ExcelVersion.Version2016);
        workbook.Dispose();
    }
}

RESULT: result page of converting txt to excel with spire xls

Conclusion

Converting TXT files into Excel format makes it easier to analyze, organize, and share your data. In this post, we explored three methods:

  • Microsoft Excel import – quick and built-in for manual conversions.
  • Python scripting – powerful and flexible for automation and large datasets.

Choose the method that best suits your needs and start turning plain text into structured, usable Excel spreadsheets.

Get a Free License

To fully experience the capabilities of Spire.XLS for .NET without any evaluation limitations, you can request a free 30-day trial license.

See Also: