How to use smart markers?

Laurence,
I had a thought last night about trying to use a DataSet object that I would point to any one of the multiple datasets and assign that to the designer and call process. Unfortunately that didn’t work. Being able to clear out the datasource should solve the problem.

What’s the ETA for the next hotfix?

Thanks again.
Dennis



Hi Dennis,

It will be released in next week.

Hi Laurence,
I just recently downloaded the latest hot fix and re-tried my project.
It seems that the ClearDatasource is not working. I tested it by using two datasets. If the two datasets are different dataset instances, then the first worksheet gets populated but not the second. However if I set the datasource to the same dataset twice, then it does work.

Any ideas?

Dennis

Hi Dennis,

Could you elaborate your question and post your code if possible?

Actually ClearDataSource method doesn’t clear data in your dataset. It just clear the data source in ExcelDesigner object.

For example, if you use the following code:

excelDesigner.SetDataSource(myDataSet);

excelDesigner.ClearDataSource();

The data in myDataSet is cleared but it’s removed from excelDesigner object. You can still access the data in myDataSet. However, if you call the excelDesigner.Process method, the data will not be populated into excelDesigner.

Hi Laurence,

First thing that I see is that the below code snippet doesn’t work :

’ note worksheet 0 and 1 already exist
DataSet ds1 = Data.GetDataSet();
DataSet ds2 = ds1.Clone();

excelDesigner.SetDataSource(ds1);
excelDesigner.Process(0, True);
excelDesigner.ClearDataSource();

excelDesigner.SetDataSource(ds2);
excelDesigner.Process(1, True);

The first worksheet gets populated, but the second does not. If I change ds2 so that is not a clone, but another dataset, then it works. This code is really not useful, I was just trying to understand what is going on.

The second problem is that if the worksheet is generated dynamically, then smart tags will not get replaced.



DataSet ds1 = Data.GetDataSet();
DataSet ds2 = ds1.Clone();

’ copy the template worksheet 0
int idx = excelDesigner.Excel.Worksheets.AddCopy(0)


’ process worksheet 1
excelDesigner.SetDataSource(ds1);
excelDesigner.Process(idx, True);
excelDesigner.ClearDataSource();

’ process worksheet 0
excelDesigner.SetDataSource(ds2);
excelDesigner.Process(0, True);

In the above code snippet, there is a pre-existing template worksheet at index 0, it gets copied to index 1. Worksheet(1) is processed first, and then Worksheet(0) is processed. Only worksheet(0) has the smart tags replaced.

Your help, as always, is appreciated,

Dennis.

Hi Dennis,

If your check DataSet.Clone method in MSDN, you can see the following word:

Copies the structure of the DataSet, including all DataTable schemas, relations, and constraints. Does not copy any data.

[Visual Basic]  Overridable Public Function Clone() As DataSet
[C#] [Serializable] public virtual DataSet Clone();
[C++] [Serializable] public: virtual DataSet* Clone();
[JScript] public Serializable function Clone() : DataSet;

Return Value

A new DataSet with the same schema as the current DataSet, but none of the data.


So your ds2 contains no data. And smart markers processing with ds2 will not be replaced. Please check it.

Hi Laurence,

Sorry, I was using that to try and understand what was happening with the set and clear methods.


I will email you a sample project that shows this problem.


Dennis



Hi Dennis,

I found your template file had 4 hidden worksheets. If you use AddCopy method, the added worksheets is always inserted as the last one. So the index of new added worksheet is not 1, but 5. Please verify it.


So please change your code to:

ExcelDesigner excelDesigner = new ExcelDesigner();
excelDesigner.Open("Template.xls");

// add a copy of the first template worksheet
int index1 = excelDesigner.Excel.Worksheets.AddCopy(0);
int index2 = excelDesigner.Excel.Worksheets.AddCopy(0);

// process the three worksheets in sequential fashion
excelDesigner.SetDataSource(ds1);
excelDesigner.Process(0, true);

excelDesigner.ClearDataSource();
excelDesigner.SetDataSource(ds2);
excelDesigner.Process(index1, true);

excelDesigner.ClearDataSource();
excelDesigner.SetDataSource(ds3);
excelDesigner.Process(index2, true);

excelDesigner.Save("result1.xls", Aspose.Excel.FileFormatType.Default);
open("result1.xls");

And your loop code has the same problem.

Thanks Laurence,

that was driving me crazy, never thought to think there were hidden worksheets.

Dennis