|
|
|
запуск Excel из Java
|
|||
|---|---|---|---|
|
#18+
Здравствуйте. Ситуация такая: Создаю Excel-отчет с помощью POI, сохраняю его в файл c:\report.xls (сохранение проходит успешно). После этого пытаюсь открыть этот отчет: Код: plaintext 1. 2. Результат - окно Excel не открывается, хотя в списке процессов он появляется. Эксперименты с различными вариантами задания пути (например, "C:/Program Files/Microsoft Office/Office/EXCEL.EXE c:/report.xls"), взятием пути к Excel и файлу в кавычки, запуском просто Excel безо всякого файла привели к аналогичному результату. В чем может быть проблема? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 26.04.2007, 09:08:29 |
|
||
|
запуск Excel из Java
|
|||
|---|---|---|---|
|
#18+
попробуй так: Код: plaintext 1. 2. 3. 4. 5. 6. 7. 8. 9. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 26.04.2007, 09:21:16 |
|
||
|
запуск Excel из Java
|
|||
|---|---|---|---|
|
#18+
Результат аналогичен. Excel установлен видимо нормально, поскольку из cmd он таки запускается (той же самой командой, что и через Java пытаюсь). ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 26.04.2007, 10:22:13 |
|
||
|
запуск Excel из Java
|
|||
|---|---|---|---|
|
#18+
Тоже долго мучался с этой проблемой, у меня вот так работает: Код: plaintext 1. 2. 3. 4. 5. 6. 7. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 26.04.2007, 17:39:38 |
|
||
|
запуск Excel из Java
|
|||
|---|---|---|---|
|
#18+
Вот если бы кто сказал, как красиво реализовать запуск в зависимости от привязки xls файлов в операционке, т.е. если по умолчанию OpenOffice запускать OpenOffice, если Excel - Excel. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 26.04.2007, 17:42:30 |
|
||
|
запуск Excel из Java
|
|||
|---|---|---|---|
|
#18+
Для тех у кого excel появляется в процессах и зависает - не забывайте вычитывать IO потоки из экземпляра класса Process который отдается по exec. Для тех кто ищет нормальное кроссплатформенное решение - JDIC или Java 1.6 в которую он уже интегрирован. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 26.04.2007, 18:35:40 |
|
||
|
запуск Excel из Java
|
|||
|---|---|---|---|
|
#18+
//Взято из OpenSwing Framework. Работает замечательно. Хотя под Линукс не проверял. Под Винду все OK /** * <p>Title: OpenSwing Framework</p> * <p>Copyright: Copyright (C) 2006 Mauro Carniel</p> * * <p> This file is part of OpenSwing Framework. * This library is free software; you can redistribute it and/or * modify it under the terms of the (LGPL) Lesser General Public * License as published by the Free Software Foundation; * * GNU LESSER GENERAL PUBLIC LICENSE * Version 2.1, February 1999 * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ public static void displayURL(String url) { try { if (url.toLowerCase().startsWith("file://")) url = url.substring(7); Object desktop = Class.forName("java.awt.Desktop").getMethod( "getDesktop", new Class[0]).invoke(null, new Object[0]); desktop.getClass().getMethod("open", new Class[] { java.io.File.class }).invoke(desktop, new Object[] { new java.io.File(url) }); } catch (Throwable ex1) { if (!url.toLowerCase().startsWith("file://")) url = "file://" + url; boolean windows = false; String os = System.getProperty("os.name"); if (os != null && os.startsWith("Windows")) windows = true; String cmd = null; try { if (windows) { // cmd = 'rundll32 url.dll,FileProtocolHandler http://...' cmd = "rundll32 url.dll,FileProtocolHandler " + url; Process p = Runtime.getRuntime().exec(cmd); } else { // Under Unix, Netscape has to be running for the "-remote" // command to work. So, we try sending the command and // check for an exit value. If the exit command is 0, // it worked, otherwise we need to start the browser. // cmd = 'netscape -remote // openURL(http://www.javaworld.com)' cmd = "netscape -remote openURL(" + url + ")"; Process p = Runtime.getRuntime().exec(cmd); try { // wait for exit code -- if it's 0, command worked, // otherwise we need to start the browser up. int exitCode = p.waitFor(); if (exitCode != 0) { // Command failed, start up the browser // cmd = 'netscape http://www.javaworld.com' cmd = "netscape " + url; p = Runtime.getRuntime().exec(cmd); } } catch (InterruptedException ex) { System.out.println( "Error while showing local document (cmd='" + cmd + "':\n" + ex.getMessage()); ex.printStackTrace(); } } } catch (Exception ex) { // couldn't exec viewer System.out.println("Error while local document (cmd='" + cmd + "':\n"); ex.printStackTrace(); } } } ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 20.06.2007, 16:50:30 |
|
||
|
|

start [/forum/topic.php?fid=59&msg=34608477&tid=2145363]: |
0ms |
get settings: |
17ms |
get forum list: |
25ms |
check forum access: |
6ms |
check topic access: |
6ms |
track hit: |
60ms |
get topic data: |
17ms |
get forum data: |
4ms |
get page messages: |
69ms |
get tp. blocked users: |
3ms |
| others: | 367ms |
| total: | 574ms |

| 0 / 0 |
