This command requires at least two rows of source data

前端 未结 3 1624
长发绾君心
长发绾君心 2021-01-19 15:03

I am getting this error:

This command requires at least two rows of source data. You cannot use the command on a selection in only one row. Try the following         


        
3条回答
  •  走了就别回头了
    2021-01-19 16:04

    i suppose this situation occurs because of the pivot tables you got. cause refresh all will trigger pivot table's refresh command too. look at the code below. It may give you an idea about it. Its not about 1 row im sure. i checked it everthing works just fine its most posibly caused by pivot tables.

    Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
    Microsoft.Office.Interop.Excel.Workbook xlWorkbook = xlApp.Workbooks.Open("some.xlsx");
    // For each worksheet we got
    foreach (Microsoft.Office.Interop.Excel.Worksheet worksheet in xlWorkbook.Sheets) 
    {   // and each pivot table in each worksheet
        foreach (Microsoft.Office.Interop.Excel.PivotTable pivot in worksheet.PivotTables())
        {   // disable BackgroundQuery
            pivot.PivotTableWizard(BackgroundQuery: false);
        }
    }
    // try to refresh all sheet
    try { xlWorkbook.RefreshAll(); } catch { }
    // then save
    xlWorkbook.Save();
    

提交回复
热议问题