Get Excel Summary using AI

2024-02-05 05:52:15 Written by  support iceblue
Rate this item
(0 votes)

In the era of big data, facing the challenge of processing massive amounts of information stored in Excel documents, artificial intelligence (AI) technology provides a new solution for efficiently and accurately extracting key content and generating summaries.

This article focuses on the application of AI to automatically identify and extract core data from Excel documents, enabling the automated generation of concise and highlighted document summaries. This technology not only enhances data processing efficiency but also empowers decision-makers to gain deeper insights and utilize the data effectively. In the following sections, we will gradually explore how to apply AI technology to precisely extract summaries from Excel documents.

Install Spire.XLS for .NET

The Excel AI integrated into Spire.XLS for .NET package, hence to begin with, you need to add the DLL files included in the Spire.XLS for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.XLS

Request a License Key of AI Product

A license key is required to run Spire.XLS AI, please contact our sales department (sales@e-iceblue.com) to request one.

Use AI to get Document Summaries

Spire.XLS AI provides the ExcelAI class, which encapsulates the ability to perform intelligent analysis and search on Excel data. In fact, ExcelAI goes beyond merely supporting intelligent analysis of Excel data, it also extends its capabilities to encompass a variety of file formats such as txt, csv, pdf, and md, thereby enabling cross-format intelligent processing and insights. Within this class, three key methods are included:

  • UploadWorkbook(Workbook wb): This method is used to upload a Workbook object processed by Spire.XLS to the AI server, facilitating the integration of Excel content with the AI system's data.
  • UploadFile(string fileName, Stream stream): This method is used to upload txt files or files in other formats to the AI server.
  • DocumentSearch(string question, string file_server_path, bool enableHistory = false): This method allows posing specific questions to the AI system against a designated Excel document, generating intelligent responses based on its contents. The optional parameter enableHistory is set to false by default, if set to true, it enables the search history feature, allowing subsequent operations to track or leverage previous query results.

1. The following code demonstrates how to retrieve a summary of content from an Excel document:

  • C#
using Spire.Xls;
using Spire.Xls.AI;
using System.IO;
using System.Text;

// Define the file path of the Excel document 
string inputfile = "input.xlsx";

// Create a new instance of the Workbook
Workbook wb = new Workbook();

// Load the Excel file
wb.LoadFromFile(inputfile);

// Create a new instance of the ExcelAI
ExcelAI excelAI = new ExcelAI();

// Upload the workbook and obtain the file path where it's stored in the AI system
string fpath = excelAI.UploadWorkbook(wb);

// Set the question to be asked to the AI system. In this case, asking it to generate a concise summary from the Excel
string question = "Please generate a concise summary from the document";

// Get the answer generated by the AI based on the question
string answer = excelAI.DocumentSearch(question, fpath, true);

// Create a StringBuilder object to append the answer
StringBuilder builder = new StringBuilder();
builder.AppendLine(answer);

// Write the answer to the txt file
File.WriteAllText("SummaryFromExcel.txt", builder.ToString());

Input Excel Content:

Get Excel Summary using AI

Generated TXT Content:

Get Excel Summary using AI

2. The following code demonstrates how to retrieve a summary of content from a TXT:

  • C#
using Spire.Xls.AI;
using System.IO;
using System.Text;

// Define the file path of the txt 
string inputfile = "input.txt";

// Create a new instance of the ExcelAI
ExcelAI excelAI = new ExcelAI();

// Open and read the content of the text file as a stream
using (Stream stream = File.Open(inputfile, FileMode.Open))
{
    // Upload the text file to the AI system
    string fpath = excelAI.UploadFile(inputfile, stream);

    // Set the question to be asked to the AI system. In this case, asking it to generate a concise summary from the txt
    string question = "Please generate a concise summary from the document";

    // Get the answer generated by the AI based on the question
    string answer = excelAI.DocumentSearch(question, fpath, true);

    // Create a StringBuilder object to append the answer
    StringBuilder builder = new StringBuilder();
    builder.AppendLine(answer);

    // Write the answer to the txt file
    File.WriteAllText("SummaryFromTxt.txt", builder.ToString());
}

Input TXT Content:

Get Excel Summary using AI

Generated TXT Content:

Get Excel Summary using AI

Additional Info

  • tutorial_title:
Last modified on Wednesday, 28 February 2024 01:52