DEV Community

Cover image for Transform Excel Data into Smart Summaries Using C# and GPT
Zahra Sandra Nasaka for Syncfusion, Inc.

Posted on • Originally published at syncfusion.com on

Transform Excel Data into Smart Summaries Using C# and GPT

TL;DR: Tired of manually analyzing spreadsheets? This tutorial shows how to build an AI-powered Excel summary tool using C#. By combining a .NET-compatible Excel library with GPT, you’ll learn to extract structured data from Excel files and generate intelligent summaries automatically, perfect for developers building smart dashboards, reporting tools, or productivity apps.

Excel is a cornerstone tool for managing structured data, whether it’s sales reports, operational logs, or support dashboards. But as datasets grow, interpreting them quickly becomes a challenge. That’s where AI-powered summarization comes in.

In this blog, you’ll learn how to build a C# console application that reads Excel files using the Syncfusion .NET Excel library and generates intelligent summaries using OpenAI GPT.

Prerequisites

To follow along with this guide, make sure you have the following:

Step-by-step implementation

Step 1: Create a .NET Core Console app

Start by creating a new .NET Core Console application in Visual Studio.

Step 2: Install the NuGet packages

Then, install the latest Syncfusion.XlsIO.NET.Core and OpenAI NuGet packages in your application.

Step 3. Read Excel data

To extract data from an Excel file, we use Syncfusion’s XlsIO library. The goal is to convert the Excel sheet into plain text that can be sent to OpenAI.

Key points:

  1. Open the Excel file using ExcelEngine.
  2. Access the first worksheet.
  3. Loop through the used range (non-empty cells).
  4. Collect cell values row by row into a string.
public static string ExtractDataAsText(string filePath)
{
    // Initialize the Excel engine
    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        // Get the Excel application instance
        IApplication application = excelEngine.Excel;

        // Set the default version to Xlsx
        application.DefaultVersion = ExcelVersion.Xlsx;

        // Open the Excel file
        IWorkbook workbook = application.Workbooks.Open(filePath);

        // Create a StringBuilder to hold the extracted data
        StringBuilder sb = new StringBuilder();

        // Iterate through each worksheet and extract data
        foreach (IWorksheet worksheet in workbook.Worksheets)
        {
            // Append the worksheet name
            sb.AppendLine($"Worksheet: {worksheet.Name}");

            // Get the used range of the worksheet
            IRange usedRange = worksheet.UsedRange;

            for (int row = usedRange.Row; row <= usedRange.LastRow; row++)
            {
                for (int col = usedRange.Column; col <= usedRange.LastColumn; col++)
                {
                    // Get the cell value and append it to the StringBuilder
                    sb.Append(worksheet.GetCellValue(row, col, true) + "\t");
                }
                sb.AppendLine();
            }

            sb.AppendLine();
        }

        return sb.ToString();
    }
}
Enter fullscreen mode Exit fullscreen mode

This gives you a clean, tab-separated text version of your Excel data.

Step 4. Send data to OpenAI GPT

Once you have the Excel data as text, you send it to OpenAI GPT to get a summary.

Key points:

  1. Use the OpenAI NuGet package.
  2. Set GPT-4 as the model.
  3. Provide a system role (e.g., “You are a data analyst”).
  4. Pass the Excel data as a user message.
public static async Task<string> SummarizeData(string inputText, string apiKey)
{
    // Initialize the OpenAI client with the provided API key and model
    ChatClient client = new(model: "gpt-5", apiKey);

    // Create a chat completion request to summarize the Excel data
    ChatCompletion completion = await client.CompleteChatAsync(
        new SystemChatMessage("You are a helpful assistant that summarizes Excel data."),
        new UserChatMessage($"Summarize the following Excel data:\n{inputText}")
    );

    // Check if the completion has content and return the summary
    return completion.Content[0].Text?.Trim() ?? string.Empty;
}
Enter fullscreen mode Exit fullscreen mode

This sends the data to GPT and returns a natural-language summary.

Step 5. Get an AI Summary from Excel

You can provide the Excel document and OpenAI API key to generate the summary. The method below provides a ready-to-use AI-powered summary from any Excel file.

static async Task<Main>()
{
    string excelFilePath = "File Path"; // Replace with the path to your Excel file
    string openAiApiKey = "OpenAI API key"; // Replace with your OpenAI API key 
    try
    {
        // Read Excel data
        string excelText = ExtractDataAsText(excelFilePath);
        Console.WriteLine("Excel data read successfully.");

        // Get summary from OpenAI
        string summary = await SummarizeData(excelText, openAiApiKey);
        Console.WriteLine("Summary from OpenAI:");
        Console.WriteLine(summary);
    }
    catch (Exception ex)
    {
        Console.WriteLine($"An error occurred: {ex.Message}");
    }
}
Enter fullscreen mode Exit fullscreen mode

Use case: Sales data summary

Imagine you’ve created an Excel file containing monthly sales data for 25 regions (January–May). Instead of manually analyzing the data, you want an AI-generated summary that highlights trends, top performers, and anomalies.

Sales data summary in Excel document


Sales data summary in Excel document

Now, use the Syncfusion .NET Excel (XlsIO) library to read the Excel document. The extracted data will appear as shown in the table below.

Region Jan Feb Mar Apr May
Region 1  $118,017  $174,803  $94,967  $180,331  $128,086
Region 2  $217,216  $218,436  $207,568  $94,502  $86,507
Region 3  $153,489  $216,328  $125,298  $248,655  $92,567
Region 4  $145,564  $139,839  $183,428  $134,356  $194,829
Region 5  $205,951  $211,589  $210,952  $186,433  $171,343
Region 6  $231,253  $143,369  $111,216  $125,112  $142,429
Region 7  $228,886  $201,669  $166,766  $105,860  $186,337
Region 8  $128,911  $193,303  $91,459  $133,207  $213,201
Region 9  $172,230  $120,484  $138,772  $184,620  $90,024
Region 10  $116,969  $243,933  $85,616  $243,440  $229,446
Region 11  $182,020  $209,462  $240,014  $137,342  $206,014
Region 12  $144,680  $220,656  $103,530  $104,883  $166,219
Region 13  $171,126  $166,316  $219,495  $129,701  $234,000
Region 14  $141,185  $129,564  $238,925  $120,482  $229,810
Region 15  $222,072  $85,435  $99,283  $220,020  $199,344
Region 16  $115,554  $235,693  $227,168  $94,344  $212,828
Region 17  $91,142  $204,142  $219,468  $203,400  $137,496
Region 18  $238,539  $165,822  $81,183  $248,280  $144,542
Region 19  $230,822  $119,669  $205,471  $196,795  $120,801
Region 20  $221,408  $80,048  $229,625  $107,344  $104,077
Region 21  $94,270  $142,935  $159,161  $166,505  $234,993
Region 22  $244,581  $218,727  $212,618  $120,062  $99,059
Region 23  $189,859  $128,230  $133,847  $179,155  $93,149
Region 24  $182,197  $165,389  $160,310  $173,761  $95,213
Region 25  $233,747  $146,593  $107,373  $135,004  $125,395

By applying the remaining steps, converting the data to plain text, and sending it to GPT, you instantly receive a natural-language summary that highlights:

  • Total and average sales across months and regions
  • Monthly performance trends and shifts
  • Top and bottom-performing regions
  • Volatility indicators and key takeaways
Category Metric/detail Value/notes
Overall totals Total (Jan–May) $20,668,938
Avg per month (all regions) $4,133,788
Avg per region (YTD) $826,758
Monthly trend Jan $4.422M → Feb $4.282M → Mar $4.054M → Apr $3.974M → May $3.938M
% Change Jan to May ↓ 10.9%
Monthly leaders & laggards January – High / Low Region 22 $244,581 / Region 17 $91,142
February – High / Low Region 10 $243,933 / Region 20 $80,048
March – High / Low Region 11 $240,014 / Region 18 $81,183
April – High / Low Region 3 $248,655 / Region 16 $94,344
May – High / Low Region 21 $234,993 / Region 2 $86,507
Highest single month overall Region 3 in April ($248,655)
Lowest single month overall Region 20 in February ($80,048)
Top Regions (YTD) Top 5 Region 5 $986,268; Region 11 $974,852; Region 13 $920,638; Region 10 $919,404; Region 22 $895,047
Bottom 5 Region 1 $696,204; Region 9 $706,130; Region 23 $724,240; Region 12 $739,968; Region 20 $742,502
Regions above YTD avg 12 of 25
Monthly totals & averages January $4,421,688 (avg/region $176,868)
February $4,282,434 (avg/region $171,297)
March $4,053,513 (avg/region $162,141)
April $3,973,594 (avg/region $158,944)
May $3,937,709 (avg/region $157,508)
Volatility Most Volatile Regions Region 18 ($167,097), Region 10 ($158,317), Region 3 ($156,088)
Key takeaways Highlights Jan strongest month; steady softening through May
Top performers Region 5 leads YTD; Regions 10, 11, 13, 22 also strong
High variability Regions 18, 10, and 3 showed biggest swings

This automated approach transforms raw spreadsheet data into actionable insights, saving hours of manual effort and enabling faster, data-driven decision-making.

For more details on working with Excel files in C#, check out the Essential XLSIO user guide.

GitHub reference

You can download the complete samples from here.

Conclusion

By combining Syncfusion Excel Library with OpenAI GPT, you can transform raw Excel data into actionable insights. Whether you’re building dashboards, reports, or decision-support tools, this integration empowers your applications with intelligent summarization.

Check out the Syncfusion .NET Excel Library documentation to discover additional features like exporting to PDF, working with charts, and using template markers, all with ready-to-use code samples. For hands-on experience, visit our online demos to see the library in action.

If you’re a Syncfusion user, you can download the setup from the license and downloads page. Otherwise, you can download a free 30-day trial.

You can also contact us through our support forum, support portal, or Feedback Portal for queries. We are always happy to assist you!

Related Blogs

This article was originally published at Syncfusion.com.

Top comments (0)