Hi All, I am using the following code to create a pivot table:
string FilePath =@(Path);
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(FilePath, 0, true, 5, """", """", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, ""\t"", false, false, 0, true, 1, 0);
xlApp.WindowState = Excel.XlWindowState.xlMaximized;
xlApp.Visible=true;
//# of Rows
// # of Colunm
Excel.Workbook book = xlApp.ActiveWorkbook;
Excel.Worksheet sheet = book.Worksheets[""Sheet1""] as Excel.Worksheet;
Excel.PivotCaches pCaches = book.PivotCaches();
Excel.PivotCache pCache = pCaches.Create(Excel.XlPivotTableSourceType.xlDatabase, ""Sheet1!E10:EX075"", Excel.XlPivotTableVersionList.xlPivotTableVersion14);
sheet = book.Worksheets[""Sheet2""] as Excel.Worksheet;
sheet.Select(2);
Excel.Range rngDes = sheet.get_Range(""A1"",""EX075"");
Excel.PivotTable pTable = pCache.CreatePivotTable(rngDes, ""PivotTable1"", Excel.XlPivotTableVersionList.xlPivotTableVersion14,misValue);
Excel.PivotField fieldQ = (Excel.PivotField)pTable.PivotFields(""Manager"");
Excel.PivotField fieldQ = (Excel.PivotField)pTable.PivotFields(""Manager"");
Excel.PivotField fieldA = (Excel.PivotField)pTable.PivotFields(""Department"");
Excel.PivotField fieldc = (Excel.PivotField)pTable.PivotFields(""Balance"");
fieldQ.Orientation = Excel.XlPivotFieldOrientation.xlRowField;
fieldQ.Position = 1;
fieldA.Orientation = Excel.XlPivotFieldOrientation.xlColumnField;
fieldc.Orientation = Excel.XlPivotFieldOrientation.xlDataField;
But I am geeting the following error:
""Page: Create Pivot
Stage: Code
Type: Error
Action: Validate
Description: Compiler error at line 1: Keyword, identifier, or string expected after verbatim specifier: @
Repairable: No""
Any suggestions on how to fix this. I am using Interop dll and namespace.
Thanks in advance.Regards,
Snehasish