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
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();