Developer forum

Forum » Development » Using GENERIC EXCEL EXPORTER

Using GENERIC EXCEL EXPORTER

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I have found out this functionality for exporting/generating excel documents based on an object.

I think the functionality is pretty useful but I would like to understand a bit more about how it works.

I have read the documentation here: https://doc.dynamicweb.com/other/tools/generic-excel-exporter but I still feel that it needs a bit more clarifications.

I have managed to create an object  (a list of ProductViewModel) that I want to output.

I have created a MasterFile and have defined the location/file that I want to output.

My problem is how to find out the placeholders available to use.

I have created a page that would generate this excel file. I have tried adding ?dwtemplatetags=true but it only outputs the generic tags.

In my Master file I have tried using {Name} and {productList.Name}.

What I think I need to understand is the connection between my object passed to the ExcelWriter (productList in my case) the formula in the excel (Loop({productList}, $2:$3, TRUE) and the Placeholder tag {Name}.

My expectation would be that the placeholder would have to be the name of the property (since I am using ProductViewModel, it can be Name) or it should be an identifier of the row plus the name of the property (in the documentation example it was using {Product_Name}.

For reference, this is how the example looks like (from the documentation site):

Anybody can help me understand this functionality better?

Thank you,
Adrian

 

 

 

 


Replies

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Anybody?

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Did you code your own use of this? And what is your code...?

The format is {object}_{property}

For loops it is Loop({propertyOnBaseObjectThatIsAList})

If you pass in a list<productviewmodel> it has no name.

If you pass a viewmodel base implemenation (named AdriansProductListViewmodel) with a property "List<ProductViewmodel> MyProducts", you will get a loop called "MyProducts"

Votes for this answer: 1
 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Thank you for the answer.

I did code my own code:

List<Dynamicweb.Ecommerce.ProductCatalog.ProductViewModel> productList = new List<Dynamicweb.Ecommerce.ProductCatalog.ProductViewModel>();
var result = new Dynamicweb.Data.ExcelWriter();
string masterFile = "/Files/Files/DocumentareProduse/TemplateImportProduseAX.xlsx";
foreach (System.Data.DataRow dr in dt.Rows)
    {
        string productId = dr[dt.Columns[0]].ToString();
        var productRequest = new ProductViewModelSettings();
        productRequest.EnsureFilledPropertiesExist();
        Dynamicweb.Ecommerce.ProductCatalog.ProductViewModel productModel = ViewModelFactory.CreateView(productRequest, productId);
        productList.Add(productModel);
 }

result.Write(productList, SystemInformation.MapPath(masterFile), SystemInformation.MapPath("/Files/Files/DocumentareProduse/FisierGenerat.xlsx"));

As you can see, I have created a list of ProductViewModel objects which is probably the issue here.

I will have to use your recommendation and create a ProductListViewModel and add the products to the list inside that.

In this case (following your example), my placeholders would be something like {MyProducts_Name}? 

Thank you very much. Maybe it would be good to add this explanation to the documentation as it can help other people use this awesome functionality.

Thank you,

Adrian

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

I confirm that it worked. The placeholders are based on the properties of the object. In this case the ProductViewModel.

This means {Name} instead of {MyProducts_Name}.

Thank you,

Adrian

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

One more thing about the placeholders.

Considering that I am using a list of ProductViewModel in a ProductListViewModel. If I want to use CustomFields in the placeholders, how should I create the placeholders?

Can I use ProductFields_FieldSystemName ?

Thank you,


Adrian

 
Pedro Meias
Pedro Meias
Reply

Hi Adrian,

I am looking for documentation on the excel exported and this post seems to be the best option.

Do you have a working example you can share?

Thank you in advance

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Pedro,

I do. I have attached it here. It has my template (where I create an excel file that can be downloaded) and the master excel file.

I hope it makes sense.

 

 
Pedro Meias
Pedro Meias
Reply

Hi Adrian,

Thank you! this was a great help

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Pedro,

I am happy to hear that.

Adrian

 

You must be logged in to post in the forum