none
How to reference Excel 2010 template project in my ViewModel RRS feed

  • Question

  • Hi,

    I have 3 separate projects :

    • Excel 2010 template project
    • Class Library project
    • WPF Application project

    Excel 2010 template project hosts wpf user controls developed in WPF Application project. Those controls use command bindings to Class Library project which contains my ViewModels. When user clicks on button on hosted WPF control in Excel 2010 template project ViewModel generating BindingList.

    Now I need to show content of generated BindingList on Excel worksheet in Excel 2010 template project by using ListObject.

    Can anyone provide me with instructions or even better with example or solution to my problem in order to make this working OK.

     Thank you in advance.

    Almir

    Wednesday, February 4, 2015 8:06 AM

Answers

  • Hi,

    >> This generate different Name every time when end user re-generate data from ViewModel in the same worksheet.

    I’m not sure if I understand your requirement correctly. From your code, I think you were trying to refresh the data in Excel table from the ViewModel. If so, instead of inserting a new list object every time, you could just set a binding list once.

    Here is sample project for your reference.

    # Sample on OneDrive

    Hope it will help.

    Regards,

    Jeffrey


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, February 6, 2015 11:41 PM
    Moderator

All replies

  • Hi Almir,

    You can not reference the Excel Template Project in the Class Library project. But you could reference the Excel Object Model in your Class Library project.

    Wednesday, February 4, 2015 11:53 AM
  • Hi,

    thank you for your reply. In order to solve problem, I have build the same WPF user controls in Excel 2010 template and pass DataContext behind working sheet in order to populate ListObject and show data in Excel datagrid.

    Here is how I did it

    private PlanningAreaDimensionDetailsViewModel ViewModel
            {
                get
                {
                    return (PlanningAreaDimensionDetailsViewModel)DataContext;
                }
            }
    
            private void Buton_Clicking(object sender, RoutedEventArgs e)
            {
                Sheet1 ws = (Sheet1)Globals.Sheet1;
                ws.ShowResult(ViewModel);
            }

    I don't like this code behind my button_click (I prefer no code behind) but don't know how to do this differently in Excel templeting. Any proposal will be more than Welcome.

    Also, I have created ShowResult method  behind my Sheet1 and it looks as follows:

    public void ShowResult(PlanningAreaDimensionDetailsViewModel ViewModel)
            {
                PlanningAreaDimensionDetailsViewModel myList = ViewModel;
               
                int ListObjectCount = this.ListObjects.Count;
                this.Columns.Delete();
    
             
                inputTable = Controls.AddListObject(Range["A8", "E11"], ViewModel.SelectedPlanningArea.ToString());
                inputTable.SetDataBinding(myList.PlanningDimensions, string.Empty, null);
            }

    Do you maybe know how can I delete ListObject if already exist the one with the same name? This is where I stuck right now:(

    Sorry for this questions, but I have never before used VSTO. Just trying to reuse my ViewModels and WPF controls in order to provide solution to my boss he asked (he is Excel man and wants Excel as Front)

    Kind regards,

    Almir

    Wednesday, February 4, 2015 2:55 PM
  • Hi AlmirMulahasanovic,

    I am trying to make a simple code to delete ListObject, and there will be some delay in time. I would try my best to figure it out.

    Thanks for your understanding.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.





    Thursday, February 5, 2015 12:02 PM
  • Edward,

    thank you very much for your time and effort.

    I definitely would like to have this working. In order to avoid this problem for now I just pass random number contacanated to string parameter from my ViewModel in order avoid this error. Here is code snippet:

     inputTable = Controls.AddListObject(Range["A8"], ViewModel.SelectedPlanningArea.ToString()+_random.Next().ToString());
    This generate different Name every time when end user re-generate data from ViewModel in the same worksheet.

    Hoping that you will get to the solution. Looking forward to see if you get the one.Thanks one more time. Regards  Almir

    Thursday, February 5, 2015 1:47 PM
  • Hi,

    >> This generate different Name every time when end user re-generate data from ViewModel in the same worksheet.

    I’m not sure if I understand your requirement correctly. From your code, I think you were trying to refresh the data in Excel table from the ViewModel. If so, instead of inserting a new list object every time, you could just set a binding list once.

    Here is sample project for your reference.

    # Sample on OneDrive

    Hope it will help.

    Regards,

    Jeffrey


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, February 6, 2015 11:41 PM
    Moderator