當編程生成一個「正常」的Excel工作表,一個範圍的PageBreak屬性可以設置爲xlPageBreakManual,然後你可以指定頁面與代碼打破像這樣:是否可以向數據透視表(Excel Interop)添加手動分頁符?
workbook.Worksheets[0].VPageBreaks.Add(sheet.Range["G1"]);
...但就是這個打印數據透視表時可能嗎?我不這麼認爲,因爲數據透視表是從一個數據源(在我的案例中是一個「原始數據」頁面,我隨後隱藏的頁面)提供的,但如果是這樣,我想知道如何。
這就是我現在做的準備印刷的PivotTablized片:
private void FormatPivotTable()
{
. . .
ConfigureForPrinting(_xlPivotTableSheet.UsedRange.Rows.Count);
}
private void ConfigureForPrinting(int finalRow)
{
string lastColumn = GetExcelTextColumnName(_xlPivotTableSheet.UsedRange.Columns.Count);
string printArea = String.Format("A1:{0}{1}", lastColumn, finalRow);
_xlPivotTableSheet.PageSetup.PrintArea = printArea;
_xlPivotTableSheet.PageSetup.Orientation = XlPageOrientation.xlLandscape;
_xlPivotTableSheet.PageSetup.Zoom = false;
_xlPivotTableSheet.PageSetup.FitToPagesWide = 1;
_xlPivotTableSheet.PageSetup.FitToPagesTall = 50;
_xlPivotTableSheet.PageSetup.LeftMargin = _xlApp.Application.InchesToPoints(0.5);
_xlPivotTableSheet.PageSetup.RightMargin = _xlApp.Application.InchesToPoints(0.5);
_xlPivotTableSheet.PageSetup.TopMargin = _xlApp.Application.InchesToPoints(0.5);
_xlPivotTableSheet.PageSetup.BottomMargin = _xlApp.Application.InchesToPoints(0.5);
_xlPivotTableSheet.PageSetup.HeaderMargin = _xlApp.Application.InchesToPoints(0.5);
_xlPivotTableSheet.PageSetup.FooterMargin = _xlApp.Application.InchesToPoints(0.5);
string rangeToRepeat = string.Format("$A$6:${0}$7", lastColumn);
_xlPivotTableSheet.PageSetup.PrintTitleRows = rangeToRepeat;
}
什麼用戶希望的是,數據的每個邏輯塊放在一起在一張紙上,這樣一個塊(5行)不能跨越多個表單。 IOW,如果塊開始時當前頁面上的空間少於5行,則跳至帶分頁符的下一頁。
這可能與數據透視表?