Excel數(shù)據(jù)透視表的打印功能怎么用
Excel數(shù)據(jù)透視表的打印功能怎么用
在文檔的使用過程中,打印功能對于我們來說并不陌生,在Excel數(shù)據(jù)透視表中也有打印功能。以下是學(xué)習(xí)啦小編為您帶來的關(guān)于Excel數(shù)據(jù)透視表打印,希望對您有所幫助。
Excel數(shù)據(jù)透視表打印
打印 數(shù)據(jù)透視表頁字段中的每個數(shù)據(jù)項
下面的代碼將能夠?qū)崿F(xiàn)打印頁字段中的每個數(shù)據(jù)項的功能(假定為一個頁字段).請使用打印預(yù)覽測試. 準備打印時, 請去掉 ActiveSheet.PrintOut代碼前的單引號, 并在代碼ActiveSheet.PrintPreview前添加一個單引號.
Sub PrintPivotPages()
'打印數(shù)據(jù)透視表一個頁字段下的每個數(shù)據(jù)項
'假設(shè)只有一個頁字段存在
On Error Resume Next
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = ActiveSheet.PivotTables.Item(1)
For Each pf In pt.PageFields
For Each pi In pf.PivotItems
pt.PivotFields(pf.Name).CurrentPage = pi.Name
' ActiveSheet.PrintOut '使用這個代碼打印
ActiveSheet.PrintPreview '使用這個代碼預(yù)覽
Next
Next pf
End Sub
打印數(shù)據(jù)透視表頁字段下每個數(shù)據(jù)項的透視圖
下面的代碼將能夠?qū)崿F(xiàn)打印頁字段中的每個數(shù)據(jù)項的透視圖功能(假定為一個頁字段).請使用打印預(yù)覽測試. 準備打印時, 請去掉 ActiveSheet.PrintOut代碼前的單引號, 并在代碼ActiveSheet.PrintPreview前添加一個單引號.
Sub PrintPivotCharts()
'prints a chart for each item in the page field
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = ActiveChart.PivotLayout.PivotTable
For Each pf In pt.PageFields
For Each pi In pf.PivotItems
pt.PivotFields(pf.Name).CurrentPage = pi.Name
' ActiveSheet.PrintOut
ActiveSheet.PrintPreview '打印預(yù)覽測試
Next
Next pf
End Sub
打印數(shù)據(jù)透視表的每個頁數(shù)據(jù)項 – 多個頁字段
下面代碼將完成打印數(shù)據(jù)透視表頁數(shù)據(jù)項的每個組合. 如果 PrintFlag 不設(shè)置為 true, 描述信息將被寫入PageItemList工作表.
Option Compare Text
Public mrow As Integer
Public PrintFlag As Boolean
'====================================================================
Sub PrintAllPages()
'from code posted by Tom Ogilvy
'September 5 2004
Dim holdSettings
Dim ws As Worksheet
Dim wsPT As Worksheet
Set ws = Worksheets("PageItemList") 'sheet for page items
Set wsPT = Worksheets("Pivot") 'sheet with PivotTable
mrow = 0
If MsgBox("Print?", vbYesNo, "Print?") = vbYes Then
PrintFlag = True
Else
PrintFlag = False
MsgBox "Page field items will be listed on sheet " & ws.Name
End If
If Not PrintFlag Then
ws.Cells(1, 1).CurrentRegion.Clear
End If
Set PvtTbl = wsPT.PivotTables(1)
wsPT.Activate
If PvtTbl.PageFields.Count = 0 Then
MsgBox "The PivotTable has no Pages"
Exit Sub
End If
With PvtTbl
ReDim holdSettings(1 To .PageFields.Count)
I = 1
For Each PgeField In .PageFields
holdSettings(I) = PgeField.CurrentPage.Name
I = I + 1
PgeField.CurrentPage = PgeField.PivotItems(1).Name
Next PgeField
End With
PvtPage = 1
PvtItem = 1
DrillPvt oTable:=PvtTbl, Ipage:=PvtPage, wksht:=ws
I = 1
For Each PgeField In PvtTbl.PageFields
PgeField.CurrentPage = holdSettings(I)
I = I + 1
Next PgeField
End Sub
'====================================================================
Sub DrillPvt(oTable, Ipage, wksht)
'Debug.Print "in DrillPvt, page:=" & Ipage & " Page Item: " & _
' oTable.PageFields(Ipage).CurrentPage & " " & mrow
If Ipage = oTable.PageFields.Count Then
With oTable
For I = 1 To .PageFields(Ipage).PivotItems.Count
.PageFields(Ipage).CurrentPage = _
.PageFields(Ipage).PivotItems(I).Name
mrow = mrow + 1
slist = ""
For j = 1 To .PageFields.Count
slist = slist & .PageFields(j).CurrentPage & " "
Next j
' Debug.Print slist
If PrintFlag Then
'' ActiveSheet.PrintOut 'print the sheet
ActiveSheet.PrintPreview 'preview -- for testing
Else
For j = 1 To .PageFields.Count
wksht.Cells(mrow, j).Value = _
.PageFields(j).CurrentPage.Name
Next j
End If
Next I
End With
For I = oTable.PageFields.Count - 1 To 1 Step -1
For j = 1 To oTable.PageFields(I).PivotItems.Count
If oTable.PageFields(I).CurrentPage = _
oTable.PageFields(I).PivotItems(j).Name Then
CurrItem = j
Exit For
End If
Next j
If CurrItem <> oTable.PageFields(I).PivotItems.Count Then
oTable.PageFields(I).CurrentPage = _
oTable.PageFields(I).PivotItems(CurrItem + 1).Name
Ipage = I + 1
DrillPvt oTable, Ipage, wksht
Else
If I <> 1 Then
oTable.PageFields(I).CurrentPage = _
oTable.PageFields(I).PivotItems(1).Name
Else
Exit Sub
End If
End If
Next I
Else
DrillPvt oTable, Ipage + 1, wksht
End If
End Sub
猜你喜歡:
1.Excel數(shù)據(jù)透視表動態(tài)數(shù)據(jù)怎么制作
2.怎樣在Excel2013數(shù)據(jù)透視表中統(tǒng)計不重復(fù)值數(shù)量