日期:2014-05-17 浏览次数:20907 次
using System;
using System.Collections.Generic;
using Excel = Microsoft.Office.Interop.Excel;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Excel.Application xlApp = new Excel.ApplicationClass();
Excel.Workbook xlBook = null;
Excel.Worksheet xlSheet = null;
xlBook = xlApp.Workbooks.Open("\\\\127.0.0.1\\test.xlsx");
string pivotSheetName = "Sheet1";
foreach (Excel.Worksheet displayWorksheet in xlBook.Sheets)
{
if (pivotSheetName == displayWorksheet.Name)
{
xlSheet = displayWorksheet;
((Excel.PivotTable)xlSheet.PivotTables("数据透视表1")).PivotCache().Refresh();
System.Console.WriteLine("刷新成功");
}
}
xlApp.DisplayAlerts = false;
xlApp.Workbooks.Close();
xlApp.Quit();
}
}
}