Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fileformat-cells-gists/b1106413ee7a364314969f46567b4c04 to your computer and use it in GitHub Desktop.
Save fileformat-cells-gists/b1106413ee7a364314969f46567b4c04 to your computer and use it in GitHub Desktop.
This C# example illustrates how to add comments in Google Sheets / Excel Spread sheet using the FileFormat.Cells library.
// Define the directory where files are stored
string outputDirectory = "Z:\\Downloads\\";
// Specify the path to the Excel file
string filePath = "Z:\\Downloads\\testFile1.xlsx";
// Open the workbook located at the specified file path
using (Workbook wb = new Workbook(filePath))
{
// Access the first worksheet in the workbook
Worksheet firstSheet = wb.Worksheets[0];
// Define the cell reference where the comment will be added
string cellReference = "B10";
// Retrieve the cell at the specified reference
Cell cell = firstSheet.Cells[cellReference];
// Set a new value for the cell
cell.PutValue("randomValue");
// Create a new comment with author and text
Comment myComment = new Comment("John Doe", "This is a test comment.");
// Add the comment to the specified cell in the worksheet
firstSheet.AddComment(cellReference, myComment);
// Save the workbook with all changes to the same file
wb.Save(filePath);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment