diff --git a/FAQ/PivotCacheFromTable/.NET/PivotCacheFromTable/PivotCacheFromTable.slnx b/FAQ/PivotCacheFromTable/.NET/PivotCacheFromTable/PivotCacheFromTable.slnx new file mode 100644 index 00000000..a4a1dd78 --- /dev/null +++ b/FAQ/PivotCacheFromTable/.NET/PivotCacheFromTable/PivotCacheFromTable.slnx @@ -0,0 +1,3 @@ + + + diff --git a/FAQ/PivotCacheFromTable/.NET/PivotCacheFromTable/PivotCacheFromTable/Data/InputTemplate.xlsx b/FAQ/PivotCacheFromTable/.NET/PivotCacheFromTable/PivotCacheFromTable/Data/InputTemplate.xlsx new file mode 100644 index 00000000..4c6499d1 Binary files /dev/null and b/FAQ/PivotCacheFromTable/.NET/PivotCacheFromTable/PivotCacheFromTable/Data/InputTemplate.xlsx differ diff --git a/FAQ/PivotCacheFromTable/.NET/PivotCacheFromTable/PivotCacheFromTable/Output/.gitkeep b/FAQ/PivotCacheFromTable/.NET/PivotCacheFromTable/PivotCacheFromTable/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/FAQ/PivotCacheFromTable/.NET/PivotCacheFromTable/PivotCacheFromTable/PivotCacheFromTable.csproj b/FAQ/PivotCacheFromTable/.NET/PivotCacheFromTable/PivotCacheFromTable/PivotCacheFromTable.csproj new file mode 100644 index 00000000..c507c73c --- /dev/null +++ b/FAQ/PivotCacheFromTable/.NET/PivotCacheFromTable/PivotCacheFromTable/PivotCacheFromTable.csproj @@ -0,0 +1,26 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + Always + + + + + + Always + + + + diff --git a/FAQ/PivotCacheFromTable/.NET/PivotCacheFromTable/PivotCacheFromTable/Program.cs b/FAQ/PivotCacheFromTable/.NET/PivotCacheFromTable/PivotCacheFromTable/Program.cs new file mode 100644 index 00000000..e2e7726f --- /dev/null +++ b/FAQ/PivotCacheFromTable/.NET/PivotCacheFromTable/PivotCacheFromTable/Program.cs @@ -0,0 +1,32 @@ +using Syncfusion.XlsIO; + +class Program +{ + static void Main(string[] args) + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + // Instantiate the Excel application object + IApplication application = excelEngine.Excel; + + // Assign default application version + application.DefaultVersion = ExcelVersion.Xlsx; + + // Open a new workbook contains table + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data\InputTemplate.xlsx")); + + // Access first worksheet from the workbook + IWorksheet worksheet = workbook.Worksheets[0]; + + IWorksheet pivotSheet = workbook.Worksheets[1]; + + // Create pivot cache from the table location + IPivotCache cache = workbook.PivotCaches.Add(worksheet.ListObjects[0].Location); + + IPivotTable pivotTable = pivotSheet.PivotTables.Add("PivotTable1", pivotSheet["A1"], cache); + + // Save the workbook to disk in XLSX format + workbook.SaveAs(Path.GetFullPath(@"Output\Output.xlsx")); + } + } +} \ No newline at end of file