# Write Excel

This script will require adding **using OfficeOpenXml;** to the namespaces section.

```csharp
ExcelWorksheet document = excelDocument.getWorkSheet(1);

for (int i=1;i<=NumberOfRows;i++)
{                               
      document.Cells[i, 1].Value=givenValue;
}
```

{% hint style="info" %}
The ExcelWorksheet variable has to be open using the “Open excel workbook” action before initializing the C# script, otherwise it will not be a valid reference to an Excel Workbook.

After the C# script action, use “Close excel workbook” to save the changes made.

{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tailent.com/scripting-utility-classes/common-scripts-repository/c-scripts-repository/write-excel.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
