当前位置: 首页>>代码示例>>C#>>正文


C# Workbook.PivotCaches方法代码示例

本文整理汇总了C#中Workbook.PivotCaches方法的典型用法代码示例。如果您正苦于以下问题:C# Workbook.PivotCaches方法的具体用法?C# Workbook.PivotCaches怎么用?C# Workbook.PivotCaches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Workbook的用法示例。


在下文中一共展示了Workbook.PivotCaches方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetPowerPivotConnection

        //((dynamic)pc.WorkbookConnection).ModelConnection.ADOConnection.ConnectionString
        // Excel 2013
        //"Provider=MSOLAP.5;Persist Security Info=True;Initial Catalog=Microsoft_SQLServer_AnalysisServices;Data Source=$Embedded$;MDX Compatibility=1;Safety Options=2;MDX Missing Member Mode=Error;Subqueries=0;Optimize Response=7"
        // Excel 2010
        // Provider=MSOLAP.5;Persist Security Info=True;Initial Catalog=Microsoft_SQLServer_AnalysisServices;Data Source=$Embedded$;MDX Compatibility=1;Safety Options=2;MDX Missing Member Mode=Error;ConnectTo=11.0;Optimize Response=3;Cell Error Mode=TextValue;location=\"C:\Users\Test\Documents\Products.xlsx\";Show Hidden Cubes=true"
        /*
        public ADOTabularConnection GetPowerPivotConnection()
        {
            PivotCache pc;
            string connStr;
            var wb = _app.ActiveWorkbook;

            if (IsExcel2013OrLater)
            {
                PivotCaches pvtcaches = wb.PivotCaches();
                pc = (from PivotCache pvtc in pvtcaches
                                 let conn = pvtc.Connection.ToString()
                                 where pvtc.OLAP
                                       && pvtc.CommandType == XlCmdType.xlCmdCube
                                       && (int) pvtc.WorkbookConnection.Type == 7 // xl15Model
                                 select pvtc).First();
                var wbc = ((dynamic)pc.WorkbookConnection);
                var modelCnn = wbc.ModelConnection;

                //var wbkCnn = FindPowerPivotConnection(wb);
                //var modelCnn = wbkCnn.ModelConnection;
                var cnn = modelCnn.ADOConnection;
                connStr = cnn.ConnectionString;
                connStr = string.Format("{0};location=\"{1}\"", connStr, wb.FullName);
                // for connections to Excel 2013 or later we need to use the Excel version of ADOMDClient
                return new ADOTabularConnection(connStr, AdomdType.Excel);
            }
            else
            {
                // Excel 2010
                PivotCaches pvtcaches = wb.PivotCaches();
                pc = (from PivotCache pvtc in pvtcaches
                                 let conn = pvtc.Connection.ToString()
                                 where pvtc.OLAP
                                       && pvtc.CommandType == XlCmdType.xlCmdCube
                                       //&& (int)pvtc.WorkbookConnection.Type == 7
                                 select pvtc).First();
                if (pc == null) pc = CreateHiddenPivotTable(wb);
                var wbc = ((dynamic) pc.WorkbookConnection);
                var oledbCnn = wbc.OLEDBConnection;
                var cnn = oledbCnn.Connection;

                connStr = cnn.Replace("OLEDB;","");
                connStr = string.Format("{0};location=\"{1}\"", connStr, wb.FullName);
                // for connections to Excel 2010 we need to use the AnalysisServices version of ADOMDClient
                return new ADOTabularConnection(connStr, AdomdType.AnalysisServices);
            }
        }
        */
        private PivotCache CreateHiddenPivotTable(Workbook wb)
        {
            Worksheet sht = null;
            try
            {
                sht = wb.Sheets["DaxStudioConnectionHelper"];
            }
            catch { } // swallow any exception if the sheet is not found

            if (sht == null) {
                sht = wb.Sheets.Add();
                sht.Name = "DaxStudioConnectionHelper";
                sht.Visible = XlSheetVisibility.xlSheetVeryHidden;
            }

            //PivotTable pt;
            PivotCaches pivotCaches;
            pivotCaches = wb.PivotCaches();
            var pc = pivotCaches.Create(XlPivotTableSourceType.xlExternal, wb.Connections["PowerPivot Data"], XlPivotTableVersionList.xlPivotTableVersion14);
            pc.CreatePivotTable(sht.Cells[1,1], "DaxStudioConnectionPivot", Type.Missing, XlPivotTableVersionList.xlPivotTableVersion14);
            return pc;

            //pc = wb.PivotCaches.Create(  SourceType= xlExternal, SourceData:= wb.Connections["PowerPivot Data"], Version:=xlPivotTableVersion14)
            //pt = pc.CreatePivotTable(TableDestination:="DaxStudioConnectionHelper!R1C1", TableName:= "DaxStudioConnectionPivotTable", DefaultVersion:=xlPivotTableVersion14);
        }
开发者ID:votrongdao,项目名称:DaxStudio,代码行数:79,代码来源:ExcelHelper.cs


注:本文中的Workbook.PivotCaches方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。