关注。
::::: 只爱 Java :::::
::::: 只爱 Java :::::
解决方案 »
- 正则表达式,\b[A-Z](?:[a-z0-9]+[A-Z][a-z0-9]*)+ 是什么意思?
- 类实现java.io.Serializable后的一个问题
- 如何在屏幕上显示二进制的float和double?
- 怎么让自己的文件到别机子上运行????????
- 随机数算法 急急急啊
- 什么原因不清楚 我是菜鸟
- 请高手帮忙编写这个简单程序,谢谢!
- 用JAVA Application通过JDBC访问Domino的中文问题
- jdbc连接数据库问题
- 字符串“false”和“true”怎样可转换成boolean?
- java 下如何调用 window or unix 下的可执行程序
- 请问各位高手,j2sdk,j2se,j2ee到底有什么不一样的地方,感谢!
有个项目好像叫poi,可以读写excel文件,你可以参考一下
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应用的工具,但是比较麻烦。
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);
}
}
}
不同的框架取数据的方法是不同的,但是显示的方法都是大同小异的.
跟你讲一下我的做法吧!!!!!!!!!!
我取得的数据都是一行一行的, 一行的每个数据之间都是用","分割的,你只要做一个二维数组把数据以","分开放到数组里.然后把数组中的数据重新写到要显示的表格中就行了.
如果是客户端的行为,那么需不需要上传呢???如果是单纯的显示,那么你就像楼上说的那样?做二维数组就可以完成了!其中的方法你查一下类库就知道了!其实很简单.祝你好运..........有事Message我.......
显示数据当然是服务器端的操作了!!!!!!!!