Created
February 14, 2024 10:52
-
-
Save fileformat-cells-gists/7bfc553e52be147bb97b7bd2a8a757e6 to your computer and use it in GitHub Desktop.
This C# example demonstrates how to select a specific range within an Excel worksheet and set the same value to all cells within that range using the FileFormat.Cells library.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using FileFormat.Cells; | |
// Load the workbook from the specified file path | |
using (Workbook wb = new Workbook(filePath)) | |
{ | |
// Access the first worksheet in the workbook | |
Worksheet firstSheet = wb.Worksheets[0]; | |
// Select a range within the worksheet | |
var range = firstSheet.GetRange("A1", "B10"); | |
Console.WriteLine($"Column count: {range.ColumnCount}"); | |
Console.WriteLine($"Row count: {range.RowCount}"); | |
// Set a similar value to all cells in the selected range | |
range.SetValue("Hello"); | |
// Save the changes back to the workbook | |
wb.Save(filePath); | |
Console.WriteLine("Value set to range and workbook saved successfully."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment