Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fileformat-cells-gists/7bfc553e52be147bb97b7bd2a8a757e6 to your computer and use it in GitHub Desktop.
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.
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