使用 VB.NET 按天过滤数据透视表中的列标签
Filter column labels in pivot by days using VB.NET
我有提交日期的数据透视字段代码。
ptField2 = ptTable2.PivotFields("Submitted Date")
With ptField2
.Orientation = Excel.XlPivotFieldOrientation.xlColumnField
.Name = "Submitted Date"
.Caption = dtIntFrom.Value.ToString("MM-dd-yyyy")
.ClearAllFilters()
.PivotFilters.Add(Type:=Excel.XlPivotFilterType.xlCaptionEquals, DataField:="Submitted Date", Value1:=date_stamp)
End With
这是我的目标日期:2016 年 3 月 15 日至 3 月 31 日
date_stamp = Format(dtIntFrom.Value(), "m/d/yyyy") '3/15/2016
date_stamp2 = Format(dtIntTo.Value(), "m/d/yyyy") '3/31/2016
当我 运行 我的程序时,它会显示从我的目标日期开始的所有日期。
我想过滤我选择的每周目标日期,它必须如下所示:
感谢您的帮助!
几天后,我已经使用 Range.Group Method
找到了答案
另一个错误是我在 .xlDataField
之前先编码 .xlColumnField
。它应该在最后。
示例如下:
ptField2 = ptTable2.PivotFields("Total Pages")
With ptField2
.Orientation = Excel.XlPivotFieldOrientation.xlDataField
.Function = Excel.XlConsolidationFunction.xlSum
.Name = "Pages"
.NumberFormat = "#,##0"
End With
ptField2 = ptTable2.PivotFields("Group")
With ptField2
.Orientation = Excel.XlPivotFieldOrientation.xlRowField
.Name = "Group"
End With
ptField2 = ptTable2.PivotFields("Submitted Date")
With ptField2
.Orientation = Excel.XlPivotFieldOrientation.xlColumnField
.Name = "Submitted Date"
.DataRange.Cells(1).Group(True, True, 7, New Boolean() {False, False, False, True, False, False, False})
End With
我有提交日期的数据透视字段代码。
ptField2 = ptTable2.PivotFields("Submitted Date")
With ptField2
.Orientation = Excel.XlPivotFieldOrientation.xlColumnField
.Name = "Submitted Date"
.Caption = dtIntFrom.Value.ToString("MM-dd-yyyy")
.ClearAllFilters()
.PivotFilters.Add(Type:=Excel.XlPivotFilterType.xlCaptionEquals, DataField:="Submitted Date", Value1:=date_stamp)
End With
这是我的目标日期:2016 年 3 月 15 日至 3 月 31 日
date_stamp = Format(dtIntFrom.Value(), "m/d/yyyy") '3/15/2016
date_stamp2 = Format(dtIntTo.Value(), "m/d/yyyy") '3/31/2016
当我 运行 我的程序时,它会显示从我的目标日期开始的所有日期。
我想过滤我选择的每周目标日期,它必须如下所示:
感谢您的帮助!
几天后,我已经使用 Range.Group Method
找到了答案另一个错误是我在 .xlDataField
之前先编码 .xlColumnField
。它应该在最后。
示例如下:
ptField2 = ptTable2.PivotFields("Total Pages")
With ptField2
.Orientation = Excel.XlPivotFieldOrientation.xlDataField
.Function = Excel.XlConsolidationFunction.xlSum
.Name = "Pages"
.NumberFormat = "#,##0"
End With
ptField2 = ptTable2.PivotFields("Group")
With ptField2
.Orientation = Excel.XlPivotFieldOrientation.xlRowField
.Name = "Group"
End With
ptField2 = ptTable2.PivotFields("Submitted Date")
With ptField2
.Orientation = Excel.XlPivotFieldOrientation.xlColumnField
.Name = "Submitted Date"
.DataRange.Cells(1).Group(True, True, 7, New Boolean() {False, False, False, True, False, False, False})
End With