Replace

function Replace(
  What: string | "undefined" = null,
  Replacement: string = null,
  LookAt: XlLookAt = null,
  SearchOrder: XlSearchOrder = null,
  SearchDirection: XlSearchDirection = null,
  MatchCase: boolean = null,
  ReplaceAll: boolean = null,
): void

Description

Replaces specific information to another one in a range.

Parameters

Whatstring | "undefined"default: null

The data to search for.

Replacementstringdefault: null

The replacement string.

LookAtXlLookAtdefault: null

Specifies whether the whole search text or any part of the search text is matched.

SearchOrderXlSearchOrderdefault: null

Range search order - by rows or by columns.

SearchDirectionXlSearchDirectiondefault: null

Range search direction - next match or previous match.

MatchCasebooleandefault: null

Case sensitive or not. The default value is "false".

ReplaceAllbooleandefault: null

Specifies if all the found data will be replaced or not. The default value is "true".

Returns

void

Try It

var oWorksheet = Api.GetActiveSheet();
oWorksheet.GetRange("B1").SetValue(2014);
oWorksheet.GetRange("C1").SetValue(2015);
oWorksheet.GetRange("D1").SetValue(2016);
oWorksheet.GetRange("A2").SetValue("Projected Revenue");
oWorksheet.GetRange("A3").SetValue("Estimated Costs");
oWorksheet.GetRange("A4").SetValue("Cost price");
oWorksheet.GetRange("B2").SetValue(200);
oWorksheet.GetRange("B3").SetValue(250);
oWorksheet.GetRange("B4").SetValue(50);
oWorksheet.GetRange("C2").SetValue(200);
oWorksheet.GetRange("C3").SetValue(260);
oWorksheet.GetRange("C4").SetValue(120);
oWorksheet.GetRange("D2").SetValue(200);
oWorksheet.GetRange("D3").SetValue(200);
oWorksheet.GetRange("D4").SetValue(160);
var oRange = oWorksheet.GetRange("A2:D4");
var oReplaceData = {
   What: "200", 
   Replacement: "0",
   LookAt: "xlWhole",
   SearchOrder: "xlByColumns",
   SearchDirection: "xlNext",
   MatchCase: true,
   ReplaceAll: true
};
oRange.Replace(oReplaceData);

Get Help

  • If you have any questions about ONLYOFFICE Docs, try the FAQ section first.
  • You can request a feature or report a bug by posting an issue on GitHub.
  • You can also ask our developers on ONLYOFFICE forum (registration required).