MS Officeとのメールマージを行うC#アプリケーションがあります(Interop APIを使用)。 私は現在Open Officeをサポートしようとしています。 私はOpenOfficeのSDKを使用したい:http://www.openoffice.org/api/docs/common/ref/com/sun/star/text/MailMerge.html#CommandOpenOffice SDKを使用してデータソースを作成中に例外キャスト
が今私には明確な結晶を見ていません....私は何とか差し込み印刷コードを動作させるために、管理
。 実際にMailMergeを実行する前に "DataSource"を作成する必要があります。問題が発生しました。
私はここでのJavaのサンプルを取得することができます: https://wiki.openoffice.org/wiki/Documentation/DevGuide/Database/The_DataSource_Service
を私はC#のにこれを変換する必要があります。
私の難易度は、Javaがそのキャストを実行するために、このオブジェクトを使用していることである:
XStorable store = (XStorable)UnoRuntime.queryInterface(XStorable.class, xDs);
C#で同等のものはありません。
私はコードをこのように変換:
public static void CreateDataSource(string dataSourceProvidedFilePath, string dataSourceSavedFilePath)
{
XComponentContext oStrap = uno.util.Bootstrap.bootstrap();
XMultiServiceFactory _rMSF = (XMultiServiceFactory)oStrap.getServiceManager();
// the XSingleServiceFactory of the database context creates new generic
// com.sun.star.sdb.DataSources (!)
// retrieve the database context at the global service manager and get its
// XSingleServiceFactory interface
XSingleServiceFactory xFac = (XSingleServiceFactory) _rMSF.createInstance("com.sun.star.sdb.DatabaseContext");
//(XSingleServiceFactory)UnoRuntime.queryInterface(XSingleServiceFactory.class, _rMSF.createInstance("com.sun.star.sdb.DatabaseContext"));
// instantiate an empty data source at the XSingleServiceFactory
// interface of the DatabaseContext
Object xDs = xFac.createInstance();
// register it with the database context
XNamingService xServ = (XNamingService)xFac;
//(XNamingService)UnoRuntime.queryInterface(XNamingService.class, xFac);
XStorable store = (XStorable) xDs;
//(XStorable)UnoRuntime.queryInterface(XStorable.class, xDs);
XModel model =(XModel) xDs;
//(XModel)UnoRuntime.queryInterface(XModel.class, xDs);
//on détermine le fichier ou sera sauvegardée la data source
string dataSourcePathURL = Path.Combine(Path.GetDirectoryName(dataSourceProvidedFilePath), dataSourceSavedFilePath + ".odb").ConvertToOpenOfficeURL();
store.storeAsURL(/*"file:///c:/test.odb"*/dataSourcePathURL,model.getArgs());
xServ.registerObject("NewDataSourceName", xDs);
// setting the necessary data source properties
XPropertySet xDsProps = (XPropertySet)xDs;
//(XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xDs);
// Adabas D URL
xDsProps.setPropertyValue("URL", new uno.Any("sdbc:adabas::MYDB1"));
// force password dialog
//xDsProps.setPropertyValue("IsPasswordRequired", new Boolean(true));
// suggest dsadmin as user name
xDsProps.setPropertyValue("User", new uno.Any("dsadmin"));
store.store();
}
一部キャストがうまく働いた:
XNamingService xServ = (XNamingService)xFac;
//(XNamingService)UnoRuntime.queryInterface(XNamingService.class, xFac);
しかし、いくつかの他のキャストは例外をスロー:
XStorable店=(XStorable)XDSを。 //(XStorable)UnoRuntime.queryInterface(XStorable.class、xDs);
- 正しくCの#に変換し、このコードを持つ方法は>
Unable to cast transparent proxy to type 'unoidl.com.sun.star.frame.XStorable'.
ありますか?
それ以外の場合は、Open Office DataSourceをJavaで作成する方法を示す他のリソースがありますか?
Thxを