如何更改Excel数据透视表的源数据数据、透视、如何更改、Excel

2023-09-03 22:29:48 作者:我最珍贵@

旨在实现: 我想改变源数据的使用VB.Net到一个名为范围在Excel中我的数据透视表。

我有:

table.ChangePivotCache(wb.PivotCaches.Create(SourceType:=Excel.XlPivotTableSourceType.xlDatabase, SourceData:= sheet.Names(name_of_NamedRange)RefersToRange))。

例外:

 参数不正确。 (异常来自HRESULT:80070057(E_INVALIDARG))
 

解决方案

SourceData必须是包含地址,包括工作表的名称,如我的表A1字符串:B10。试试这个:

table.ChangePivotCache(wb.PivotCaches.Create(SourceType:=Excel.XlPivotTableSourceType.xlDatabase, SourceData:= sheet.Names(name_of_NamedRange)RefersToRange.Address。(外部:= TRUE))) 怎么看10的EXCEL数据透视表源数据

Aim to achieve : I want to change the source data for my pivot table in Excel using VB.Net to a named range.

I have :

table.ChangePivotCache(wb.PivotCaches.Create(SourceType:=Excel.XlPivotTableSourceType.xlDatabase, SourceData:=sheet.Names("name_of_NamedRange").RefersToRange))

Exception :

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

解决方案

SourceData needs to be a string that contains the address, including the sheet name, like 'My Sheet'!A1:B10. Try this:

table.ChangePivotCache(wb.PivotCaches.Create(SourceType:=Excel.XlPivotTableSourceType.xlDatabase, SourceData:=sheet.Names("name_of_NamedRange").RefersToRange.Address(External:=True)))