Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fileformat-cells-gists/08ffd2631d271f696a1ef863a17f189d to your computer and use it in GitHub Desktop.
Save fileformat-cells-gists/08ffd2631d271f696a1ef863a17f189d to your computer and use it in GitHub Desktop.
Add Default Style to a Workbook in C#
// Import necessary namespace
using FileFormat.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