Class WorkbookDesigner

Class WorkbookDesigner

Namespace: Aspose.Cells
Assembly: Aspose.Cells.dll (25.2.0)

Encapsulates the object that represents a designer spreadsheet.

public class WorkbookDesigner

Inheritance

objectWorkbookDesigner

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Examples

//Create WorkbookDesigner object.
WorkbookDesigner wd = new WorkbookDesigner();
//Open the template file (which contains smart markers).
wd.Workbook = new Workbook("SmartMarker_Designer.xls");

//Initialize your data from data source
//DataSet ds = new DataSet();
//...

//Set the datatable as the data source.
//wd.SetDataSource(dt);
//Process the smart markers to fill the data into the worksheets.
wd.Process(true);
//Save the excel file.
wd.Workbook.Save("outSmartMarker_Designer.xls");</code></pre>

## Constructors

### <a id="Aspose_Cells_WorkbookDesigner__ctor"></a> WorkbookDesigner\(\)

Initializes a new instance of the Aspose.Cells.WorkbookDesigner class.

```csharp
public WorkbookDesigner()

WorkbookDesigner(Workbook)

Initializes a new instance of the Aspose.Cells.WorkbookDesigner class.

public WorkbookDesigner(Workbook workbook)

Parameters

workbook Workbook

The template workbook file.

Properties

CalculateFormula

Indicates whether formulas should be calculated.

public bool CalculateFormula { get; set; }

Property Value

bool

CallBack

Gets and sets callback interface of processing smartmarker.

public ISmartMarkerCallBack CallBack { get; set; }

Property Value

ISmartMarkerCallBack

LineByLine

Indicates whether processing the smart marker line by line.

public bool LineByLine { get; set; }

Property Value

bool

Remarks

The default value is true. If False, the template file must contain a range which is named as “_CellsSmartMarkers”.

RepeatFormulasWithSubtotal

Indicates whether repeating formulas with subtotal row.

public bool RepeatFormulasWithSubtotal { get; set; }

Property Value

bool

UpdateEmptyStringAsNull

If TRUE, Null will be inserted if the value is “”;

public bool UpdateEmptyStringAsNull { get; set; }

Property Value

bool

UpdateReference

Indicates if references in other worksheets will be updated.

public bool UpdateReference { get; set; }

Property Value

bool

Workbook

Gets and sets the Aspose.Cells.WorkbookDesigner.Workbook object.

public Workbook Workbook { get; set; }

Property Value

Workbook

Methods

ClearDataSource()

Clears all data sources.

public void ClearDataSource()

GetSmartMarkers()

Returns a collection of smart markers in a spreadsheet.

public string[] GetSmartMarkers()

Returns

string[]

A collection of smart markers

Remarks

A string array is created on every call. The array is sorted and duplicated values are removed.

Process()

Processes the smart markers and populates the data source values.

public void Process()

Process(bool)

Processes the smart markers and populates the data source values.

public void Process(bool isPreserved)

Parameters

isPreserved bool

True if the unrecognized smart marker is preserved.

Process(int, bool)

Processes the smart markers and populates the data source values.

public void Process(int sheetIndex, bool isPreserved)

Parameters

sheetIndex int

Worksheet index.

isPreserved bool

True if the unrecognized smart marker is preserved.

Remarks

This method works on worksheet level.

SetDataSource(string, ICellsDataTable)

Sets data source of a Aspose.Cells.ICellsDataTable object.

public void SetDataSource(string dataSource, ICellsDataTable cellsDataTable)

Parameters

dataSource string

The name of the data source.

cellsDataTable ICellsDataTable

data table.

SetDataSource(DataSet)

Sets data source of a DataSet object.

public void SetDataSource(DataSet dataSet)

Parameters

dataSet DataSet

DataSet object

Examples

[C#]

//Create a connection object, specify the provider info and set the data source.
OleDbConnection con = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=Northwind.mdb");
//Open the connection object.
con.Open();
//Create a command object and specify the SQL query.
OleDbCommand cmd = new OleDbCommand("Select * from [Order Details]", con);
//Create a data adapter object.
OleDbDataAdapter da = new OleDbDataAdapter();
//Specify the command.
da.SelectCommand = cmd;
//Create a dataset object.
DataSet ds = new DataSet();
//Fill the dataset with the table records.
da.Fill(ds, "Order Details");
//Create a datatable with respect to dataset table.
DataTable dt = ds.Tables["Order Details"];
//Create WorkbookDesigner object.
WorkbookDesigner wd = new WorkbookDesigner();
//Open the template file (which contains smart markers).
wd.Workbook = new Workbook("SmartMarker_Designer.xls");
//Set the datatable as the data source.
wd.SetDataSource(dt);
//Process the smart markers to fill the data into the worksheets.
wd.Process(true);
//Save the excel file.
wd.Workbook.Save("outSmartMarker_Designer.xls");
```
```vb
'Create a connection object, specify the provider info and set the data source.
Dim con As OleDbConnection = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=Northwind.mdb")
'Open the connection object.
con.Open()
'Create a command object and specify the SQL query.
Dim cmd As OleDbCommand = New OleDbCommand("Select * from [Order Details]", con)
'Create a data adapter object.
Dim da As OleDbDataAdapter = New OleDbDataAdapter()
'Specify the command.
da.SelectCommand = cmd
'Create a dataset object.
Dim ds As DataSet = New DataSet()
'Fill the dataset with the table records.
da.Fill(ds, "Order Details")
'Create a datatable with respect to dataset table.
Dim dt As DataTable = ds.Tables("Order Details")
'Create WorkbookDesigner object.
Dim wd As WorkbookDesigner = New WorkbookDesigner()
'Open the template file (which contains smart markers).
Dim workbook As Workbook = New Workbook("SmartMarker_Designer.xls")
wd.Workbook = workbook
'Set the datatable as the data source.
wd.SetDataSource(dt)
'Process the smart markers to fill the data into the worksheets.
wd.Process(True)
'Save the excel file.
wd.Workbook.Save("outSmartMarker_Designer.xls")
```

###  SetDataSource\(DataTable\)

Sets data source of a DataTable object.

```csharp
public void SetDataSource(DataTable dataTable)
```

#### Parameters

`dataTable` [DataTable](https://learn.microsoft.com/dotnet/api/system.data.datatable)

DataTable object

###  SetDataSource\(string, DataView\)

Sets data source of a DataView object and binds it to a data source name.

```csharp
public void SetDataSource(string dataSourceName, DataView dataView)
```

#### Parameters

`dataSourceName` [string](https://learn.microsoft.com/dotnet/api/system.string)

Data source name.

`dataView` [DataView](https://learn.microsoft.com/dotnet/api/system.data.dataview)

DataView object.

###  SetDataSource\(DataView\)

Sets data source of a DataView object.

```csharp
public void SetDataSource(DataView dataView)
```

#### Parameters

`dataView` [DataView](https://learn.microsoft.com/dotnet/api/system.data.dataview)

DataView object

###  SetDataSource\(string, IDataReader, int\)

Sets data source of a IDataReader object.

```csharp
public void SetDataSource(string name, IDataReader dataReader, int rowCount)
```

#### Parameters

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The data source map name.

`dataReader` [IDataReader](https://learn.microsoft.com/dotnet/api/system.data.idatareader)

IDataReader object

`rowCount` [int](https://learn.microsoft.com/dotnet/api/system.int32)

The number of the data rows.
            If the smart marker does not contains "noadd",
            we have to insert rows by the row count for performance issue and dynamic repeated formulas.
            -1 means the param is useless.

###  SetDataSource\(string, object\)

Sets data binding to a variable.

```csharp
public void SetDataSource(string variable, object data)
```

#### Parameters

`variable` [string](https://learn.microsoft.com/dotnet/api/system.string)

Variable name created using smart marker.

`data` [object](https://learn.microsoft.com/dotnet/api/system.object)

Source data.

###  SetJsonDataSource\(string, string\)

```csharp
public void SetJsonDataSource(string variable, string data)
```

#### Parameters

`variable` [string](https://learn.microsoft.com/dotnet/api/system.string)

`data` [string](https://learn.microsoft.com/dotnet/api/system.string)