关注。
::::: 只爱 Java :::::

解决方案 »

  1.   

    http://jakarta.apache.org/
    有个项目好像叫poi,可以读写excel文件,你可以参考一下
      

  2.   

    那个是可以,我用ibm的bridge2java可以,不过都不能显示,只能对文件进行读写操作,有什么办法可以实现将word/excel嵌入界面?
      

  3.   

    Automate Excel from JavaSUMMARY
    This article illustrates how to call a COM object like Microsoft® Excel from Java. It provides code samples that show how you can make an Excel application visible and open an existing Excel file. There are two code samples. One illustrates how to invoke Excel 7.0 from Java and the other shows how to invoke Excel 8.0 from Java. You will find the classes and interfaces to be quite different in Excel 8.0.
    MORE INFORMATION
    Before using code samples 1 and 2, follow these steps below: 
    1)Use the Java Applet Wizard to create a default applet or application.
    2)Run JAVATLB or JActiveX (utility similar to JAVATLB and supported by the SDK for Java 2.0x) on the Microsoft Excel 7.0 Object Library if you are using Excel 7.0 or the Microsoft Excel 8.0 Object Library if you are using Excel 8.0. This will create Java descriptions of the Excel Object. If you are using Excel 97, run the JActiveX tool on EXCEL8.OLB /EXCEL9.OLB
    Note    If you are using JActiveX, then you will need to build this sample with the JVC.EXE that ships with the SDK for Java 2.0 or later. You can download the SDK for Java from http://www.microsoft.com/java/ .
    3)Use the import statement to import the classes of the Excel Object Library into your Java project.
    Insert either one of the two code snippets in your Java Project to automate Excel from Java. 
    Code Sample 1
       import xl5en32.*;
       import com.ms.com.*;
       public void TestExcel()
       {
          _Global gbl = (_Global) new _ExcelApplication();
          Variant param = gbl.Application();
          Application app = (Application) param.getDispatch();
          param.putInt(xl5en32.Constants.xlVisible);
          app.putVisible(param);
          Variant vtemp = new Variant();
          vtemp.noParam();      Variant vtWorkbooks = Dispatch.get(gbl,"Workbooks");
          Workbooks wbs = (Workbooks)vtWorkbooks.getDispatch();      Variant vtName = new Variant();
          VtName.putStringRef("C:\\book1.xls");      Variant vtEmpty = new Variant();
          vtEmpty.noParam();
          wbs.Open(vtName,vtEmpty,vtEmpty,vtEmpty,vtEmpty,vtEmpty,vtEmpty,
                   vtEmpty,vtEmpty,vtEmpty,vtEmpty,vtEmpty,vtEmpty);
       }
    Code Sample 2
       import excel8.*;
       import com.ms.com.*;   _Global globXL=null;
       _Application appXL=null;
       Workbooks books=null;
       _Workbook book = null;   try{
          globXL = (_Global)new Global();
          appXL = (_Application)globXL.getApplication();
          appXL.putVisible(0,true);  // in Excel 97 use:
                                     // appXL.setVisible(0,true);      books = (Workbooks)appXL.getWorkbooks();      Variant vTemp = new Variant();
          vTemp.putString("c:\\book1.xls");      Variant vOptional = new Variant();
          vOptional.noParam();
          book =
       (_Workbook)books.Open("c:\\book1.xls",vOptional,vOptional,vOptional,vOption
       al,vOptional,vOptional,vOptional,vOptional,vOptional,vOptional,vOptional,vO
       ptional,0);      }
          catch(ComFailException e)
          {
             System.out.println(e.getMessage());
          }
    The above code will make the Excel application visible, and it will open up an existing Excel file.
    你需要下载微软的sdk for java,里面有关于activex/com结合java应用的工具,但是比较麻烦。
      

  4.   

    再贴一段src:
       import excel8.*;
       import com.ms.com.*;
       import com.ms.win32.*;
       public class JExcel
       {
         _Application app = null;
         _Global global = null;
         Workbooks workbooks = null;
         _Workbook workbook = null;
         Sheets sheets = null;
         _Worksheet worksheet = null;
         String name = null;
         Variant vNoParam = null;
         Range range = null;
         
         int index = 0;
         public static void main(String args[])
         {
           new JExcel().go();
         }
         public void go()
         {
           try 
           {
             global = (_Global) new Global();     
             app = (_Application)global.getApplication();
             app.setVisible(0, true);
             workbooks = app.getWorkbooks();
             
             vNoParam = new Variant();
             vNoParam.noParam();
             workbook = workbooks.Add(vNoParam, 0);
             name = workbook.getName();
             User32.MessageBox(0, "Workbook Name:  " + name,
                               "Application Message" , 
                               0);
             
             sheets = workbook.getWorksheets();
             
             index = sheets.getCount();
             User32.MessageBox(0, 
                               "Number of sheets:  " + index, 
                               "Application Message" , 
                               0);
             
             for (int i = 1; i <= index; i++)
             {
               worksheet = (_Worksheet)sheets.getItem(new Variant(i));
               worksheet.Activate(0);
               worksheet.setName("Bob's Sheet "+ i);
             }
             
             User32.MessageBox(0, 
                               "Changed sheets' names.", 
                               "Application Message" , 
                               0);
             
             range = worksheet.getColumns();
             range.setColumnWidth(new Variant(40));
             
             User32.MessageBox(0, 
                               "Set column width to 40.", 
                               "Application Message" , 
                               0);
             
             range = worksheet.getCells();
             
             range.setItem(new Variant(1), 
                           new Variant(1), 
                           new Variant("This is a result of a call to Range.setItem"));
             
             User32.MessageBox(0, 
                               "Set the value of cell 1:A.", 
                               "Application Message" , 
                               0);
             
             User32.MessageBox(0, 
                               "Closing Excel Application.", 
                               "Application Message" , 
                               0);
             app.Quit();
             ComLib.release(app);
             ComLib.release(global);
             ComLib.release(workbooks);
             ComLib.release(workbook);
             ComLib.release(sheets);
             ComLib.release(worksheet);
             ComLib.release(name);
             ComLib.release(range);
             //      System.gc();
             //      Thread.currentThread().sleep(1000);
           }
           
           catch(Throwable t)
           {
             User32.MessageBox(0, 
                               t.toString(), 
                               "Exception", 
                               0);
           }
         }
       }
      

  5.   

    这些代码意义不大,我用poi或者bridge2java都可以做到,问题是都没法显示,哎。
      

  6.   

    http://www.andykhan.com/jexcelapi/index.html
      

  7.   

    我们现在做的项目中就可以实现从EXCEL中取数据,显示在页面上的功能.
    不同的框架取数据的方法是不同的,但是显示的方法都是大同小异的.
    跟你讲一下我的做法吧!!!!!!!!!!
    我取得的数据都是一行一行的, 一行的每个数据之间都是用","分割的,你只要做一个二维数组把数据以","分开放到数组里.然后把数组中的数据重新写到要显示的表格中就行了.
      

  8.   

    就像xiaomin0613(小小的疲倦的鱼)说的那样?但是我想问你几个问题,你是不是把你的Excel文件内的数据显示在web页面上?是客户端的操作还是服务器的呢?
    如果是客户端的行为,那么需不需要上传呢???如果是单纯的显示,那么你就像楼上说的那样?做二维数组就可以完成了!其中的方法你查一下类库就知道了!其实很简单.祝你好运..........有事Message我.......
      

  9.   

    to Anubis(为朋友两肋插刀,为MM插朋友两刀!!) :
    显示数据当然是服务器端的操作了!!!!!!!!