Created
May 22, 2024 12:56
-
-
Save openize-cells-gists/1e187d8496bcf55823dd6699b6a351d9 to your computer and use it in GitHub Desktop.
Add Default Style to a Workbook in C#
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
// 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"; | |
// Open the existing workbook specified by the filePath | |
using (Workbook wb = new Workbook()) | |
{ | |
// Update the default style for the workbook: | |
// Set font to Arial, font size to 12, and font color to the hex code "A02000" (a shade of red) | |
wb.UpdateDefaultStyle("Arial", 12, "A02000"); | |
// Get the first worksheet from the workbook | |
Worksheet firstSheet = wb.Worksheets[0]; | |
// Add values to the cells A1 to A3 with the new default style | |
firstSheet.Cells["A1"].PutValue("Hello, World!"); | |
firstSheet.Cells["A2"].PutValue("Default Style Applied!"); | |
firstSheet.Cells["A3"].PutValue("Check Font & Color."); | |
// Save the changes made to the new workbook. | |
wb.Save(filePath); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment