相关疑难解决方法(0)

列出并刷新所有数据透视表

我正在尝试创建一个脚本来刷新工作表中的所有数据,然后刷新数据透视表(因为数据库中的数据通常在数据库中的数据之前刷新,默认情况下结果不正确).

为此,我使用此脚本(因为我每天在9.00自动启动此脚本).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            // Get fully qualified path for xlsx file
            var spreadsheetLocation = "C:\\update_rapport\\Salgsrapport.xlsx";

            var exApp = new Microsoft.Office.Interop.Excel.Application();
            var exWbk = exApp.Workbooks.Open(spreadsheetLocation);
            //var exWks = (Microsoft.Office.Interop.Excel.Worksheet)exWbk.Sheets["responses(7)"];

            exWbk.RefreshAll();

            exApp.DisplayAlerts = false;

            // This part is not correct. Need to find all pivot tables and update them
            Object PivotTables(
                Object Index
            );


            string save_file_name = "C:\\temp\\updated\\Salgsrapport.xlsx";
            exWbk.SaveAs(save_file_name);
            exWbk.Close(true); …
Run Code Online (Sandbox Code Playgroud)

c# excel pivot-table

5
推荐指数
1
解决办法
3791
查看次数

使用Interop c#在Microsoft Excel中检测数据透视表

我试图通过使用Microsoft Interop c#来检测Microsoft Excel中的单元格是否包含数据透视表

我想要做的是循环遍历所有单元格,如下面的代码所示,然后如果单元格包含数据透视表,我想将该单元格的行和列信息存储为整数值,如下所示:

int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;

Excel.Range cell = null;

for (int iRow = 1; iRow < rowCount; iRow++)
{
    for (int iCol = 1; iCol <= colCount; iCol++)
    {
        /* This line of code is probably wrong */
        cell = xlRange.Cells[iRow, iCol] as Excel.Range;

        if(/*Cell contains PivotTable*/)
        {
            int rowLocation = iRow;
            int colLocation = iCol;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试过查看MSDN和其他来源,但似乎无法找到任何方法来检测单元格是否包含数据透视表.

任何帮助表示赞赏,谢谢.

c# excel interop

4
推荐指数
1
解决办法
1956
查看次数

标签 统计

c# ×2

excel ×2

interop ×1

pivot-table ×1