jacob 打开有密码保护的文件卡住,如何解决

bukebuhao 2009-03-09 06:43:12
代码如下

ActiveXComponent xl = null;
//ComThread.InitSTA();
try{
xl = new ActiveXComponent("Excel.Application");
Dispatch.put(xl, "Visible", new Variant(true));
Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();

Dispatch.get(workbooks, "password");
//Variant asp = Dispatch.call(as, "Protect","password",new Variant(true),new Variant(true),new Variant(true));
// Dispatch cell = Dispatch.invoke(workbooks, "password", Dispatch.Get,new Object[] {0},new int[1]).toDispatch();
// String value = Dispatch.get(cell,"Value").toString();

Dispatch workbook = Dispatch.invoke((Dispatch) workbooks, "Open", Dispatch.Method, new Object[]
{xlsfile, new Variant(false), new Variant(true) }, new int[1]).toDispatch(); // readonly

workbook.safeRelease();
Dispatch.invoke(workbook, "SaveAs", Dispatch.Method, new Object[] { htmlfile, new Variant(44) }, new int[1]);

Dispatch.call(workbook, "Close", new Variant(false));
} catch (Exception e) {
Logger.getLogger(FileUtil.class).error(e);
} finally {
xl.invoke("Quit", new Variant[] {});
xl = null;
//ComThread.Release();
}

...全文
302 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
bukebuhao 2009-03-10
  • 打赏
  • 举报
回复
不是吧,兄弟们,都出谋划策呀,帮小弟一把
guoxyj 2009-03-10
  • 打赏
  • 举报
回复
up
software51 2009-03-10
  • 打赏
  • 举报
回复
up
moonshowder 2009-03-10
  • 打赏
  • 举报
回复
mark!
ljfsun6688 2009-03-10
  • 打赏
  • 举报
回复
jacob 是什么东东?
x_pengcheng 2009-03-09
  • 打赏
  • 举报
回复
帮你顶!
bukebuhao 2009-03-09
  • 打赏
  • 举报
回复

ActiveXComponent xl = null;
//ComThread.InitSTA();
try{
xl = new ActiveXComponent("Excel.Application");
Dispatch.put(xl, "Visible", new Variant(true));
Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();

Dispatch workbook = Dispatch.invoke((Dispatch) workbooks, "Open", Dispatch.Method, new Object[]
{xlsfile, new Variant(false), new Variant(true) }, new int[1]).toDispatch(); // 是否以只?方式打?

Dispatch.invoke(workbook, "SaveAs", Dispatch.Method, new Object[] { htmlfile, new Variant(44) }, new int[1]);

Dispatch.call(workbook, "Close", new Variant(false));
} catch (Exception e) {
Logger.getLogger(FileUtil.class).error(e);
} finally {
xl.invoke("Quit", new Variant[] {});
xl = null;
//ComThread.Release();
}

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧