Skip to content

πŸ—£οΈ Chat with Excel files using natural language! Powered by Azure OpenAI and .NET 9, this app transforms spreadsheets into conversational insights with intelligent RAG pipeline and real-time data analysis.

Notifications You must be signed in to change notification settings

donpotts/AzureExcelChat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ŠπŸ’¬ Azure Excel Chat

Chat with your Excel files using natural language powered by Azure OpenAI!

.NET Azure OpenAI Semantic Kernel Excel

Transform your Excel spreadsheets into conversational insights! Ask questions about your Excel data in plain English and get intelligent responses powered by Azure OpenAI.

Azure Excel Chat Demo

✨ Features

πŸ—£οΈ Natural Language Queries - Ask questions like "Who are the engineers?" or "What's the average salary in Sales?"

πŸ€– Azure OpenAI Integration - Leverages Azure OpenAI Service (GPT-4) for intelligent data interpretation

πŸ”— Two-Step RAG Pipeline - Ensures AI answers are grounded in real data from your Excel files

βš™οΈ Auto-Setup - Automatically creates and populates sample data in Excel format

πŸ” Secure Configuration - Uses .NET User Secrets for secure API key storage

⚑ Real-time Processing - Instant responses with live Excel data parsing

πŸ“ Local Files - Works with local Excel files (.xlsx format)

🎨 Beautiful Console Interface - Rich console output with emojis and formatting

πŸ”§ How It Works

The application follows a simple, two-step RAG (Retrieval-Augmented Generation) pattern:

graph TD
    A[❓ User Question] --> B[🧠 Azure OpenAI Analysis]
    B --> C[πŸ“ Query Description]
    C --> D[πŸ“Š Excel File Parsing]
    D --> E[πŸ” Data Filtering]
    E --> F[πŸ’­ Answer Generation]
    F --> G[πŸ’¬ Natural Language Response]
Loading
  1. Step 1: Query Analysis - Converts your question into a filtering strategy using your Excel schema
  2. Step 2: Data Retrieval & Response - Filters the Excel data and generates a friendly, natural language answer

🎬 Demo

Here's what a typical session looks like:

πŸ“ŠπŸ’¬ Azure Excel Chat
════════════════════════════════════════
Chat with your Excel files using natural language powered by Azure OpenAI!

βš™οΈ Setting up Excel file...
βœ… Created new worksheet: Employees
πŸ“Š Excel file 'Employees' populated with sample data
πŸ“ File location: G:\repos\AzureExcelChat\employees.xlsx

πŸ“‹ Excel Schema:
πŸ“‹ Excel Worksheet Structure:
════════════════════════════════════════
Worksheet Name: Employees
Columns:
- A: Id (INTEGER) - Employee ID number
- B: Name (TEXT) - Employee full name  
- C: Department (TEXT) - Department (Engineering, Sales, HR, Marketing)
- D: Salary (INTEGER) - Annual salary in USD
- E: HireDate (TEXT) - Date hired (YYYY-MM-DD format)

πŸ’¬ Chat with your Excel file! Type 'exit' to quit.
════════════════════════════════════════

πŸ€– > Who are the engineers?

πŸ” Query Analysis: Filter employees where Department column contains 'Engineering' and return their names, IDs, and salaries.
πŸ“Š Excel Data Retrieved:

Id Name Department Salary HireDate 1 Alice Johnson Engineering 95000 2022-01-15 3 Charlie Brown Engineering 110000 2020-05-20 7 Grace Liu Engineering 103000 2023-01-20


πŸ’‘ Answer: The engineers in the company are Alice Johnson (ID: 1, Salary: $95,000), Charlie Brown (ID: 3, Salary: $110,000), and Grace Liu (ID: 7, Salary: $103,000).

════════════════════════════════════════

πŸ€– > What is the average salary in the Sales department?

πŸ” Query Analysis: Filter employees where Department is 'Sales' and calculate the average of their Salary values.
πŸ“Š Excel Data Retrieved:

Id Name Department Salary HireDate 2 Bob Smith Sales 82000 2021-11-30 4 Diana Prince Sales 78000 2022-08-01 8 Henry Davis Sales 85000 2022-03-12


πŸ’‘ Answer: The average salary in the Sales department is $81,667. This is calculated from three employees: Bob Smith ($82,000), Diana Prince ($78,000), and Henry Davis ($85,000).

πŸ“‹ Prerequisites

Before you begin, ensure you have:

πŸš€ Quick Start

1. Clone and Setup

git clone https://github.com/donpotts/AzureExcelChat.git
cd AzureExcelChat
dotnet restore

2. Configure Azure OpenAI Credentials

The application uses .NET User Secrets to securely store your API keys:

# Initialize user secrets
dotnet user-secrets init

# Set your Azure OpenAI credentials
dotnet user-secrets set "AZURE_OPENAI_API_KEY" "your-azure-openai-api-key"
dotnet user-secrets set "AZURE_OPENAI_ENDPOINT" "https://your-resource.openai.azure.com/"
dotnet user-secrets set "AZURE_OPENAI_DEPLOYMENT_NAME" "your-gpt-4-deployment-name"

# Optional: Set custom Excel file path (defaults to ./employees.xlsx)
dotnet user-secrets set "EXCEL_FILE_PATH" "C:\path\to\your\custom\file.xlsx"

3. Get Your Azure OpenAI Credentials

  1. Create Azure OpenAI Resource

    • Go to Azure Portal
    • Create an Azure OpenAI resource
    • Note your endpoint URL (e.g., https://your-resource.openai.azure.com/)
  2. Deploy a Model

    • In Azure OpenAI Studio, deploy a GPT model
    • Recommended: gpt-4 or gpt-35-turbo
    • Note your deployment name
  3. Get API Key

    • In Azure Portal, go to your OpenAI resource
    • Navigate to "Keys and Endpoint"
    • Copy one of the API keys

4. Run the Application

dotnet run

πŸ’­ Example Queries

Try these natural language questions with your Excel data:

🏒 Department Queries

  • "Who are the engineers?"
  • "Show me the Sales team"
  • "List all HR employees"
  • "How many people work in Marketing?"

πŸ’° Salary Analysis

  • "Who earns more than $90,000?"
  • "What's the average salary?"
  • "Who has the highest salary?"
  • "Show me employees earning between $70,000 and $100,000"

πŸ“… Date Filtering

  • "Who was hired in 2022?"
  • "Show recent hires"
  • "List employees hired before 2021"

πŸ“Š Statistics

  • "How many people work in each department?"
  • "What's the average salary by department?"
  • "Who are the top 3 earners?"

πŸ” General Queries

  • "List all employees"
  • "Show me everyone's information"
  • "Give me a summary of the data"

πŸ—οΈ Architecture & Technology Stack

Core Technologies

Component Technology Purpose
AI Framework Microsoft Semantic Kernel 1.64.0 AI orchestration and prompt management
Language Model Azure OpenAI Service (GPT-4) Natural language understanding and generation
Data Source Excel Files (.xlsx) Local spreadsheet data storage
Excel Library ClosedXML 0.104.1 Excel file reading and manipulation
Runtime .NET 9.0 Modern, high-performance application platform
Configuration .NET User Secrets Secure API key management

Key Components

  • Semantic Kernel: Microsoft's AI orchestration framework for building AI applications
  • Azure OpenAI: Enterprise-ready AI service with GPT models
  • ClosedXML: Powerful .NET library for Excel file manipulation
  • Smart Filtering: Context-aware data filtering based on AI analysis
  • User Secrets: Secure credential storage for development

βš™οΈ Customization

Switching GPT Models

Update your deployment to use different models:

# For GPT-4 (recommended for best results)
dotnet user-secrets set "AZURE_OPENAI_DEPLOYMENT_NAME" "gpt-4"

# For GPT-3.5-turbo (faster and more cost-effective)
dotnet user-secrets set "AZURE_OPENAI_DEPLOYMENT_NAME" "gpt-35-turbo"

Adding Custom Query Types

Extend the FilterDataBasedOnQuery method in Program.cs:

// Example: Position-based filtering
else if (query.Contains("manager") || query.Contains("senior") || description.Contains("position"))
{
    includeRow = row.Count > 5 && row[5]?.ToString()?.ToLower().Contains("manager") == true;
}

Custom Excel File Structure

  1. Update Schema: Modify GetExcelSchema() to reflect your data structure
  2. Adjust Sample Data: Update SetupExcelFile() with your sample data
  3. Update Filtering: Modify FilterDataBasedOnQuery() for your columns
  4. Column Mapping: Adjust column indices throughout the code

Environment-Specific Configuration

For production deployments, you can use environment variables instead of user secrets:

# Environment variables (production)
export AZURE_OPENAI_API_KEY="your-key"
export AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com/"
export AZURE_OPENAI_DEPLOYMENT_NAME="your-deployment"
export EXCEL_FILE_PATH="/path/to/production/file.xlsx"

πŸ“Š Sample Data Structure

The application creates this sample employee dataset:

Id Name Department Salary HireDate
1 Alice Johnson Engineering $95,000 2022-01-15
2 Bob Smith Sales $82,000 2021-11-30
3 Charlie Brown Engineering $110,000 2020-05-20
4 Diana Prince Sales $78,000 2022-08-01
5 Eve Adams HR $65,000 2023-02-10
6 Frank Wilson Marketing $72,000 2021-09-15
7 Grace Liu Engineering $103,000 2023-01-20
8 Henry Davis Sales $85,000 2022-03-12
9 Ivy Chen HR $70,000 2020-12-05
10 Jack Miller Marketing $68,000 2023-05-18

πŸ”’ Security Best Practices

  • πŸ” User Secrets: API keys are stored securely using .NET User Secrets
  • ❌ No Hardcoded Credentials: All sensitive data is externalized
  • 🌍 Environment Variables: Support for production environment configuration
  • πŸ“ Local Files: Excel files are processed locally, ensuring data privacy
  • πŸ›‘οΈ Minimal Permissions: Application only requires file system access

πŸ”§ Troubleshooting

Common Issues & Solutions

Issue Solution
"AZURE_OPENAI_API_KEY is not set" Run: dotnet user-secrets set "AZURE_OPENAI_API_KEY" "your-key"
"AZURE_OPENAI_ENDPOINT is not set" Run: dotnet user-secrets set "AZURE_OPENAI_ENDPOINT" "your-endpoint"
"AZURE_OPENAI_DEPLOYMENT_NAME is not set" Run: dotnet user-secrets set "AZURE_OPENAI_DEPLOYMENT_NAME" "your-deployment"
"Error reading Excel file" Ensure Excel file isn't open in another application
"Authorization failed" Verify your Azure OpenAI API key and endpoint are correct
"Model not found" Ensure your deployment name matches exactly

Debug Steps

  1. Verify Configuration: Check user secrets with dotnet user-secrets list
  2. Test Azure OpenAI: Ensure your Azure OpenAI resource is properly configured
  3. Check File Permissions: Ensure the application can read/write Excel files
  4. Review Logs: Check console output for specific error messages
  5. Validate Deployment: Confirm your GPT model deployment is active

Getting Help

If you encounter issues:

  1. Check Azure OpenAI Status: Visit Azure Status Page
  2. Review Documentation: Azure OpenAI Documentation
  3. Open an Issue: Create a GitHub issue with error details and configuration (without secrets)

⚑ Performance Optimization

Response Speed

  • Use gpt-35-turbo for faster responses
  • Reduce max_tokens in prompt settings for shorter responses
  • Filter Excel data before sending to AI to reduce token usage

Cost Optimization

  • Use gpt-35-turbo instead of gpt-4 for cost savings
  • Implement caching for repeated queries
  • Optimize prompts to reduce token consumption

Large Excel Files

  • Consider pagination for files with thousands of rows
  • Implement column selection to focus on relevant data
  • Use Excel filtering before AI processing

Development Guidelines

  • Follow .NET coding conventions
  • Add unit tests for new features
  • Update documentation for any changes
  • Ensure all tests pass before submitting PR

πŸ™ Acknowledgments

⭐ Show Your Support

If you find this project helpful, please consider:

  • ⭐ Starring this repository
  • πŸ› Reporting bugs or suggesting features
  • πŸ“’ Sharing with others who might benefit

πŸ“§ Contact

Don Potts - Don.Potts@DonPotts.com


πŸš€ Transform your Excel spreadsheets into intelligent conversations today! πŸ“Š

About

πŸ—£οΈ Chat with Excel files using natural language! Powered by Azure OpenAI and .NET 9, this app transforms spreadsheets into conversational insights with intelligent RAG pipeline and real-time data analysis.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published