Created
October 23, 2023 06:53
-
-
Save fileformat-cells-gists/65f165dc2d09e35222991eb175894119 to your computer and use it in GitHub Desktop.
Set Document Properties 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
// 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"); | |
Cell cellA2 = firstSheet.Cells["A2"]; | |
cellA2.PutValue("Text A2"); | |
// Configure document properties. | |
var newProperties = new BuiltInDocumentProperties | |
{ | |
Author = "Fahad Adeel", | |
Title = "Sample Workbook", | |
CreatedDate = DateTime.Now, | |
ModifiedBy = "Fahad", | |
ModifiedDate = DateTime.Now.AddHours(1), | |
Subject = "Testing Subject" | |
}; | |
// Assign the new properties to the workbook. | |
workbook.BuiltinDocumentProperties = newProperties; | |
// Save the workbook to the specified path. | |
workbook.Save(filePath); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment