Click or drag to resize

XlsWorksheet Replace Method (String, DataTable, Boolean)

Replaces cells' values with new data.
Examples
The following code snippet illustrates how to replace the string value with data table:
<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 table</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>worksheet.Replace(oldValue, table, 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,
	DataTable newValues,
	bool columnHeaders
)

Parameters

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

Implements

IWorksheet Replace(String, DataTable, 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