FileDocCategorySizeDatePackage
SViewer.javaAPI DocApache Poi 3.0.15120Mon Jan 01 12:39:34 GMT 2007org.apache.poi.hssf.contrib.view

SViewer

public class SViewer extends JApplet
Sheet Viewer - Views XLS files via HSSF. Can be used as an applet with filename="" or as a applications (pass the filename as the first parameter). Or you can pass it a URL in a "url" parameter when run as an applet or just that first parameter must start with http:// and it will guess its a url. I only tested it as an applet though, so it probably won't work...you fix it.
author
Andrew C. Oliver
author
Jason Height

Fields Summary
private SViewerPanel
panel
boolean
isStandalone
String
filename
Constructors Summary
public SViewer()
Construct the applet

  
Methods Summary
private org.apache.poi.hssf.usermodel.HSSFWorkbookconstructWorkbook(java.lang.String filename)

    HSSFWorkbook wb = null;
      FileInputStream in = new FileInputStream(filename);
      wb = new HSSFWorkbook(in);
      in.close();
    return wb;
  
private org.apache.poi.hssf.usermodel.HSSFWorkbookconstructWorkbook(java.io.InputStream in)

    HSSFWorkbook wb = null;

      wb = new HSSFWorkbook(in);
      in.close();
    return wb;
  
public voiddestroy()
Destroy the applet

  
public java.lang.StringgetAppletInfo()
Get Applet information

    return "Applet Information";
  
public java.lang.StringgetParameter(java.lang.String key, java.lang.String def)
Get a parameter value


     
        
    return isStandalone ? System.getProperty(key, def) :
      (getParameter(key) != null ? getParameter(key) : def);
  
public java.lang.String[][]getParameterInfo()
Get parameter info

    return null;
  
private java.io.InputStreamgetXLSFromURL(java.lang.String urlstring)
opens a url and returns an inputstream

    URL url = new URL(urlstring);
    URLConnection uc = url.openConnection();
    String field = uc.getHeaderField(0);
    for (int i=0;field != null; i++) {
      System.out.println(field);
      field = uc.getHeaderField(i);
  }
    BufferedInputStream is = new BufferedInputStream(uc.getInputStream());
    return is;
  
public voidinit()
Initialize the applet

    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  
private voidjbInit()
Component initialization

    InputStream i = null;
    boolean isurl = false;
    if (filename == null) filename = getParameter("filename");

    if (filename == null || filename.substring(0,7).equals("http://")) {
      isurl = true;
      if (filename == null) filename = getParameter("url");
      i = getXLSFromURL(filename);
    }

    HSSFWorkbook wb = null;
    if (isurl) {
      wb = constructWorkbook(i);
    } else {
      wb = constructWorkbook(filename);
    }
    panel = new SViewerPanel(wb, false);
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(panel, BorderLayout.CENTER);
  
public static voidmain(java.lang.String[] args)
Main method

    SViewer applet = new SViewer();
    applet.isStandalone = true;
    applet.filename = args[0];
    Frame frame;
    frame = new Frame() {
      protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
        }
      }
      public synchronized void setTitle(String title) {
        super.setTitle(title);
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
      }
    };
    frame.setTitle("Applet Frame");
    frame.add(applet, BorderLayout.CENTER);
    applet.init();
    applet.start();
    frame.setSize(400,320);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
    frame.setVisible(true);
  
public voidstart()
Start the applet

  
public voidstop()
Stop the applet