5
J'essaie d'enregistrer un classeur qui a été modifié automatiquement. Voici un exemple:Comment enregistrer un classeur Excel en utilisant l'API com4j sans y être invité
import excel.*;
import com4j.Variant;
import static com4j.Variant.MISSING;
public class ExcelDemo {
public static void main(String[] args) {
_Application app = excel.ClassFactory.createApplication();
app.visible(0,false);
//Variant readOnly = new Variant(Variant.Type.VT_BOOL);
//readOnly.set(0);
//Variant ignoreReadOnly = new Variant(Variant.Type.VT_BOOL);
//ignoreReadOnly.set(1);
//Variant saveBeforeExit = new Variant(Variant.Type.VT_BOOL);
//saveBeforeExit.set(1);
app.workbooks().open(
"C:/dev/test.xlsx",
MISSING,
MISSING,
MISSING,
MISSING,
MISSING,
MISSING,
MISSING,
MISSING,
MISSING,
MISSING,
MISSING,
MISSING,
MISSING,
MISSING,
0);
app.calculate(0);
app.save(MISSING,0);
app.workbooks().close(0);
//app.workbooks().close(saveBeforeExit,MISSING,MISSING);
}
}
Le code ci-dessus a été exécuté à partir d'un fichier ant et produit l'erreur suivante:
run:
[java] Exception in thread "main" com4j.ComException: 800a03ec (Unknown error) : The file could not be accessed. Try one of the following:
[java]
[java] ò Make sure the specified folder exists.
[java] ò Make sure the folder that contains the file is not read-only.
[java] ò Make sure the file name does not contain any of the following characters: < > ? [ ] : | or *
[java] ò Make sure the file/path name doesn't contain more than 218 characters. : .\invoke.cpp:460
[java] at com4j.Wrapper.invoke(Wrapper.java:122)
[java] at $Proxy5.save(Unknown Source)
[java] at ExcelDemo.main(ExcelDemo.java:36)
[java] Caused by: com4j.ComException: 800a03ec (Unknown error) : The file could not be accessed. Try one of the following:
[java]
[java] ò Make sure the specified folder exists.
[java] ò Make sure the folder that contains the file is not read-only.
[java] ò Make sure the file name does not contain any of the following characters: < > ? [ ] : | or *
[java] ò Make sure the file/path name doesn't contain more than 218 characters. : .\invoke.cpp:460
[java] at com4j.Native.invoke(Native Method)
[java] at com4j.StandardComMethod.invoke(StandardComMethod.java:95)
[java] at com4j.Wrapper$InvocationThunk.call(Wrapper.java:258)
[java] at com4j.Task.invoke(Task.java:44)
[java] at com4j.ComThread.run0(ComThread.java:149)
[java] at com4j.ComThread.run(ComThread.java:125)
[java] Java Result: 1
J'ai essayé des choses et n'ont réussi suivantes:
- définissant le paramètre readOnly false
- définissant le paramètre ignoreReadOnly true
- Faire la fois 1 et 2
- passer l'objet saveBeforeExit à la méthode de sauvegarde
Est-il possible d'enregistrer un classeur sans être invité? Notez que le code ci-dessus ouvre le fichier et calcule les formules sans erreurs.
Merci
une raison quelconque vous ne souhaitez pas utiliser POI: http://poi.apache.org/ – tronda
@tronda: J'ai besoin de calculer un classeur contenant plusieurs feuilles de formules. POI peut évaluer des formules dans des cellules seulement. Je suis proche d'avoir une solution en utilisant l'API com4j. Va poster bientôt. – kninja