我的问题是代码执行的时候浏览器进度条一到38%就不走了 我追条测试之后发现问题在Dispatch.get(workbook,"PrintOut");这条上面 但是不知道要怎么解决 所以恳请各位大虾们帮忙了 谢谢各位 以下为程序代码 小弟刚来这 分不多 对于大家十分感激
import mybean.data.*;
import com.jacob.com.*;
import com.jacob.activeX.*;
import java.sql.*;
import java.io.*;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.net.*;
import java.util.Date;
import javax.servlet.*;
import javax.servlet.http.*;
public class HandleDayin extends HttpServlet
{
ActiveXComponent xl;
Dispatch workbooks=new Dispatch();
Dispatch workbook=new Dispatch();
static Dispatch sheet=new Dispatch();
int x=0; public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
x=1;
if(x==1)
{
/*
try {
// System.out.println("version=" + xl.getProperty("Version"));
//不打开文档 // Dispatch.put(xl, "Visible", new Variant(true));
ComThread.InitSTA();
*/
xl=new ActiveXComponent("Excel.Application");
Dispatch.put(xl,"Visible",new Variant(false));
workbooks = xl.getProperty("Workbooks").toDispatch();
String excelPath = this .getServletContext().getRealPath( "/" );
excelPath = excelPath.replace('\\','/');
String reportFilePath = excelPath + "moban/book.xls" ;
//打开文档
workbook=Dispatch.call(workbooks,"Open",reportFilePath).toDispatch();
//打开sheet
sheet = Dispatch.get(workbook,"ActiveSheet").toDispatch();
SetValue("A1","Value","2");
SetValue("A5","Value","qwqweqwe");
SetValue("c4","Value","顺在要要在地");
//开始打印
Dispatch.get(workbook,"PrintOut");
//Dispatch.get(xl,"Quit"); /*
} catch (Exception e) {
e.printStackTrace();
}
//始终释放资源
Dispatch.call(workbook, "Close", new Variant(0)); xl.invoke("Quit", new Variant[] {});
ComThread.Release();
}
*/
}
RequestDispatcher dispatcher=request.getRequestDispatcher("showDayin.jsp");
dispatcher.forward(request,response);
}
public static void SetValue(String position,String type,String value)
{Dispatch cell = Dispatch.invoke(sheet, "Range", Dispatch.Get,new Object[]{position},new int[1]).toDispatch();Dispatch.put(cell, type, value);
}
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{doPost(request,response);
}
}
import mybean.data.*;
import com.jacob.com.*;
import com.jacob.activeX.*;
import java.sql.*;
import java.io.*;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.net.*;
import java.util.Date;
import javax.servlet.*;
import javax.servlet.http.*;
public class HandleDayin extends HttpServlet
{
ActiveXComponent xl;
Dispatch workbooks=new Dispatch();
Dispatch workbook=new Dispatch();
static Dispatch sheet=new Dispatch();
int x=0; public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
x=1;
if(x==1)
{
/*
try {
// System.out.println("version=" + xl.getProperty("Version"));
//不打开文档 // Dispatch.put(xl, "Visible", new Variant(true));
ComThread.InitSTA();
*/
xl=new ActiveXComponent("Excel.Application");
Dispatch.put(xl,"Visible",new Variant(false));
workbooks = xl.getProperty("Workbooks").toDispatch();
String excelPath = this .getServletContext().getRealPath( "/" );
excelPath = excelPath.replace('\\','/');
String reportFilePath = excelPath + "moban/book.xls" ;
//打开文档
workbook=Dispatch.call(workbooks,"Open",reportFilePath).toDispatch();
//打开sheet
sheet = Dispatch.get(workbook,"ActiveSheet").toDispatch();
SetValue("A1","Value","2");
SetValue("A5","Value","qwqweqwe");
SetValue("c4","Value","顺在要要在地");
//开始打印
Dispatch.get(workbook,"PrintOut");
//Dispatch.get(xl,"Quit"); /*
} catch (Exception e) {
e.printStackTrace();
}
//始终释放资源
Dispatch.call(workbook, "Close", new Variant(0)); xl.invoke("Quit", new Variant[] {});
ComThread.Release();
}
*/
}
RequestDispatcher dispatcher=request.getRequestDispatcher("showDayin.jsp");
dispatcher.forward(request,response);
}
public static void SetValue(String position,String type,String value)
{Dispatch cell = Dispatch.invoke(sheet, "Range", Dispatch.Get,new Object[]{position},new int[1]).toDispatch();Dispatch.put(cell, type, value);
}
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{doPost(request,response);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货