예제 #1
0
        /// <summary>
        /// Crear una tabla pivot.
        /// <param name="hoja_tabla">Número de la hoja a la que se agregará la tabla pivot</param>
        /// <param name="nombre_campo_fila">Nombre del campo de fila</param>
        /// <param name="nombre_campo_datos">Nombre del campo de datos</param>
        /// </summary>
        public override void crearTablaPivot(string hoja_tabla, string nombre_campo_fila, string nombre_campo_datos)
        {
            XlPivotTableSourceType  fuente            = XlPivotTableSourceType.xlDatabase;
            XlPivotFieldOrientation orientacion_fila  = XlPivotFieldOrientation.xlRowField;
            XlPivotFieldOrientation orientacion_datos = XlPivotFieldOrientation.xlDataField;

            // Crear la tabla pivot

            _hoja = (Worksheet)_libro.Worksheets[hoja_tabla];

            _hoja.PivotTableWizard(fuente, _seleccionado, _missing, "PivTab1");

            PivotTable tabla       = (PivotTable)_hoja.PivotTables("PivTab1");
            PivotField campo_fila  = ((PivotField)tabla.PivotFields(nombre_campo_fila));
            PivotField campo_datos = ((PivotField)tabla.PivotFields(nombre_campo_datos));

            campo_fila.Orientation  = orientacion_fila;
            campo_datos.Orientation = orientacion_datos;
        }
예제 #2
0
 /// <summary>
 /// Creates a new PivotCache.
 /// </summary>
 /// <param name="SourceType">SourceType can be one of these XlPivotTableSourceType constants: xlConsolidation, xlDatabase, or xlExternal.</param>
 /// <param name="SourceData">The data for the new PivotTable cache.</param>
 /// <param name="Version">Version of the PivotTable. Version can be one of the XlPivotTableVersionList constants.</param>
 public PivotCache Create(XlPivotTableSourceType SourceType, object SourceData, XlPivotTableVersionList Version)
 {
     return(new PivotCache(InternalObject.GetType().InvokeMember("Create", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, ComArguments.Prepare(SourceType, SourceData, Version))));
 }
        /// <summary>创建一个新的数据透视表。此方法不显示“数据透视表向导”,它不适用于 OLE DB 数据源。请使用 Add 方法添加数据透视表缓存,然后创建基于该缓存的数据透视表。
        /// </summary>
        /// <param name="SourceType">一个代表报表数据源的 XlPivotTableSourceType 值。如果指定了此参数,那么必须同时指定 SourceData。如果忽略 SourceType 和 SourceData,Microsoft Excel 将假定源类型为 xlDatabase,并假定源数据来自命名区域“Database”。如果该命名区域不存在,那么当选定区域所在的当前区域中包含数据的单元格超过 10 个时,Microsoft Excel 就使用当前区域。否则,此方法将失败。</param>
        /// <param name="SourceData">新报表的数据。它可以是一个 Range 对象、一个区域数组或是代表其他报表名称的一个文本常量。对于外部数据库而言,SourceData 是一个包含 SQL 查询字符串的字符串数组,其中的每个元素最长为 255 个字符。您应该使用 Connection 参数指定 ODBC 连接字符串。为了能与旧版本的 Excel 兼容,SourceData 可以是一个二元数组。第一个元素是用于指定数据的 ODBC 源的连接字符串,第二个元素是用于获取数据的 SQL 查询字符串。如果指定 SourceData,则必须同时指定 SourceType。如果活动单元格位于 SourceData 区域内,则必须同时指定 TableDestination。</param>
        /// <param name="TableDestination">一个 Range 对象,它指定报表在工作表中的位置。如果省略此参数,则将报表置于活动单元格中。</param>
        /// <param name="TableName">用于指定新报表名称的字符串。</param>
        /// <param name="RowGrand">如果为 True,则显示报表中的行总计。</param>
        /// <param name="ColumnGrand">如果为 True,则显示报表中的列总计。</param>
        /// <param name="SaveData">如果为 True,则保存报表中的数据。如果为 False,则仅保存报表的定义。</param>
        /// <param name="HasAutoFormat">如果为 True,当刷新报表或移动字段时,Microsoft Excel 将自动设置其格式。</param>
        /// <param name="AutoPage">仅当 SourceType 为 xlConsolidation 时有效。如果值为 True,Microsoft Excel 将为合并创建页字段。如果 AutoPage 为 False,则必须创建一个或多个页字段。</param>
        /// <param name="Reserved">不在 Microsoft Excel 中使用。</param>
        /// <param name="BackgroundQuery">如果为 True,则 Excel 将异步执行(后台执行)报表查询。默认值为 False。</param>
        /// <param name="OptimizeCache">如果为 True,则在构造数据透视表的缓存时对其进行优化。默认值为 False。</param>
        /// <param name="PageFieldOrder">在数据透视表布局中添加页字段的顺序。可为以下 XlOrder 常量之一:xlDownThenOver 或 xlOverThenDown。默认值为 xlDownThenOver。</param>
        /// <param name="PageFieldWrapCount">数据透视表中每列或每行的页字段数。默认值为 0(零)。</param>
        /// <param name="ReadData">如果为 True,则创建数据透视表缓存以包含外部数据库中的所有记录;此时缓存可能会很大。如果 ReadData 为 False,则可在实际读取数据之前,将某些字段设为基于服务器的页字段。</param>
        /// <param name="Connection">包含 ODBC 设置的字符串,这些设置使得 Excel 可以连接 ODBC 数据源。连接字符串的格式为“ODBC;<连接字符串>”。该参数取代以前为 PivotCache 对象的 Connection 属性所做的任何设置。</param>
        public PivotTable PivotTableWizard(XlPivotTableSourceType? SourceType = null, object SourceData = null, Range TableDestination = null, string TableName = null, bool? RowGrand = null, bool? ColumnGrand = null, bool? SaveData = null, bool? HasAutoFormat = null, bool? AutoPage = null, object Reserved = null, bool? BackgroundQuery = null, bool? OptimizeCache = null, XlOrder? PageFieldOrder = null, int? PageFieldWrapCount = null, bool? ReadData = null, string Connection = null)
        {
            _objaParameters = new object[16] {
                SourceType == null ? System.Type.Missing : SourceType,
                SourceData == null ? System.Type.Missing : SourceData,
                TableDestination == null ? System.Type.Missing : TableDestination._objRange,
                TableName == null ? System.Type.Missing : TableName,
                RowGrand == null ? System.Type.Missing : RowGrand,
                ColumnGrand == null ? System.Type.Missing : ColumnGrand,
                SaveData == null ? System.Type.Missing : SaveData,
                HasAutoFormat == null ? System.Type.Missing : HasAutoFormat,
                AutoPage == null ? System.Type.Missing : AutoPage,
                Reserved == null ? System.Type.Missing : Reserved,
                BackgroundQuery == null ? System.Type.Missing : BackgroundQuery,
                OptimizeCache == null ? System.Type.Missing : OptimizeCache,
                PageFieldOrder == null ? System.Type.Missing : PageFieldOrder,
                PageFieldWrapCount == null ? System.Type.Missing : PageFieldWrapCount,
                ReadData == null ? System.Type.Missing : ReadData,
                Connection == null ? System.Type.Missing : Connection
            };

            return new PivotTable(_objWorksheet.GetType().InvokeMember("PivotTableWizard", BindingFlags.InvokeMethod, null, _objWorksheet, _objaParameters));
        }