Skip to content

Instantly share code, notes, and snippets.

View openize-cells-gists's full-sized avatar

openize-cells-gists

View GitHub Profile
@openize-cells-gists
openize-cells-gists / add-value-to-cell-in-a-workbook.cs
Created May 22, 2024 12:50
Assigning Cell Values to a Workbook in C#
string filePath = "/Users/fahadadeelqazi/Downloads/spreadsheet.xlsx";
using (Workbook wb = new Workbook(filePath))
{
Worksheet firstSheet = wb.Worksheets[1];
Cell cell = firstSheet.Cells["D2"];
cell.PutValue("Fahad");
wb.Save();
}
@openize-cells-gists
openize-cells-gists / get-value-from-cell-in-a-workbook.cs
Created May 22, 2024 12:50
Getting Cell Values from a Workbook in C#
using (Workbook wb = new Workbook(filePath)) // Load existing spreadsheet/workbook file.
{
Worksheet firstSheet = wb.Worksheets[0]; // Load first worksheet within workbook.
Cell cellA1 = firstSheet.Cells["A1"]; // Get A1 cell object within cellA1 variable.
Console.WriteLine(cellA1.GetDataType()); // Output cellA1 data type.
string value = cellA1.GetValue(); // Get value within cell A1.
Console.WriteLine(value); // Output the value stored in cell A1
}
@openize-cells-gists
openize-cells-gists / add-formula-to-cells.cs
Created May 22, 2024 12:51
Adding Formulas to Cells in a Workbook in C#
// This example demonstrates how to add formulas to cells in a workbook.
using (Workbook wb = new Workbook())
{
// Accessing the first worksheet in the workbook.
Worksheet firstSheet = wb.Worksheets[0];
// Create a random number generator.
Random rand = new Random();
// Loop through the first 10 rows in column A.
@openize-cells-gists
openize-cells-gists / set-document-properties-to-a-workbook.cs
Created May 22, 2024 12:52
Set Document Properties to a Workbook in C#
// Create a new workbook and set cell values and document properties.
using (var workbook = new Workbook())
{
// Access the first worksheet.
Worksheet firstSheet = workbook.Worksheets[0];
// Set values for cells A1 and A2.
Cell cellA1 = firstSheet.Cells["A1"];
cellA1.PutValue("Text A1");
@openize-cells-gists
openize-cells-gists / get-document-properties-to-a-workbook.cs
Created May 22, 2024 12:53
Get Document Properties to a Workbook in C#
// Open the existing workbook.
using (var workbook = new Workbook(filePath))
{
// Retrieve and display the document properties.
var properties = workbook.BuiltinDocumentProperties;
DisplayProperties(properties);
}
// Helper method to display document properties.
static void DisplayProperties(BuiltInDocumentProperties properties)
@openize-cells-gists
openize-cells-gists / add-worksheet-to-workbook.cs
Created May 22, 2024 12:53
Add Worksheet to a Workbook in C#
string filePath = "/path/to/existing/spreadsheet.xlsx"; // Replace with the path to your file
// Open the existing workbook.
using (var workbook = new Workbook(filePath))
{
// Add a new worksheet to the workbook.
Worksheet newSheet = workbook.AddSheet("NewWorksheetName"); // Replace 'NewWorksheetName' with the desired name
// You can also add some content to the new worksheet if needed.
Cell cellA1 = newSheet.Cells["A1"];
@openize-cells-gists
openize-cells-gists / remove-sheet-from-a-workbook
Created May 22, 2024 12:54
Remove Worksheet from a Workbook in C#
using Openize.Cells;
class Program
{
static void Main(string[] args)
{
string filePath = "Z:\\Downloads\\test_spreadsheet.xlsx"; // Replace with the path to your file
using (var workbook = new Workbook(filePath))
{
@openize-cells-gists
openize-cells-gists / protect-worksheet-in-a-workbook.cs
Created May 22, 2024 12:54
Protect a Sheet in a Workbook in C#
using Openize.Cells;
class Program
{
static void Main(string[] args)
{
string filePath = "Z:\\Downloads\\test_spreadsheet.xlsx"; // Replace with the path to your file
using (var workbook = new Workbook(filePath))
{
@openize-cells-gists
openize-cells-gists / un-protect-all-worksheets-with-in-a-workbook.cs
Created May 22, 2024 12:55
Un-Protect all worksheets with in a Workbook in C#
using Openize.Cells;
class Program
{
static void Main(string[] args)
{
// Define the path to the existing spreadsheet
string filePath = "Z:\\Downloads\\test_spreadsheet.xlsx";
// Open the existing workbook specified by the filePath
@openize-cells-gists
openize-cells-gists / add-default-style-to-workbook.cs
Created May 22, 2024 12:56
Add Default Style to a Workbook in C#
// Import necessary namespace
using Openize.Cells;
class Program
{
static void Main(string[] args)
{
// Define the path to the existing spreadsheet
string filePath = "Z:\\Downloads\\test_spreadsheet1.xlsx";