精通.NET中的日常打印(使用C# 非常实用)

打印

文章标题是翻译出的中文标题,英文原文标题为:Master Everyday Printing in .NET

文章来自Fawcette Technical Publications(www.ftponline.com)

文章详细地讲述了 System.Drawing.Printing  命名空间中的 20个类 7 个枚举以及 3个委托的用法。

本文将先贴出英文原文,最后再贴出完整源代码,希望对大家有所帮助!

英文原文:

Listing 1 C#

Create and Dispose. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />


The PrintDocument object exposes several events. BeginPrint is fired before any pages are actually printed, giving you the opportunity to allocate objects or open files. EndPrint occurs after the last page has been printed. Don’t forget to bind the events to your PrintDocument object.

 

// At the class level

private Font bodyFont;

private Font headerFont;

private StreamReader data;

private PrintDocument doc;

private void MainForm_Load(object

   sender, System.EventArgs e) {

   doc = new PrintDocument();

   // shows up in Print Manager

   doc.DocumentName = “Contact List”;

   doc.BeginPrint += new

       PrintEventHandler(doc_BeginPrint);

   doc.EndPrint += new

       PrintEventHandler(doc_EndPrint);

}

private void doc_BeginPrint(object

   sender, PrintEventArgs pv) {

   data = new

       StreamReader("contacts.csv");

   Font bodyFont = new Font(“Arial”,

       12);

   Font headerFont = new Font(“Arial”,

       24);

}

private void doc_EndPrint(object

   sender, PrintEventArgs pv) {

   data.Close();

   bodyFont.Dispose();

   headerFont.Dispose();

}

 

Listing 2 C#

Inherit From PrintDocument.


Derive a new class from PrintDocument so you can encapsulate all your printing functionality in a single place, enhancing code reuse.

 

public class CustomPrintDocument : PrintDocument {

   private StreamReader dataToPrint;

   public CustomPrintDocument(StreamReader data) : base()

   {

       dataToPrint = data;

   }

   protected override void OnBeginPrint(PrintEventArgs

       ev) {

       base.OnBeginPrint(ev) ;

   }

   protected override void OnEndPrint(PrintEventArgs ev)

   {

       base.OnEndPrint(ev);

   }

   protected override void

       OnQueryPageSettings(QueryPageSettingsEventArgs ev)

   {

       base.OnQueryPageSettings(ev);

   }

   protected override void OnPrintPage(PrintPageEventArgs

       ev) {

       base.OnPrintPage(ev);

       ev.Graphics.DrawString("this is a test", new

          Font("Arial", 24), Brushes.Black, 100, 100);

       ev.HasMorePages = false;

   }

}

 

Listing 3 C#

Retrieve the Margins With P/Invoke.


The .NET Framework doesn’t provide a way to retrieve the hard margins of a printer, so you need to use P/Invoke and call the Win32 GetDeviceCaps function. The method in this class takes a device handle (hDc), then populates the class members with the information you need.

 

[DllImport("gdi32.dll")]

private static extern Int16 GetDeviceCaps([In] [MarshalAs

   (UnmanagedType.U4)] int hDc, [In] [MarshalAs

   (UnmanagedType.U2)] Int16 funct);

private float _leftMargin = 0;

private float _topMargin = 0;

private float _rightMargin = 0;

private float _bottomMargin = 0;

const short HORZSIZE      = 4;

const short VERTSIZE      = 6;

const short HORZRES       = 8;

const short VERTRES       = 10;

const short PHYSICALOFFSETX = 112;

const short PHYSICALOFFSETY = 113;

public marginInfo(int deviceHandle) {

   float offx = Convert.ToSingle(

       GetDeviceCaps(deviceHandle, PHYSICALOFFSETX));

   float offy = Convert.ToSingle(

       GetDeviceCaps(deviceHandle, PHYSICALOFFSETY));

   float resx = Convert.ToSingle(

       GetDeviceCaps(deviceHandle, HORZRES));

   float resy = Convert.ToSingle(

       GetDeviceCaps(deviceHandle, VERTRES));

   float hsz = Convert.ToSingle(

       GetDeviceCaps(deviceHandle, HORZSIZE))/25.4f;

   float vsz = Convert.ToSingle(

       GetDeviceCaps(deviceHandle,VERTSIZE))/25.4f;

   float ppix = resx/hsz;

   float ppiy = resy/vsz;

   _leftMargin  = (offx/ppix) * 100.0f;

   _topMargin   = (offy/ppix) * 100.0f;

   _bottomMargin  = _topMargin + (vsz * 100.0f);

   _rightMargin  = _leftMargin + (hsz * 100.0f);

}

 

Listing 4 C#

Lay Out the Report.


The basic format of any report must include at least a header, body, and footer section. Use Rectangle objects to lay out your reports easily. You can increase the complexity of those reports by adding more Rectangle objects.

 

// create the header

int headerHeight =

   hf.GetHeight(ev.Graphics);

RectangleF header = new

   RectangleF(leftMargin, topMargin,

       pageWidth, headerHeight);

// create the footer

int bodyFontHeight =

   bodyFont.GetHeight(ev.Graphics);

RectangleF footer = new 

   RectangleF(leftMargin, body.Bottom,

       pageWidth, bodyFontHeight);

// create the body section

RectangleF body = new

   RectangleF(leftMargin, header.Bottom,

       pageWidth, pageHeight –

       bodyFontHeight);

 

Listing 5 C#

PrintPage Provides the Key to Printing.


The PrintPage event is the primary event you’ll use when printing using the System.Drawing.Printing objects. This event fires once per page until you set the value of ev.HasMorePages to false. The code used to retrieve the hard margins makes up for any shortcomings in the .NET Framework.

 

private void doc_PrintPage(object sender,

   System.Drawing.Printing.PrintPageEventArgs ev) {

   _currentPage++;

   String headerText = "Northwinds Customer Contacts";

   IntPtr hDc = ev.Graphics.GetHdc();

   ev.Graphics.ReleaseHdc(hDc);

   marginInfo mi = new marginInfo(hDc.ToInt32());

   // take the hard margins into account…

   float leftMargin = ev.MarginBounds.Left - mi.Left;

   float rightMargin = ev.MarginBounds.Right;

   float topMargin = ev.MarginBounds.Top - mi.Left;

   float bottomMargin = ev.MarginBounds.Bottom;

   float pageHeight = bottomMargin - topMargin;

   float pageWidth = rightMargin - leftMargin;

   float headerHeight =

   headerFont.GetHeight(ev.Graphics);

   float footerHeight = bodyFont.GetHeight(ev.Graphics);

   // report header

   RectangleF ReportheaderR = new RectangleF(leftMargin,

       topMargin, pageWidth, headerHeight);

   // report body

   RectangleF bodyR = new RectangleF(leftMargin,

       ReportheaderR.Bottom, pageWidth, pageHeight –

       ReportheaderR.Height - footerHeight);           

   // report footer

   RectangleF ReportfooterR = new RectangleF(leftMargin,

       bodyR.Bottom, pageWidth, footerHeight * 2);

   // results of using the Split function on the text

   String[] el;

   // a line of text from our file

   string text = "";

   // print the header once per page

   centerText(ev.Graphics, headerText, headerFont,

       defaultBrush, ReportheaderR);

   // the header is equal to 2 normal lines

   int currentLine = 2;

   // how many lines can we fit on a page?             

   int linesPerPage = Convert.ToInt32(bodyR.Height /

       bodyFont.GetHeight(ev.Graphics)) - 1;

   float bodyFontHeight =

       bodyFont.GetHeight(ev.Graphics);

   float currentY;

   // Print each line of the file.

   while(currentLine < linesPerPage &&

   ((text=data.ReadLine()) != null)) {

       el = text.Split(',');

       currentY = getCurrentY(currentLine, topMargin,

          bodyFontHeight);

       ev.Graphics.DrawString(el[0], bodyFont,

          defaultBrush, bodyR.Left, currentY);

       currentLine++;

       currentY = getCurrentY(currentLine, topMargin,

          bodyFontHeight);

       ev.Graphics.DrawString(el[1],

          bodyFont, defaultBrush, bodyR.Left + 20,

          currentY);

       currentLine++;

       currentY = getCurrentY(currentLine, topMargin,

          bodyFontHeight);

       ev.Graphics.DrawString("Phone: " + el[2],

          bodyFont, defaultBrush, bodyR.Left + 20,

          currentY);

       currentLine++;

       currentY = getCurrentY(currentLine, topMargin,

          bodyFontHeight);

       ev.Graphics.DrawString("Fax: " + el[3],

          bodyFont,defaultBrush, bodyR.Left + 20,

          currentY);

, NT>
       currentLine++;

       currentY = getCurrentY(currentLine, topMargin,

          bodyFontHeight);

       ev.Graphics.DrawLine(Pens.Black, leftMargin,

          currentY, ev.MarginBounds.Right, currentY);

   }

   // page number

   centerText(ev.Graphics, "Page " +

       currentPage.ToString(), bodyFont,

       defaultBrush, ReportfooterR);

   if (text != null) {

       ev.HasMorePages = true;

   } else {

       // no more pages to print

       ev.HasMorePages = false;

   }

}

private float getCurrentY(int currentLine, float

   topMargin, float fontHeight) {

   return topMargin + (currentLine * fontHeight);

}

private void centerText(Graphics g,

   string t, Font f, Brush b, RectangleF

   rect) {

   StringFormat sf = new StringFormat();

   sf.Alignment =

       StringAlignment.Center;

   g.DrawString(t, f, b, rect, sf);

}

 

 


完整源代码:

using System;
using System.IO;
using System.Drawing;
using System.Drawing.Printing;
using System.ComponentModel;
using System.Windows.Forms;

namespace printTest {
    public class PrintForm : System.Windows.Forms.Form
 {

        // private variables
        private PrintDocument _PDoc;
        private StreamReader _Data;
        private int _currentPage = 0;
        // these will be created in BeginPrint and
        // destroyed in EndPrint.
        private Font _headerFont;
        private Font _bodyFont;
        private Brush _defaultBrush = Brushes.Black;
        private Pen _defaultPen = new Pen(Brushes.Black, .25f);

        private System.Windows.Forms.Button PreviewButton;
        private System.Windows.Forms.Button PrintButton;
        private System.Windows.Forms.Label StatusLabel;

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

  public PrintForm()
  {
   InitializeComponent();
  }

  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows Form Designer generated code
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {
            this.PreviewButton = new System.Windows.Forms.Button();
            this.PrintButton = new System.Windows.Forms.Button();
            this.StatusLabel = new System.Windows.Forms.Label();
            this.SuspendLayout();
            //
            // PreviewButton
            //
            this.PreviewButton.Location = new System.Drawing.Point(108, 40);
            this.PreviewButton.Name = "PreviewButton";
            this.PreviewButton.TabIndex = 1;
            this.PreviewButton.Text = "Preview";
            this.PreviewButton.Click += new System.EventHandler(this.PreviewButton_Click);
            //
            // PrintButton
            //
            this.PrintButton.Location = new System.Drawing.Point(188, 40);
            this.PrintButton.Name = "PrintButton";
            this.PrintButton.TabIndex = 2;
            this.PrintButton.Text = "Print";
            this.PrintButton.Click += new System.EventHandler(this.PrintButton_Click);
            //
            // StatusLabel
            //
            this.StatusLabel.Location = new System.Drawing.Point(9, 8);
            this.StatusLabel.Name = "StatusLabel";
            this.StatusLabel.Size = new System.Drawing.Size(352, 23);
            this.StatusLabel.TabIndex = 3;
            this.StatusLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            //
            // PrintForm
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(370, 71);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.StatusLabel,
                                                                          this.PrintButton,
                                                                          this.PreviewButton});
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.Name = "PrintForm";
            this.Text = "Print Demo";
            this.Load += new System.EventHandler(this.PrintForm_Load);
            this.ResumeLayout(false);

        }
  #endregion

  [STAThread]
  static void Main()
  {
   Application.Run(new PrintForm());
  }

        private void PreviewButton_Click(object sender, System.EventArgs e)
  {
            PrintPreviewDialog previewDialog = new PrintPreviewDialog();           

            // display a pagesetup dialog
            PageSetupDialog pageSetup = new PageSetupDialog();
            pageSetup.Document = _PDoc;
            DialogResult Rc = pageSetup.ShowDialog();
            if (Rc == DialogResult.Cancel)
   {
                return;
            }           

            // display the preview dialog
            previewDialog.Document = _PDoc;
            previewDialog.PrintPreviewControl.Zoom = 1.0;
            previewDialog.WindowState = FormWindowState.Maximized;
            previewDialog.ShowInTaskbar = true;
            previewDialog.ShowDialog();
        }

        private void _PDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs ev)
  {

            _currentPage++;

            String headerText = "Northwinds Customer Contacts";

            marginInfo mi;

            float leftMargin = 0f;
            float rightMargin = 0f;
            float topMargin = 0f;
            float bottomMargin = 0f;
            float pageHeight = 0f;
            float pageWidth = 0f;

            // retrieve the hard printer margins
            IntPtr hDc = ev.Graphics.GetHdc();
            try {
                mi = new marginInfo(hDc.ToInt32());   
            } finally {
                ev.Graphics.ReleaseHdc(hDc);
            }
           
            ev.Graphics.PageUnit = GraphicsUnit.Inch;
            ev.Graphics.PageScale = .01f;
            ev.Graphics.TranslateTransform(-mi.Left, -mi.Top);

            // retrieve the margins
            leftMargin = ev.MarginBounds.Left - mi.Left;
            rightMargin = ev.MarginBounds.Right;
            topMargin = ev.MarginBounds.Top - mi.Top;
            bottomMargin = ev.MarginBounds.Bottom;
            pageHeight = bottomMargin - topMargin;
            pageWidth = rightMargin - leftMargin;

            // used to define the sections of the document
            float headerHeight = _headerFont.GetHeight(ev.Graphics);
            float footerHeight = _bodyFont.GetHeight(ev.Graphics);           

            // report header
            RectangleF ReportheaderR = new RectangleF(leftMargin, topMargin, pageWidth, headerHeight);
            // report body
            RectangleF bodyR = new RectangleF(leftMargin, ReportheaderR.Bottom, pageWidth, pageHeight - ReportheaderR.Height - footerHeight);
            // report footer
            RectangleF ReportfooterR = new RectangleF(leftMargin, bodyR.Bottom, pageWidth, footerHeight * 2);

           
            // uncomment these lines to draw borders around the rectangles
            /*
            drawRect(ev.Graphics, _defaultPen, leftMargin, topMargin, pageWidth, headerHeight);
            drawRect(ev.Graphics, _defaultPen, leftMargin, ReportheaderR.Bottom, pageWidth, pageHeight - ReportheaderR.Height - footerHeight);
            drawRect(ev.Graphics, _defaultPen, leftMargin, bodyR.Bottom, pageWidth, ReportfooterR.Height);                                   
           
            centerText(ev.Graphics, "Header section", _headerFont, _defaultBrush, ReportheaderR);
            centerText(ev.Graphics, "Body section", _headerFont, _defaultBrush, bodyR);
            centerText(ev.Graphics, "Footer section", _headerFont, _defaultBrush, ReportfooterR);          
            return;
            */

            // results of using the Split function on the text
            String[] data;
            // a line of text from our file
            string text = "";

            // print the header once per page
            centerText(ev.Graphics, headerText, _headerFont, _defaultBrush, ReportheaderR);

            // how many lines can we fit on a page?             
            float bodyFontHeight = footerHeight;
            int linesPerPage = Convert.ToInt32(bodyR.Height / bodyFontHeight) - 1;

            // the header = 2 lines
            int currentLine = 2;
            // currentY is what we'll use for the Top (Y) coordinate that
            // DrawString needs.
            float currentY = 0;

            // Print each line of the file.  This could be easily modified to
            // deal with data from a DataTable
            while(currentLine + 1 < linesPerPage && ((text=_Data.ReadLine()) != null))
   {
               
                data = text.Split(',');

                // retrieve the current top position
                currentY = getCurrentY(currentLine++, bodyR.Top, bodyFontHeight);
                // DrawString will take a Rectangle argument, but NOT a RectangleF arg,
                // so we need to provide the X and Y arguments.
                ev.Graphics.DrawString(data[0], _bodyFont, _defaultBrush,  bodyR.Left, currentY);
                currentY = getCurrentY(currentLine++, bodyR.Top, bodyFontHeight);
                ev.Graphics.DrawString(data[1], _bodyFont, _defaultBrush, bodyR.Left + 25, currentY);
                currentY = getCurrentY(currentLine++, bodyR.Top, bodyFontHeight);
                ev.Graphics.DrawString("Phone: " + data[2], _bodyFont, _defaultBrush, bodyR.Left + 25, currentY);
                currentY = getCurrentY(currentLine++, bodyR.Top, bodyFontHeight);
                ev.Graphics.DrawString("Fax: " + data[3], _bodyFont,_defaultBrush, bodyR.Left + 25, currentY);               
                //currentY = getCurrentY(currentLine++, topMargin, bodyFontHeight);
                //ev.Graphics.DrawLine(_defaultPen, leftMargin, currentY, pageWidth, currentY);
                currentLine++;
            }

            // page number
            centerText(ev.Graphics, "Page " + _currentPage.ToString(), _bodyFont, _defaultBrush, ReportfooterR);

            // Do we have more pages to print?
            if (text != null) {
                ev.HasMorePages = true;
            } else {
                ev.HasMorePages = false;
            }
        }

        private float getCurrentY(int currentLine, float topMargin, float fontHeight)
  {
            return topMargin + (currentLine * fontHeight);
        }

        // my wrapper for DrawRectangle
        private void drawRect(Graphics g, Pen p, float left, float top, float width, float height)
  {
            g.DrawRectangle(_defaultPen, left, top, width, height);
        }

        // the StringFormat class has a lot of cool features
        private void centerText(Graphics g, string t, Font f, Brush b, RectangleF rect)
  {
            StringFormat sf = new StringFormat();
            // center horizontally
            sf.Alignment = StringAlignment.Center;
            // center vertically
            sf.LineAlignment = StringAlignment.Center;
            g.DrawString(t, f, b, rect, sf);
        }

        // used for debugging
        private void dumpRectF(RectangleF rect)
  {
            System.Diagnostics.Debug.WriteLine(rect.ToString());
        }

        private void _PDoc_BeginPrint(object sender, PrintEventArgs pv)
  {
            // make sure we reset this before printing
            _currentPage = 0;

            // the file should be in the same folder as the EXE
            _Data = new StreamReader("contacts.csv");
            _headerFont = new Font("Arial", 24, FontStyle.Underline, GraphicsUnit.World);
            _bodyFont = new Font("Arial", 12, GraphicsUnit.World);
        }

        private void _PDoc_EndPrint(object sender, PrintEventArgs pv)
  {
            _Data.Close();
            _headerFont.Dispose();
            _bodyFont.Dispose();
        }

        private void _PDoc_QueryPageSettings(object sender, QueryPageSettingsEventArgs ev)
  {
           
        }

        private void PrintForm_Load(object sender, System.EventArgs e)
  {           
            _PDoc = new PrintDocument();
            // this is what will show up in the print manager
            _PDoc.DocumentName = "printTest -- Northwind Contact List";
            // make sure at least one printer is installed
            if (_PDoc.PrinterSettings.PrinterName == "<no default printer>") {
                StatusLabel.Text = "At least one (1) printer must be installed to continue.";
                PrintButton.Enabled = false;
                PreviewButton.Enabled = false;
            } else {
                StatusLabel.Text = "You have " + PrinterSettings.InstalledPrinters.Count + " printer(s) installed.";
                // bind the events
                _PDoc.PrintPage += new PrintPageEventHandler(_PDoc_PrintPage);
                _PDoc.BeginPrint += new PrintEventHandler(_PDoc_BeginPrint);
                _PDoc.EndPrint += new PrintEventHandler(_PDoc_EndPrint);
                _PDoc.QueryPageSettings += new QueryPageSettingsEventHandler(_PDoc_QueryPageSettings);
            }
        }

        private void PrintButton_Click(object sender, System.EventArgs e)
  {
            PrintDialog pd = new PrintDialog();
            pd.Document = _PDoc;
            DialogResult Rc = pd.ShowDialog();

            if (Rc == DialogResult.OK) {
                _PDoc.Print();
            }
        }
 }
}

时间: 2024-08-03 12:08:24

精通.NET中的日常打印(使用C# 非常实用)的相关文章

WPS Office 2005中丰富的打印功能

在WPS Office 2005中打印功能是非常强大的,不仅有大家日常使用的一些打印功能,还有一些较专业的打印功能,今天就让小佳在政府工作的父亲张先生给我们介绍一下他在使用WPS打印功能的一些心得. 反片输出:在WPS文字2005中,WPS提供了打印反片的功能,如果要在透明胶片上打印投影演示文稿,或者想用不干胶贴纸打印广告文字,可以使用反片打印来打印文字.首先做好一个需要反片的文档,然后选择"文件|打印"命令,打开"打印"对话框:在"打印机"选项

vfp报表中如何动态显示打印二维码,每条记录的值有可能重复,比如姓名用二维码显示打印。

问题描述 vfp报表中如何动态显示打印二维码,每条记录的值有可能重复,比如姓名用二维码显示打印. vfp报表中如何动态显示打印二维码,每条记录的值有可能重复,比如姓名用二维码显示打印.求关注求转发求收藏qq:1280737814https://shop67511955.taobao.com/ 解决方案 http://bbs.bccn.net/thread-436671-1-1.html 解决方案二: 二维码打印JS

如何在Word 2013中使用后台打印文档功能

通过使用后台打印功能,可以实现在打印文档的同时继续编辑该Word2013文档,否则只能在完成打印任务后才能进行编辑.在Word2013中启用后台打印功能的步骤如下所述: 第1步,打开Word2013文档窗口,依次单击"文件"→"选项"命令,如图2013041821所示. 图2013041821 单击"选项"命令 第2步,打开"Word选项"对话框,切换到"高级"选项卡.在"打印"区域选中

Word 2013中如何快速打印文档

在Word2013文档中,用户可以按默认设置快速打印文档.这个操作就跟在Word2003中直接单击常用工具栏中的"打印"按钮一样,可以在不进行任何设置的情况下完整打印一份当前文档.在Word2013中快速打印文档的步骤如下所述: 第1步,打开Word2013文档窗口,单击"自定义快速访问工具栏"按钮,并在打开的列表中选中"快速打印"选项,如图2013080710所示. 图2013080710 选中"快速打印"选项 第2步,在&

在Word 2007中使用后台打印文档功能

通过使用后台打印功能,可以实现在打印文档的同时继续编辑该Word2007文档,否则只能在完成打印任务后才能进行编辑.在Word2007中启用后台打印功能的步骤如下所述: 第1步,打开Word2007文档窗口,依次单击"Office按钮"→"Word选项"按钮,如图2012040213所示. 图2012040213 单击"Word选项"按钮 第2步,打开"Word选项"对话框,切换到"高级"选项卡.在&quo

在Word 2010中使用后台打印文档功能

通过使用后台打印功能,可以实现在打印文档的同时继续编辑该Word 2010文档,否则只能在完成打印任务后才能进行编辑. 在Word 2010中启用后台打印功能的步骤如下所述: 第1步,打开Word 2010文档窗口,依次单击"文件"→"选项"命令,如图2011121111所示. 图2011121111 单 击"选项"命令 第2步,打开"Word选项"对话框,切换到"高级"选项卡.在"打印"

在excel表格中怎么居中打印?

  在excel表格中怎么居中打印? 1.首先,可以看到表格默认在纸张的左上方 2.点击上方菜单的[页面布局],再点击箭头所指的按钮 3.在[页面]上设置表格的缩放比例 4.将表格调整到合适的大小 5.在[页边距]下,将居中方式的[水平]和[竖直]都打上勾 6.这样表格就会在页面的中间以合适的大小出现了

如何在wps表格中统一设置打印表头

  在wps表格中统一设置打印表头的方法: 打开我们想要打印的表格,点击页面布局 选择打印标题 在顶端标题行中,点击区域选择按钮 在表格中框选想要显示出来的表头,例如:$A1:$H1 点击确定. 我们在分页显示中的第二页中没有设置表头(但是在打印预览中将会出现). 点击预览,预览一下. 在打印预览中的每一页表头都显示表头了,下图为第二页中现实的表头.

Word 2007 中添加快速打印按钮

  与Microsoft Office Word 2007 Beta 2相比,正式版的Microsoft Office Word 2007快速访问工具栏少了个"快速打印"按钮,这给初次使用Microsoft Office Word 2007的新手带来小小的不便,因为往往要费些功夫才能找到有关打印的选项.其实可以通过自定义的方法在快速访问工具栏中添加"快速打印"按钮(图2),当然还可以根据需要添加"打印预览"等其它按钮.