我眼下有一个项目需要用JAVA来操作WORD或EXCEL来生成报表单据(如销售单等),请教如何才能实现呀,最好能贴下代码。谢谢了!急呀!
解决方案 »
- 如何改变菜单栏的大小和里面JMenuItem的大小?
- 向各位高手请教一个关于LIST求和的问题,谢谢了
- 子类必须实现父类的所有抽象方法吗?
- 请问如何判断JTable被编辑了?!
- 新手问题:java程序可不可以用来传送文件。
- 庆祝历史上的8月15日,散分!
- applet中,可以有多个CLASS吗?其中一个是继承于APPLET,其他的被他所使用.在HTML中应该怎么写?是不是所有的CLASS都要写上去?
- 关于接口的作用
- 请问在Jbuilder6中怎样改变组件的大小及其在窗口中的位置?
- JDK安装后,还要修改AUTOEXEC.BAT么?
- 帮我看一下这代码有什么问题?
- 可以查看正在运行中的线程是由哪个处理器运行的吗?
http://danadler.com/jacob/
http://jakarta.apache.org/poi/
http://www.onjava.com/pub/a/onjava/2003/01/22/poi.html
http://www.csdn.net/develop/article/15/15311.shtm
http://forum.java.sun.com/thread.jsp?forum=40&thread=382666&tstart=0&trange=15 一个jacob操作Word的例子,操作Excel,Access,Outlook的例子jacob的sample目录中有
import java.io.File;
import com.jacob.com.*;
import com.jacob.activeX.*;
public class WordTest { public static void main(String[] args) {
WordBean word=new WordBean();
word.openWord(true);
word.createNewDocument();
word.insertText("Hello word.");
}
}
import com.jacob.activeX.*;
import com.jacob.com.*;
public class WordBean extends java.awt.Panel
{
private ActiveXComponent MsWordApp = null;
private Dispatch document = null;
public WordBean()
{
super();
}
public void openWord(boolean makeVisible)
{
//Open Word if we've not done it already
if (MsWordApp == null)
{
MsWordApp = new ActiveXComponent("Word.Application");
}
//Set the visible property as required.
Dispatch.put(MsWordApp, "Visible",
new Variant(makeVisible));
}
public void createNewDocument()
{
//Find the Documents collection object maintained by Word
Dispatch documents =
Dispatch.get(MsWordApp,"Documents").toDispatch();
//Call the Add method of the Documents collection to create
//a new document to edit
document = Dispatch.call(documents,"Add").toDispatch();
}
public void insertText(String textToInsert)
{
// Get the current selection within Word at the moment. If
// a new document has just been created then this will be at
// the top of the new doc
Dispatch selection =
Dispatch.get(MsWordApp,"Selection").toDispatch();
//Put the specified text at the insertion point
Dispatch.put(selection,"Text",textToInsert);
}
public void saveFileAs(String filename)
{
Dispatch.call(document,"SaveAs",filename);
}
public void printFile()
{
//Just print the current document to the default printer
Dispatch.call(document,"PrintOut");
}
public void closeDocument()
{
// Close the document without saving changes
// 0 = wdDoNotSaveChanges
// -1 = wdSaveChanges
// -2 = wdPromptToSaveChanges
Dispatch.call(document, "Close", new Variant(0));
document = null;
}
public void closeWord()
{
Dispatch.call(MsWordApp,"Quit");
MsWordApp = null;
document = null;
}
} http://www.lowagie.com/iText/docs.html#download
http://danadler.com/jacob/jacobBin_17.zip
比如报表内容如下:
有一个2*2表格,表格的第一列的第一行写“名称”,第一列的第一行写“重量”;然后第二列的第一行和第二行分别就是从用户界面输入的名称和重量的具体值。
2.用js操作控件,涉及到安全,客户端要重新设置
3.直接把头改成.doc然后用out.print("<table><tr><td></td></tr></table>");这样的输出.