⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zprinter.java

📁 用Java写的报表.功能如下: 0.内建网络打印,网络预览功能! 1.文件操作。包括url 指定的文件。 2.全功能打印支持。包括打印预览。 3.Undo 和 redo。 4.合并单元格。 5.Cel
💻 JAVA
字号:
/*
 * Copyright 2002 EZCell , Inc. All rights reserved.
 * Version  1.0.
 * Author   W.John
 */
package ezcell;

import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.IOException;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.*;
import java.awt.print.Printable;
import java.awt.print.PrinterJob;
import java.io.FileOutputStream;
import java.io.IOException;



/**
 * put your documentation comment here
 */
class ZPrintableCells {
    static ZSheetPainter sheetPainter = (ZSheetPainter) (ZUIManager.getDefault().get("Painter.sheet"));
    static ZCellPainter cellPainter = (ZCellPainter) (ZUIManager.getDefault().get("Painter.cell.common"));
    private ZSheet sheet;
    private ZRect visibleCells;
    private ZRect clip;

    /**
     * put your documentation comment here
     * @param     ZSheet sheet
     * @param     ZRect visibleCells
     * @param     ZRect clip
     */
    public ZPrintableCells(ZSheet sheet, ZRect visibleCells, ZRect clip) {
        this.sheet = sheet;
        this.visibleCells = visibleCells;
        this.clip = clip;
    }

    /**
     * put your documentation comment here
     * @return
     */
    public ZSheet getSheet() {
        return sheet;
    }

    /**
     * put your documentation comment here
     * @return
     */
    public ZRect getVisibleCells() {
        return visibleCells;
    }
}

/**
 * put your documentation comment here
 */
public class ZPrinter {
    static boolean printing;
    private static ZPrinter sharePrinter;

    /**
     * put your documentation comment here
     */
    private ZPrinter() {
    }

    /**
     * put your documentation comment here
     * @return
     */
    static public ZPrinter getPrinter() {
        if (sharePrinter == null) {
            sharePrinter = new ZPrinter();
        }

        return sharePrinter;
    }

    /**
     * put your documentation comment here
     * @param doc
     * @param showDialog
     * @exception Exception
     */
    public void print(ZDocument doc, boolean showDialog)
               throws Exception {
        if (doc.recreatePages() == 0) {
            throw new ZException("there is no any printable cells!");
        }

        ZPage page;
        PageFormat pageFormat = doc.getPageFormat();

        //--- Create a new PrinterJob object
        PrinterJob printJob = PrinterJob.getPrinterJob();
 //       printJob.setJobName(doc.getTitle());


        //--- Show the page dialog
        //          if (showDialog) ;
        //--- Add the pages to the book
        //--- Tell the printJob to use the book as the pageable object
        printJob.setPageable(doc);

        //--- Show the print dialog box. If the user click the
        //--- print button we then proceed to print else we abort.
        try {
            if (showDialog) {
                if (printJob.printDialog()) {
                    printJob.print();
                }
            } else {
                printJob.print();
            }
        } catch (Exception PrintException) {
            PrintException.printStackTrace();
        }
    }

    /**
     * put your documentation comment here
     * @param doc
     * @exception Exception
     */
    public void printPreview(ZDocument doc) throws Exception {
        if (doc.recreatePages() == 0) {
            throw new ZException("there is no any printable cells!");
        }

        ZPrintPreviewFrame printPreview = new ZPrintPreviewFrame(doc);
    }

    /**
     * put your documentation comment here
     * @param doc
     * @return
     */
    public PageFormat printSetup(ZDocument doc) {
        PrinterJob job = PrinterJob.getPrinterJob();

        return job.pageDialog(doc.getPageFormat());
    }

    /**
     *
     * @param doc
     *
     * @throws Exception
     */
    public void printToPostscriptFile(ZDocument doc) throws Exception {

   /*   if (doc.recreatePages() == 0) {
          throw new ZException("there is no any printable cells!");
        }*/
  /* Use the pre-defined flavor for a Printable from an InputStream */
//  DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PAGEABLE ;

   /* Specify the type of the output stream */
//   String psMimeType = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();

  /* Locate factory which can export a GIF image stream as Postscript */
//   StreamPrintServiceFactory[] factories =
//   StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
             //             flavor, psMimeType);
//   if (factories.length == 0) {
   //        System.err.println("No suitable factories");
      //     System.exit(0);
 //  }

 // //  try {
          /*
          FileOutputStream fos = new FileOutputStream("out.ps");

          StreamPrintService sps = factories[0].getPrintService(fos);

          DocPrintJob pj = sps.createPrintJob();
          PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

          Doc doc1 = new SimpleDoc(doc, flavor, null);

          pj.print(doc1, aset);
          fos.close();

  } catch (PrintException pe) {
          System.err.println(pe);
  } catch (IOException ie) {
          System.err.println(ie);
  }

*/

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -