Clearing Pivot Table data without destroying the Pivot Table

Đang mở
#173 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
18/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
documentation

Hướng nghiên cứu

Không có tệp, kiểm thử hay điểm vào nào của repository được nêu tên. Hãy bắt đầu bằng việc xem xét phương thức SetPivotRefresh cùng các API PivotTableCacheDefinitionPart và PivotCacheDefinition được tham chiếu, sau đó xác định liệu tài liệu có nên đề cập đến việc xóa các bản ghi bộ nhớ đệm trong khi vẫn giữ nguyên bảng pivot hay không, cũng như các workbook được bảo vệ hoặc chỉ đọc ảnh hưởng như thế nào đến hành vi làm mới.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

We have a situation where we have a spreadsheet with a sheet data and the second sheet containing a pivot table. Some of our customers open their spreadsheets in read only or protected mode in Excel, which causes a notification that the pivot table cannot be updated upon opening it. Only the first sheet with the data is updated when we create the spreadsheet. The sheet with the pivot table is updated upon opening the spreadsheet (except in this case).

I've been looking everywhere and trying anything to remove the cache or the fields and get it to work. I want the pivot table to stay intact but not to present un-updated data in the pivot table sheet. We have a way to update the pivot table upon opening, but the problem has to do with the workbook being opened readonly or in protected mode which shows un-updated and wrong data in the pivot table.

This is what we use to make the sheet updatable and I've been trying to remove some things and to keep the workbook from displaying errors that a part is missing or something else, but with no succes:

 void SetPivotRefresh(Sheet sheet, bool sourceLocked)
 {
     try
     {
         List<PivotTableCacheDefinitionPart> pivotTableCacheDefinitionParts =
            _openXmlSpreadsheetDocument.WorkbookPart.PivotTableCacheDefinitionParts.Where(x =>
                x.PivotCacheDefinition.CacheSource.WorksheetSource.Name == sheet.CompleteName || x.PivotCacheDefinition.CacheSource.WorksheetSource.Sheet == sheet.CompleteName).ToList();

         foreach (PivotTableCacheDefinitionPart pivotTableCacheDefinition in pivotTableCacheDefinitionParts)
         {
             pivotTableCacheDefinition.PivotCacheDefinition.EnableRefresh = true;
             pivotTableCacheDefinition.PivotCacheDefinition.RefreshOnLoad = true;
             pivotTableCacheDefinition.PivotCacheDefinition.RecordCount = Convert.ToUInt32(sheet.RowCount);                                 

             if (!sourceLocked)
             {
                 WorksheetSource worksheetSource = pivotTableCacheDefinition.PivotCacheDefinition.PivotTableCacheDefinitionPart.PivotCacheDefinition.CacheSource.WorksheetSource;
                 // otherwise a share violation will be given and files built with OpenXML or Excel use these properties differently
                 worksheetSource.Sheet = sheet.CompleteName;
                 worksheetSource.Name = null;

                 string startingCellReference = sheet.ColumnDefinitions.FirstOrDefault()?.CellReference;
                 worksheetSource.Reference = startingCellReference + ":" + SpreadsheetHelper.ConvertColumnNumberToName(sheet.ColumnCount) + (sheet.RowCount + 1);
             }

             // Remove cache so that new information is updated
             pivotTableCacheDefinition.PivotTableCacheRecordsPart.PivotCacheRecords.RemoveAllChildren();
             pivotTableCacheDefinition.PivotTableCacheRecordsPart.PivotCacheRecords.Count = 0;
             pivotTableCacheDefinition.PivotCacheDefinition.Save();
         }
     }
     catch (Exception e)
     {
         Log.LogHandledException(e);
     }
 }

"sheet" is our own object which contains all the data that should go into an Excel sheet.

Ngôn ngữ chính
PowerShell
Star
109
Fork
72
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của OfficeDev/open-xml-docs

Tất cả issue của OfficeDev/open-xml-docs

Issue tương tự

Thêm issue về Documentation

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.