Esempio n. 1
0
        static void Main()
        {
            string dataDir = Common.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            string input = "sample1.xlsx";

            Common.StorageService.File.UploadFile(dataDir + input, input, storage: Common.STORAGE);
            string sheetName = "Sheet1";

            PivotTableResponse apiResponse = Common.CellsService.PivotTable.GetWorksheetPivottableInfoByIndex(input, sheetName, 0, Common.FOLDER, storage: Common.STORAGE);

            Console.WriteLine(" Output " + apiResponse.PivotTable.link.Title);
        }
        public static void Run()
        {
            // ExStart:1
            CellsApi   cellsApi   = new CellsApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);
            StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);

            String fileName      = "Sample_Test_Book.xls";
            string sheetName     = "Sheet1";
            string storage       = null;
            string folder        = null;
            string sourceData    = null;
            string destCellName  = null;
            string tableName     = null;
            bool?  useSameSource = false;

            Com.Aspose.Cells.Model.CreatePivotTableRequest body = new Com.Aspose.Cells.Model.CreatePivotTableRequest();
            body.Name           = "MyPivot";
            body.SourceData     = "A5:E10";
            body.DestCellName   = "H20";
            body.UseSameSource  = true;
            body.PivotFieldRows = new System.Collections.Generic.List <int?> {
                1
            };
            body.PivotFieldColumns = new System.Collections.Generic.List <int?> {
                1
            };
            body.PivotFieldData = new System.Collections.Generic.List <int?> {
                1
            };

            try
            {
                // Upload source file to aspose cloud storage
                storageApi.PutCreate(fileName, "", "", System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName));

                // Invoke Aspose.Cells Cloud SDK API to add pivot table worksheet
                PivotTableResponse apiResponse = cellsApi.PutWorksheetPivotTable(fileName, sheetName, storage, folder, sourceData, destCellName, tableName, useSameSource, body);

                if (apiResponse != null && apiResponse.Status.Equals("OK"))
                {
                    Console.WriteLine("Add a Pivot Table in a Worksheet, Done!");
                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
            }
            // ExEnd:1
        }
        public void Cells_PivotTable_Tests()
        {
            try
            {
                storageService.File.CopyFile(Utils.CloudStorage_Input_Folder + "/cells-sample.xlsx", Utils.CloudStorage_Output_Folder + "/cells-sample.xlsx");

                string name = "cells-sample.xlsx";

                PivotTablesResponse pivotTablesResponse = cellsService.PivotTable.GetWorksheetPivottablesInfo(name, "sheet6", Utils.CloudStorage_Output_Folder);
                PivotTableResponse  pivotTableResponse  = cellsService.PivotTable.GetWorksheetPivottableInfoByIndex(name, "sheet6", 0, Utils.CloudStorage_Output_Folder);
                cellsService.PivotTable.DeleteWorksheetPivotTableByIndex(name, "sheet6", 0, Utils.CloudStorage_Output_Folder);
                cellsService.PivotTable.DeleteWorksheetPivotTables(name, "sheet6", Utils.CloudStorage_Output_Folder);

                CreatePivotTableRequest createPivotTableRequest = new CreatePivotTableRequest();
                createPivotTableRequest.Name          = "Test Pivot Table";
                createPivotTableRequest.SourceData    = "A1:C7";
                createPivotTableRequest.DestCellName  = "H10";
                createPivotTableRequest.UseSameSource = true;

                createPivotTableRequest.PivotFieldRows = new List <int>();
                createPivotTableRequest.PivotFieldRows.Add(1);

                createPivotTableRequest.PivotFieldColumns = new List <int>();
                createPivotTableRequest.PivotFieldColumns.Add(1);

                createPivotTableRequest.PivotFieldData = new List <int>();
                createPivotTableRequest.PivotFieldData.Add(1);

                cellsService.PivotTable.AddAPivotTableIntoWorksheet(name, "sheet7", createPivotTableRequest, Utils.CloudStorage_Output_Folder);

                PivotTableFieldRequest pivotTableFieldRequest = new PivotTableFieldRequest();
                pivotTableFieldRequest.Data = new List <int>();
                pivotTableFieldRequest.Data.Add(1);
                pivotTableFieldRequest.Data.Add(2);
                cellsService.PivotTable.AddPivotFieldIntoIntoPivotTable(name, "sheet6", 0, "Row", pivotTableFieldRequest, Utils.CloudStorage_Output_Folder);

                WorkbookStyleResponse workbookStyleResponse = cellsService.WorksheetColumns.ReadCellStyleInfo(name, "sheet6", "A8", Utils.CloudStorage_Output_Folder);

                cellsService.PivotTable.UpdateCellStyleForPivotTable(name, "sheet6", 0, 1, 1, workbookStyleResponse.Style, Utils.CloudStorage_Output_Folder);

                cellsService.PivotTable.UpdateStyleForPivotTable(name, "sheet6", 0, workbookStyleResponse.Style, Utils.CloudStorage_Output_Folder);

                storageService.File.DownloadFile(Utils.CloudStorage_Output_Folder + "/cells-sample.xlsx", "d:\\cells-sample.xlsx");
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Esempio n. 4
0
        public static void Run()
        {
            // ExStart:1
            CellsApi   cellsApi   = new CellsApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);
            StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);

            String fileName        = "Sample_Pivot_Table_Example.xls";
            String sheetName       = "Sheet2";
            int    pivottableIndex = 0;
            String storage         = "";
            String folder          = "";

            try
            {
                // Upload source file to aspose cloud storage
                storageApi.PutCreate(fileName, "", "", System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName));

                // Invoke Aspose.Cells Cloud SDK API to get worksheet pivot table informations by index
                PivotTableResponse apiResponse = cellsApi.GetWorksheetPivotTable(fileName, sheetName, pivottableIndex, storage, folder);

                if (apiResponse != null && apiResponse.Status.Equals("OK"))
                {
                    PivotTable pivotTable = apiResponse.PivotTable;
                    Console.WriteLine("Name" + pivotTable.Name);
                    foreach (PivotItem item in pivotTable.BaseFields[0].PivotItems)
                    {
                        Console.WriteLine("Pivot Item Name :: " + item.Name);
                        Console.WriteLine("Pivot Item Value :: " + item.Value);
                    }
                    Console.WriteLine("Delete Row from a Worksheet, Done!");
                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
            }
            // ExEnd:1
        }