Using IronXL, you can instantly compute aggregate values such as sum and maximum from any range. これらの一行メソッドは、定型的なコードなしで数値データを迅速かつ簡単に分析することを可能にします。 ライブラリはすべての解析を処理し、数値以外の内容は自動的に無視されます。
1Install IronXL with NuGet Package Manager
PM > Install-Package IronXL.Excel
Install-Package IronXL.Excel
2このコード スニペットをコピーして実行します。
decimal total = workSheet["A1:A8"].Sum();decimal maximum = workSheet["A1:A8"].Max();
decimal total = workSheet["A1:A8"].Sum();
decimal maximum = workSheet["A1:A8"].Max();
using IronXL;using System.Linq;WorkBook workBook = WorkBook.Load("sample.xls");WorkSheet workSheet = workBook.WorkSheets.First();// Get range from worksheetvar range = workSheet["A1:A8"];// Calculate the sum of numeric cells within the rangedecimal sum = range.Sum();// Calculate the average value of numeric cells within the rangedecimal avg = range.Avg();// Identify the maximum value among numeric cells within the rangedecimal max = range.Max();// Identify the minimum value among numeric cells within the rangedecimal min = range.Min();
using IronXL;
using System.Linq;
WorkBook workBook = WorkBook.Load("sample.xls");
WorkSheet workSheet = workBook.WorkSheets.First();
// Get range from worksheet
var range = workSheet["A1:A8"];
// Calculate the sum of numeric cells within the range
decimal sum = range.Sum();
// Calculate the average value of numeric cells within the range
decimal avg = range.Avg();
// Identify the maximum value among numeric cells within the range
decimal max = range.Max();
// Identify the minimum value among numeric cells within the range
decimal min = range.Min();
ImportsIronXLImportsSystem.LinqDim workBook AsWorkBook = WorkBook.Load("sample.xls")Dim workSheet AsWorkSheet = workBook.WorkSheets.First()' Get range from worksheetDim range = workSheet("A1:A8")' Calculate the sum of numeric cells within the rangeDim sum AsDecimal = range.Sum()' Calculate the average value of numeric cells within the rangeDim avg AsDecimal = range.Avg()' Identify the maximum value among numeric cells within the rangeDim max AsDecimal = range.Max()' Identify the minimum value among numeric cells within the rangeDim min AsDecimal = range.Min()
Imports IronXL
Imports System.Linq
Dim workBook As WorkBook = WorkBook.Load("sample.xls")
Dim workSheet As WorkSheet = workBook.WorkSheets.First()
' Get range from worksheet
Dim range = workSheet("A1:A8")
' Calculate the sum of numeric cells within the range
Dim sum As Decimal = range.Sum()
' Calculate the average value of numeric cells within the range
Dim avg As Decimal = range.Avg()
' Identify the maximum value among numeric cells within the range
Dim max As Decimal = range.Max()
' Identify the minimum value among numeric cells within the range
Dim min As Decimal = range.Min()
using IronXL;WorkBook workBook = WorkBook.Load("sales-data.xlsx");WorkSheet sheet = workBook.DefaultWorkSheet;// Calculate total sales from rangedecimal totalSales = sheet["B2:B50"].Sum();Console.WriteLine($"Total Sales: ${totalSales:N2}");
using IronXL;
WorkBook workBook = WorkBook.Load("sales-data.xlsx");
WorkSheet sheet = workBook.DefaultWorkSheet;
// Calculate total sales from range
decimal totalSales = sheet["B2:B50"].Sum();
Console.WriteLine($"Total Sales: ${totalSales:N2}");
ImportsIronXLDim workBook AsWorkBook = WorkBook.Load("sales-data.xlsx")Dim sheet AsWorkSheet = workBook.DefaultWorkSheet' Calculate total sales from rangeDim totalSales AsDecimal = sheet("B2:B50").Sum()Console.WriteLine($"Total Sales: {totalSales:N2}")
Imports IronXL
Dim workBook As WorkBook = WorkBook.Load("sales-data.xlsx")
Dim sheet As WorkSheet = workBook.DefaultWorkSheet
' Calculate total sales from range
Dim totalSales As Decimal = sheet("B2:B50").Sum()
Console.WriteLine($"Total Sales: {totalSales:N2}")
using IronXL;WorkBook workBook = WorkBook.Load("student-grades.xlsx");WorkSheet sheet = workBook.DefaultWorkSheet;// Calculate average grade for a studentdecimal avgGrade = sheet["C2:C10"].Avg();Console.WriteLine($"Average Grade: {avgGrade:F2}");
using IronXL;
WorkBook workBook = WorkBook.Load("student-grades.xlsx");
WorkSheet sheet = workBook.DefaultWorkSheet;
// Calculate average grade for a student
decimal avgGrade = sheet["C2:C10"].Avg();
Console.WriteLine($"Average Grade: {avgGrade:F2}");
ImportsIronXLDim workBook AsWorkBook = WorkBook.Load("student-grades.xlsx")Dim sheet AsWorkSheet = workBook.DefaultWorkSheet' Calculate average grade for a studentDim avgGrade AsDecimal = sheet("C2:C10").Avg()Console.WriteLine($"Average Grade: {avgGrade:F2}")
Imports IronXL
Dim workBook As WorkBook = WorkBook.Load("student-grades.xlsx")
Dim sheet As WorkSheet = workBook.DefaultWorkSheet
' Calculate average grade for a student
Dim avgGrade As Decimal = sheet("C2:C10").Avg()
Console.WriteLine($"Average Grade: {avgGrade:F2}")
Imports IronXL
Dim workBook As WorkBook = WorkBook.Load("product-prices.xlsx")
Dim sheet As WorkSheet = workBook.DefaultWorkSheet
' Find the lowest price
Dim lowestPrice As Decimal = sheet("D2:D100").Min()
Console.WriteLine($"Lowest Price: ${lowestPrice:N2}")
using IronXL;WorkBook workBook = WorkBook.Load("temperature-data.xlsx");WorkSheet sheet = workBook.DefaultWorkSheet;// Find the highest temperature recordeddecimal maxTemp = sheet["E2:E365"].Max();Console.WriteLine($"Highest Temperature: {maxTemp:F1}°F");
using IronXL;
WorkBook workBook = WorkBook.Load("temperature-data.xlsx");
WorkSheet sheet = workBook.DefaultWorkSheet;
// Find the highest temperature recorded
decimal maxTemp = sheet["E2:E365"].Max();
Console.WriteLine($"Highest Temperature: {maxTemp:F1}°F");
ImportsIronXLDim workBook AsWorkBook = WorkBook.Load("temperature-data.xlsx")Dim sheet AsWorkSheet = workBook.DefaultWorkSheet' Find the highest temperature recordedDim maxTemp AsDecimal = sheet("E2:E365").Max()Console.WriteLine($"Highest Temperature: {maxTemp:F1}°F")
Imports IronXL
Dim workBook As WorkBook = WorkBook.Load("temperature-data.xlsx")
Dim sheet As WorkSheet = workBook.DefaultWorkSheet
' Find the highest temperature recorded
Dim maxTemp As Decimal = sheet("E2:E365").Max()
Console.WriteLine($"Highest Temperature: {maxTemp:F1}°F")
using IronXL;// Load workbook containing various numeric formatsWorkBook workBook = WorkBook.Load("financial-data.xlsx");WorkSheet salesSheet = workBook.GetWorkSheet("Q4Sales");// Calculate total revenue from currency-formatted cellsdecimal totalRevenue = salesSheet["B2:B50"].Sum();Console.WriteLine($"Total Q4 Revenue: ${totalRevenue:N2}");// Find the highest individual sale amountdecimal maxSale = salesSheet["B2:B50"].Max();Console.WriteLine($"Largest Sale: ${maxSale:N2}");// Calculate average sale amountdecimal avgSale = salesSheet["B2:B50"].Avg();Console.WriteLine($"Average Sale: ${avgSale:N2}");// Process percentage data (e.g., tax rates)decimal avgTaxRate = salesSheet["D2:D50"].Avg();Console.WriteLine($"Average Tax Rate: {avgTaxRate:P2}");
using IronXL;
// Load workbook containing various numeric formats
WorkBook workBook = WorkBook.Load("financial-data.xlsx");
WorkSheet salesSheet = workBook.GetWorkSheet("Q4Sales");
// Calculate total revenue from currency-formatted cells
decimal totalRevenue = salesSheet["B2:B50"].Sum();
Console.WriteLine($"Total Q4 Revenue: ${totalRevenue:N2}");
// Find the highest individual sale amount
decimal maxSale = salesSheet["B2:B50"].Max();
Console.WriteLine($"Largest Sale: ${maxSale:N2}");
// Calculate average sale amount
decimal avgSale = salesSheet["B2:B50"].Avg();
Console.WriteLine($"Average Sale: ${avgSale:N2}");
// Process percentage data (e.g., tax rates)
decimal avgTaxRate = salesSheet["D2:D50"].Avg();
Console.WriteLine($"Average Tax Rate: {avgTaxRate:P2}");
ImportsIronXL' Load workbook containing various numeric formatsDim workBook AsWorkBook = WorkBook.Load("financial-data.xlsx")Dim salesSheet AsWorkSheet = workBook.GetWorkSheet("Q4Sales")' Calculate total revenue from currency-formatted cellsDim totalRevenue AsDecimal = salesSheet("B2:B50").Sum()Console.WriteLine($"Total Q4 Revenue: {totalRevenue:N2}")' Find the highest individual sale amountDim maxSale AsDecimal = salesSheet("B2:B50").Max()Console.WriteLine($"Largest Sale: {maxSale:N2}")' Calculate average sale amountDim avgSale AsDecimal = salesSheet("B2:B50").Avg()Console.WriteLine($"Average Sale: {avgSale:N2}")' Process percentage data (e.g., tax rates)Dim avgTaxRate AsDecimal = salesSheet("D2:D50").Avg()Console.WriteLine($"Average Tax Rate: {avgTaxRate:P2}")
Imports IronXL
' Load workbook containing various numeric formats
Dim workBook As WorkBook = WorkBook.Load("financial-data.xlsx")
Dim salesSheet As WorkSheet = workBook.GetWorkSheet("Q4Sales")
' Calculate total revenue from currency-formatted cells
Dim totalRevenue As Decimal = salesSheet("B2:B50").Sum()
Console.WriteLine($"Total Q4 Revenue: {totalRevenue:N2}")
' Find the highest individual sale amount
Dim maxSale As Decimal = salesSheet("B2:B50").Max()
Console.WriteLine($"Largest Sale: {maxSale:N2}")
' Calculate average sale amount
Dim avgSale As Decimal = salesSheet("B2:B50").Avg()
Console.WriteLine($"Average Sale: {avgSale:N2}")
' Process percentage data (e.g., tax rates)
Dim avgTaxRate As Decimal = salesSheet("D2:D50").Avg()
Console.WriteLine($"Average Tax Rate: {avgTaxRate:P2}")
using IronXL;WorkBook workBook = WorkBook.Load("quarterly-report.xlsx");WorkSheet dataSheet = workBook.DefaultWorkSheet;// Calculate sum for entire column (e.g., all sales data)decimal columnTotal = dataSheet.GetColumn(1).Sum(); // Column B// Calculate average for entire row (e.g., monthly averages)decimal rowAverage = dataSheet.GetRow(4).Avg(); // Row 5// Work with multiple columns simultaneouslyfor (int col = 1; col <= 12; col++) // Columns B through M{ decimal monthlyTotal = dataSheet.GetColumn(col).Sum();Console.WriteLine($"Month {col} Total: ${monthlyTotal:N2}");}// Calculate grand total across multiple rangesvar q1Range = dataSheet["B2:D50"];var q2Range = dataSheet["E2:G50"];decimal firstHalfTotal = q1Range.Sum() + q2Range.Sum();
using IronXL;
WorkBook workBook = WorkBook.Load("quarterly-report.xlsx");
WorkSheet dataSheet = workBook.DefaultWorkSheet;
// Calculate sum for entire column (e.g., all sales data)
decimal columnTotal = dataSheet.GetColumn(1).Sum(); // Column B
// Calculate average for entire row (e.g., monthly averages)
decimal rowAverage = dataSheet.GetRow(4).Avg(); // Row 5
// Work with multiple columns simultaneously
for (int col = 1; col <= 12; col++) // Columns B through M
{
decimal monthlyTotal = dataSheet.GetColumn(col).Sum();
Console.WriteLine($"Month {col} Total: ${monthlyTotal:N2}");
}
// Calculate grand total across multiple ranges
var q1Range = dataSheet["B2:D50"];
var q2Range = dataSheet["E2:G50"];
decimal firstHalfTotal = q1Range.Sum() + q2Range.Sum();
ImportsIronXLDim workBook AsWorkBook = WorkBook.Load("quarterly-report.xlsx")Dim dataSheet AsWorkSheet = workBook.DefaultWorkSheet' Calculate sum for entire column (e.g., all sales data)Dim columnTotal AsDecimal = dataSheet.GetColumn(1).Sum() ' Column B' Calculate average for entire row (e.g., monthly averages)Dim rowAverage AsDecimal = dataSheet.GetRow(4).Avg() ' Row 5' Work with multiple columns simultaneouslyFor col AsInteger = 1 To 12 ' Columns B through M Dim monthlyTotal AsDecimal = dataSheet.GetColumn(col).Sum()Console.WriteLine($"Month {col} Total: ${monthlyTotal:N2}")Next' Calculate grand total across multiple rangesDim q1Range = dataSheet("B2:D50")Dim q2Range = dataSheet("E2:G50")Dim firstHalfTotal AsDecimal = q1Range.Sum() + q2Range.Sum()
Imports IronXL
Dim workBook As WorkBook = WorkBook.Load("quarterly-report.xlsx")
Dim dataSheet As WorkSheet = workBook.DefaultWorkSheet
' Calculate sum for entire column (e.g., all sales data)
Dim columnTotal As Decimal = dataSheet.GetColumn(1).Sum() ' Column B
' Calculate average for entire row (e.g., monthly averages)
Dim rowAverage As Decimal = dataSheet.GetRow(4).Avg() ' Row 5
' Work with multiple columns simultaneously
For col As Integer = 1 To 12 ' Columns B through M
Dim monthlyTotal As Decimal = dataSheet.GetColumn(col).Sum()
Console.WriteLine($"Month {col} Total: ${monthlyTotal:N2}")
Next
' Calculate grand total across multiple ranges
Dim q1Range = dataSheet("B2:D50")
Dim q2Range = dataSheet("E2:G50")
Dim firstHalfTotal As Decimal = q1Range.Sum() + q2Range.Sum()
What are the benefits of using IronXL for Excel automation?
IronXL streamlines Excel automation by providing simple, effective functions for data analysis, efficient handling of large datasets, and compatibility with various numeric formats, all without requiring Microsoft Excel to be installed.
Can IronXL work with entire columns or rows for aggregation?
Yes, IronXL allows aggregation of entire columns or rows using its math functions. You can calculate totals or averages for complete columns or rows, making it easy to work with structured datasets.
How do I perform calculations across multiple Excel ranges in IronXL?
IronXL allows combining multiple ranges for comprehensive calculations. By summing results from different ranges, such as `firstHalfTotal = q1Range.Sum() + q2Range.Sum();`, you can aggregate data across diverse selections.
What additional features does IronXL offer for Excel manipulation?
Apart from math functions, IronXL features capabilities like creating charts, applying conditional formatting, and exporting to various file formats, making it a versatile tool for comprehensive Excel automation.