Click or drag to resize

XlsWorksheet Replace Method (String, DataColumn, Boolean)

Replaces cells' values with new data.
Examples
The following code snippet illustrates how to replace the string value with data column:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>workbook.LoadFromFile("Sample.xlsx");</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Replace the oldValue by data column</para><para>string oldValue = "Find";</para><para>System.Data.DataTable table = new System.Data.DataTable();</para><para>table.Columns.Add("Dosage", typeof(int));</para><para>table.Rows.Add(1);</para><para>System.Data.DataColumn dataColumn = table.Columns[0];</para><para>worksheet.Replace(oldValue, dataColumn, true);</para><para>//Save to file</para><para>workbook.SaveToFile("Replace.xlsx");</para>

Namespace: Spire.Xls.Core.Spreadsheet
Assembly: Spire.XLS (in Spire.XLS.dll) Version: 15.4.0.0 (15.4.0.5046)
Syntax
public void Replace(
	string oldValue,
	DataColumn column,
	bool columnHeaders
)

Parameters

oldValue
Type: System String
String value to replace.
column
Type: System.Data DataColumn
Data table with new data.
columnHeaders
Type: System Boolean
Indicates whether to import field names.

Implements

IWorksheet Replace(String, DataColumn, Boolean)
Remarks
This can be long operation (needs iteration through all cells in the worksheet). Better use named ranges instead and call Import function instead of placeholders.
See Also