예제 #1
0
        public string ChangeSourceDataPivotTable(string FilePath, string PivotSheetName, string SourceSheetName, string SourceDataRange, string PivotTableName)
        {
            string result = "";

            try
            {
                string srcData = SourceSheetName + "!" + Ws.Range[SourceDataRange].Address[XlReferenceStyle.xlR1C1];
                result = OpenExcel(FilePath, PivotSheetName);
                if (result == "")
                {
                    Excel.PivotTable pivot = Ws.PivotTables(PivotTableName);
                    pivot.ChangePivotCache(Wb.PivotCaches().Create(XlPivotTableSourceType.xlDatabase, srcData));
                    result = "";
                }
            }
            catch (Exception e)
            {
                return("Exception caught - " + e.Message);
            }

            return(result);
        }