금. 8μ›” 15th, 2025

Have you ever stared at a seemingly endless stream of characters in a text file, knowing that hidden within are neatly organized columns of data, but they’re just… not separated? Welcome to the world of fixed-width text files! Unlike CSVs (Comma Separated Values) where commas (or other delimiters) mark the end of one field and the beginning of another, fixed-width files rely purely on character position. Each piece of data occupies a pre-defined number of characters, regardless of its actual length.

Importing these files into Excel can seem daunting at first, but with Excel’s powerful “External Data” capabilities (now evolved into “Get & Transform Data” or Power Query), it’s a straightforward process that will save you countless hours of manual data parsing. Let’s break it down!

What Exactly Is a Fixed-Width Text File? πŸ€”

Imagine a data entry system from the 1980s or a legacy mainframe system. To save space and ensure consistency, developers would assign exact positions for each data field.

Example Fixed-Width Data:

JONES   ROBERT  19750315NY  SALES   0012345
SMITH   ALICE   19881122CA  MARKET  0009876
DOE     JOHN    19620701TX  ENGINE  0005432

In this example, the data might be structured like this:

  • Last Name: Characters 1-8 (8 characters)
  • First Name: Characters 9-16 (8 characters)
  • Date of Birth + State Code: Characters 17-26 (10 characters)
  • Department: Characters 27-33 (7 characters)
  • Employee ID: Characters 34-40 (7 characters)

Notice how “JONES” uses only 5 characters but the field length is 8, leaving 3 spaces. This fixed position is key.

Why Import Fixed-Width Files into Excel? ✨

Once your data is in Excel, the possibilities are endless! You can:

  • Perform calculations and analyses.
  • Create charts and visualizations.
  • Filter, sort, and organize your data.
  • Combine it with other datasets.
  • Prepare it for database imports or other software.

Essentially, it transforms raw, difficult-to-read text into an actionable, manipulable spreadsheet.

Method 1: The Traditional “Text Import Wizard” (Excel 2010-2016 & Legacy Options) βš™οΈ

This method is the classic way to import fixed-width files and is still available in newer Excel versions under “Legacy Wizards.” It’s intuitive for one-off imports.

Step-by-Step Guide:

  1. Open Excel: Start with a blank workbook or the workbook where you want to import the data.

  2. Go to the Data Tab: In the Excel ribbon, click on the “Data” tab.

  3. Choose “Get Data” (or “From Text/CSV” in newer versions):

    • Excel 2010-2016: Look for “From Text” in the “Get External Data” group.
    • Excel 2019 / Microsoft 365: Click “Get Data” > “Legacy Wizards” > “From Text (Legacy)”. This will launch the familiar Text Import Wizard.
  4. Select Your Text File: A file explorer window will open. Navigate to and select your fixed-width text file, then click “Import.”

  5. Step 1 of the Text Import Wizard – Choose File Type:

    • Excel will display the first few rows of your data.

    • Under “Original data type,” select “Fixed width.” (Important!)

    • Ensure “My data has headers” is checked if the first row of your text file contains column names. Otherwise, leave it unchecked.

    • Click “Next >”.

    • Screenshot Idea: A dialog box showing “Delimited” and “Fixed width” options with “Fixed width” selected.

  6. Step 2 of the Text Import Wizard – Set Column Breaks: πŸ“

    • This is the most crucial step for fixed-width files. Excel will show your data with a ruler above it.

    • Click on the ruler where you want to create a column break. A vertical line will appear.

    • To remove a break, double-click on its line.

    • To move a break, click and drag it.

    • Tip: Use your knowledge of the fixed positions (e.g., Last Name is 8 characters, so break at character 9). Visually inspect the data to ensure the breaks align correctly for all rows.

    • Click “Next >”.

    • Screenshot Idea: The wizard showing the data preview with vertical lines defining columns, and the ruler at the top.

  7. Step 3 of the Text Import Wizard – Data Format Settings: βœ…

    • Here, you can specify the “Column data format” for each column.
    • Click on a column in the data preview to select it. Then choose the appropriate format:
      • General: Excel decides the best format (numbers, dates, text).
      • Text: Treats all data in the column as text, preventing Excel from converting numbers to dates, or removing leading zeros.
      • Date: Select a specific date format (e.g., YMD for 19750315).
      • Do Not Import Column: If you don’t need a specific column, select this.
    • Tip for leading zeros: If you have employee IDs like 0012345 and need to preserve the leading zeros, always set that column’s format to “Text.”
    • Click “Finish.”
  8. Choose Destination:

    • Excel will ask where to put the imported data (e.g., existing worksheet, new worksheet).
    • Select your preference and click “OK.”

Voila! Your fixed-width data is now neatly organized into columns in Excel.

Method 2: “Get & Transform Data” (Power Query) (Excel 2016+ / Microsoft 365) ✨

Power Query is Excel’s modern, powerful data transformation engine. While the Text Import Wizard is fine for simple, one-time fixed-width imports, Power Query offers significantly more flexibility, repeatability, and advanced transformation capabilities. It’s the recommended approach for any regular or complex data import tasks.

For fixed-width files, Power Query doesn’t always have a direct “fixed-width” setting in the initial import step like the old wizard. Instead, you import the file and then use Power Query’s robust “Split Column” features to parse the data based on character counts.

Step-by-Step Guide:

  1. Open Excel: Start a new or existing workbook.

  2. Go to the Data Tab: Click on the “Data” tab in the Excel ribbon.

  3. Choose “Get Data”: Click “Get Data” > “From File” > “From Text/CSV.”

  4. Select Your Text File: Navigate to and select your fixed-width text file, then click “Import.”

  5. Initial Import Preview: Excel will show a preview. Often, fixed-width files might initially appear as a single, long column if Excel doesn’t automatically detect the structure. This is perfectly fine!

    • Important: Instead of clicking “Load,” click “Transform Data”. This will open the Power Query Editor.

    • Screenshot Idea: The initial import preview, with the “Load” and “Transform Data” buttons, highlighting “Transform Data”.

  6. Inside the Power Query Editor – Splitting Columns: πŸš€

    • Your fixed-width data will likely be in one column (e.g., “Column1”).

    • Select this column.

    • Go to the “Transform” tab in the Power Query Editor ribbon.

    • Click “Split Column” > “By Number of Characters…”

    • Screenshot Idea: Power Query Editor with “Column1” selected, and the “Split Column” dropdown showing “By Number of Characters…”

  7. “Split Column by Number of Characters” Dialog:

    • A dialog box will appear. Here’s where you define your fixed widths.

    • Example for our sample data:

      • First split: After 8 characters (for “Last Name”). Enter 8.
      • Then, you might need to repeat this for subsequent columns.
      • Important: For fixed-width, you’ll typically select “Once as far left as possible” if you’re doing a series of splits from left to right, or “Repeatedly” if all segments are the same length, which is less common for varied fixed-width files. For our example, let’s assume we’ll do multiple splits.
    • Alternative/More robust method: If you have multiple varying lengths, you might need to apply “Split Column by Number of Characters” multiple times, each time splitting the remaining column.

      • Split Column1 after 8 characters (for Last Name). This creates Column1.1 and Column1.2.
      • Rename Column1.1 to “LastName”.
      • Select Column1.2 and split it after 8 characters (for First Name). This creates Column1.2.1 and Column1.2.2.
      • Rename Column1.2.1 to “FirstName”.
      • Continue this process until all columns are separated.
    • Screenshot Idea: The “Split Column by Number of Characters” dialog.

  8. Rename Columns and Adjust Data Types:

    • Once your columns are split, double-click on the column headers in Power Query to rename them (e.g., “LastName,” “FirstName,” “DOB_State,” “Department,” “EmployeeID”).

    • Click the icon next to each column header (often “ABC 123” for “Any”) to set the correct data type (e.g., Text, Number, Date). Again, for leading zeros, choose “Text.”

    • Screenshot Idea: Renamed columns and data type selection dropdowns.

  9. Load Data to Excel:

    • Once you’re satisfied with your transformations, go to the “Home” tab in the Power Query Editor.

    • Click “Close & Load” or “Close & Load To…” (if you want to specify a destination).

    • Screenshot Idea: The “Close & Load” button.

Your fixed-width data will now be loaded into Excel as a table. The beauty of Power Query is that all these steps are recorded. If the source file is updated later, you can simply right-click the table in Excel and select “Refresh” to re-import and re-apply all the transformations automatically! πŸ”„

Common Pitfalls and Troubleshooting ⚠️

  • Incorrect Column Breaks (Text Import Wizard): If your data looks jagged or misaligned, go back to Step 2 of the wizard and adjust the vertical lines. Zooming in on the preview can help.
  • Missing Leading Zeros: If numerical IDs like 0012345 turn into 12345, it means Excel interpreted them as numbers. In the Text Import Wizard (Step 3) or Power Query (Data Type setting), always set such columns to “Text.”
  • Date Misinterpretations: Dates like 19750315 can be tricky. Explicitly tell Excel the format (e.g., YMD) in the wizard, or transform them in Power Query (e.g., Text.Middle, Date.FromText).
  • Header Row Issues: If your first row is data, but you told Excel it’s a header, your first data row will become column names. Uncheck “My data has headers.” Conversely, if you do have headers and they’re being imported as data, ensure the option is checked.
  • Encoding Problems: If characters appear as gibberish (e.g., “ñ”), it’s likely an encoding issue. In the Text Import Wizard (Step 1) or Power Query’s “File Origin” setting, try different encodings like UTF-8 or different ANSI options.
  • Empty Rows/Columns: Power Query is excellent for cleaning these. Use “Remove Rows” (e.g., “Remove Blank Rows”) and “Remove Columns” features.

Best Practices for Importing Fixed-Width Data πŸ‘

  1. Understand Your Data Source: Before importing, try to get the layout specification for the fixed-width file. This will tell you exact starting positions and lengths for each field, making step 2 of the Text Import Wizard or Power Query’s “Split Column” much easier.
  2. Always Review Data: After importing, always scroll through your data and spot-check for any anomalies, misaligned columns, or incorrect data types.
  3. Use Power Query for Repeatable Tasks: If you regularly receive the same fixed-width file, investing time to set up a Power Query solution will save you immense time in the long run. The query is saved with your workbook, allowing for one-click refreshes.
  4. Preserve the Original: Never directly modify your source text file. Always import it into Excel. If something goes wrong, you can always start fresh with the original.
  5. Start Simple, Then Refine: Don’t try to get every single data type and transformation perfect on the first pass. Get the data split into columns first, then refine data types and perform further transformations.

Conclusion πŸ†

Importing fixed-width text files into Excel is a fundamental skill for anyone dealing with legacy data or specific data formats. Whether you use the classic Text Import Wizard for quick, one-off tasks or leverage the robust power of “Get & Transform Data” for repeatable, complex imports, mastering this process will transform your raw data into usable, actionable insights. Go forth and conquer those fixed-width files! πŸš€ G

λ‹΅κΈ€ 남기기

이메일 μ£Όμ†ŒλŠ” κ³΅κ°œλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. ν•„μˆ˜ ν•„λ“œλŠ” *둜 ν‘œμ‹œλ©λ‹ˆλ‹€