本文整理汇总了C#中Microsoft.Office.Interop.Excel.Workbook.PivotCaches方法的典型用法代码示例。如果您正苦于以下问题:C# Workbook.PivotCaches方法的具体用法?C# Workbook.PivotCaches怎么用?C# Workbook.PivotCaches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Excel.Workbook
的用法示例。
在下文中一共展示了Workbook.PivotCaches方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnAceptar_Click
private void btnAceptar_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
libro = app.Workbooks.Add();
libro.DefaultPivotTableStyle = "PivotStyleLight26";
Excel.PivotCache pivotCache = libro.PivotCaches().Add(Excel.XlPivotTableSourceType.xlExternal);
//string MyConString = ConfigurationManager.ConnectionStrings["ODBCExcel"].ConnectionString;
string MyConString = ConfigurationManager.ConnectionStrings["ODBCExcelLocal"].ConnectionString;
//string MyConString = ConfigurationManager.ConnectionStrings["ODBCMinusculas"].ConnectionString;
string strFecha = dateTimePicker1.Value.ToString("yyyy-MM-dd");
string command = "SELECT * FROM ventash WHERE Fecha >='" + strFecha + "'";
pivotCache.Connection = MyConString;
pivotCache.CommandText = command;
#region ValorAgregado
Excel.Worksheet sheetAgregado = libro.Sheets.Add();
libro.Sheets[libro.ActiveSheet.Name].Select();
libro.Sheets[libro.ActiveSheet.Name].Name = "Valor agregado";
Excel.PivotTables pivotTablesAgregado = sheetAgregado.PivotTables();
Excel.PivotTable pivotTableAgregado = pivotTablesAgregado.Add(pivotCache, app.Range["A4"], "Valor agregado");
sheetAgregado.PivotTables("Valor agregado").PivotFields("NombreLocal").Orientation = Excel.XlPivotFieldOrientation.xlPageField;
sheetAgregado.PivotTables("Valor agregado").PivotFields("NombreLocal").Position = 1;
sheetAgregado.PivotTables("Valor agregado").PivotFields("FormaPago").Orientation = Excel.XlPivotFieldOrientation.xlPageField;
sheetAgregado.PivotTables("Valor agregado").PivotFields("FormaPago").Position = 2;
sheetAgregado.PivotTables("Valor agregado").PivotFields("Fecha").Orientation = Excel.XlPivotFieldOrientation.xlRowField;
app.Range["B6"].Select();
sheetAgregado.PivotTables("Valor agregado").ColumnGrand = false;
sheetAgregado.PivotTables("Valor agregado").RowGrand = false;
sheetAgregado.PivotTables("Valor agregado").TableStyle2 = "PivotStyleLight26";
sheetAgregado.PivotTables("Valor agregado").CalculatedFields.Add("ValorAgregado", "=IF(TotalPublico>0,(TotalPublico/TotalCosto)-1)", true);
sheetAgregado.PivotTables("Valor agregado").PivotFields("ValorAgregado").Orientation = Excel.XlPivotFieldOrientation.xlDataField;
sheetAgregado.PivotTables("Valor agregado").PivotFields("Suma de ValorAgregado").Caption = "Valor agregado";
sheetAgregado.PivotTables("Valor agregado").PivotFields("Valor agregado").NumberFormat = "0,00%";
sheetAgregado.Cells[6, 1].Select();
object[] periodosValor = { false, false, false, false, true, false, true };
Excel.Range rangeValor = sheetAgregado.get_Range("a6");
rangeValor.Group(true, true, 1, periodosValor);
libro.ShowPivotTableFieldList = false;
app.Range["A5"].Select();
app.Range[app.Selection, app.Selection.End(Microsoft.Office.Interop.Excel.XlDirection.xlDown)].Select();
app.Range[app.Selection, app.Selection.End(Microsoft.Office.Interop.Excel.XlDirection.xlToRight)].Select();
Excel.Range rangoGrafico = app.Selection;
app.ActiveSheet.Shapes.AddChart.Select();
app.ActiveSheet.Shapes(1).Name = "Valor agregado";
app.ActiveChart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xl3DColumn;
app.ActiveChart.SetSourceData(Source: rangoGrafico);
app.ActiveChart.ClearToMatchStyle();
app.ActiveChart.ChartStyle = 42;
app.ActiveChart.ClearToMatchStyle();
app.ActiveSheet.Shapes["Valor agregado"].Left = 0;
app.ActiveSheet.Shapes["Valor agregado"].Top = 300;
app.ActiveSheet.Shapes["Valor agregado"].ScaleWidth(1.663541776, Microsoft.Office.Core.MsoTriState.msoFalse
, Microsoft.Office.Core.MsoScaleFrom.msoScaleFromTopLeft);
app.ActiveSheet.Shapes["Valor agregado"].ScaleHeight(1.2777777778, Microsoft.Office.Core.MsoTriState.msoFalse
, Microsoft.Office.Core.MsoScaleFrom.msoScaleFromTopLeft);
app.ActiveSheet.Shapes["Valor agregado"].ThreeD.RotationX = -30;
app.ActiveSheet.Shapes["Valor agregado"].ThreeD.RotationY = 100;
app.ActiveSheet.Shapes["Valor agregado"].ThreeD.FieldOfView = 10;
app.ActiveChart.ChartTitle.Text = "Valor agregado";
app.Range["A1"].Select();
#endregion
#region Prendas
Excel.Worksheet sheetPrendas = libro.Sheets.Add();
string hojaPrendas = libro.ActiveSheet.Name;
libro.Sheets[hojaPrendas].Select();
libro.Sheets[hojaPrendas].Name = "Prendas";
Excel.PivotTables pivotTablesPrendas = sheetPrendas.PivotTables();
Excel.PivotTable pivotTablePrendas = pivotTablesPrendas.Add(pivotCache, app.Range["A4"], "Prendas");
sheetPrendas.PivotTables("Prendas").TableStyle2 = "PivotStyleLight26";
sheetPrendas.PivotTables("Prendas").PivotFields("NombreLocal").Orientation = Excel.XlPivotFieldOrientation.xlPageField;
sheetPrendas.PivotTables("Prendas").PivotFields("NombreLocal").Position = 1;
sheetPrendas.PivotTables("Prendas").PivotFields("FormaPago").Orientation = Excel.XlPivotFieldOrientation.xlPageField;
sheetPrendas.PivotTables("Prendas").PivotFields("FormaPago").Position = 2;
sheetPrendas.PivotTables("Prendas").PivotFields("Fecha").Orientation = Excel.XlPivotFieldOrientation.xlRowField;
Excel.PivotField fldTotalPrendas = pivotTablePrendas.PivotFields("Prendas");
fldTotalPrendas.Orientation = Excel.XlPivotFieldOrientation.xlDataField;
fldTotalPrendas.Function = Excel.XlConsolidationFunction.xlSum;
fldTotalPrendas.Name = " Prendas";
sheetPrendas.Cells[6, 1].Select();
object[] periodosPrendas = { false, false, false, false, true, false, true };
Excel.Range rangePrendas = sheetPrendas.get_Range("a6");
rangePrendas.Group(true, true, 1, periodosPrendas);
libro.ShowPivotTableFieldList = false;
app.Range["A5"].Select();
app.Range[app.Selection, app.Selection.End(Microsoft.Office.Interop.Excel.XlDirection.xlDown)].Select();
app.Range[app.Selection, app.Selection.End(Microsoft.Office.Interop.Excel.XlDirection.xlToRight)].Select();
Excel.Range rangoGraficoPrendas = app.Selection;
app.ActiveSheet.Shapes.AddChart.Select();
app.ActiveSheet.Shapes(1).Name = "Prendas";
app.ActiveChart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xl3DColumn;
app.ActiveChart.SetSourceData(Source: rangoGraficoPrendas);
app.ActiveChart.ClearToMatchStyle();
app.ActiveChart.ChartStyle = 42;
app.ActiveChart.ClearToMatchStyle();
app.ActiveSheet.Shapes["Prendas"].Left = 0;
//.........这里部分代码省略.........