Skip to content

AutoFill.cs

Avrigeanu Laurian edited this page Apr 12, 2023 · 1 revision

AutoFill (object sheet, string range, int lastRow)

Parameters

  • sheet : The sheet name or index where the range is located.
  • range : The range to be autofilled. The range should be in A1 reference style, e.g. "A1:B10".
  • lastRow : The last row to autofill.

Returns

A boolean value indicating whether the autofill operation was successful.

Remarks

This method is used to autofill a range in Microsoft Excel. It takes in three parameters:

  • sheet: the name or index of the sheet where the range is located.
  • range: the range to be autofilled in A1 reference style, e.g. "A1:B10".
  • lastRow: the last row to autofill.

The method first splits the range parameter by ":" and extracts the second part of the range. Then it replaces all the numbers in the second part of the range with an empty string using a regular expression. This is done to get the column letter(s) of the last column in the range.

The method then uses the Microsoft.Office.Interop.Excel.Range.AutoFill method to autofill the range. It uses the xlFillCopy option to autofill the range. The method returns true if the autofill operation was successful.

Clone this wiki locally