How to create slicers using open xml in C#

Caroll Susairaj 1 Reputation point
2021-06-15T12:55:48.86+00:00

I could able to create a pivot table using openxml C# but unable to find a way on linking slicers using C#. Can some one help me on this.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,848 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,856 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Nancy Wang 116 Reputation points Microsoft Employee
    2021-06-15T17:15:52.093+00:00

    Hi @Caroll Susairaj ! Your question doesn't appear to be related to Office Scripts - could you remove the 'office-scripts-excel-dev' tag? Thank you so much!

    Warmly,
    Nancy

    0 comments No comments

  2. Timon Yang-MSFT 9,591 Reputation points
    2021-06-16T06:27:20.933+00:00

    Could you please show some existing code? Let us move on based on your code.

    Besides, can we use other packages?

    I often use Microsoft.Office.Interop.Excel, here are some codes written in this package:

                Application application = new Application();  
                Workbook oWorkbook = application.Workbooks.Open(@"C:\...\1.xlsx");  
                try  
                {  
                    Worksheet oWorksheet = (Worksheet)oWorkbook.ActiveSheet;  
      
                    SlicerCaches oSlicerCaches = oWorkbook.SlicerCaches;  
      
                    SlicerCache slicerCache = oSlicerCaches.Add2(oWorksheet.ListObjects["Table1"], "Column1", "mSlicer");  
                slicerCache.Slicers.Add(oWorksheet, System.Reflection.Missing.Value, "Column1", "testSlicer", 100,  
                    400, 150, 200);  
                }  
                catch (Exception e)  
                {  
                    Console.WriteLine(e);  
                }  
                finally   
                {  
                    oWorkbook.Save();  
                    oWorkbook.Close();  
                    application.Quit();  
                }  
    

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.