I'm trying to link .csv file as datasource for mailmerge in writer but I can't figure out whats wrong. When I run my code almost all works fine, I can see new datasource in writer, it contains table but there is some rubbish in this table (not data from file). Here's code of function supposed to link it :
Code: Select all
public static void createNewDataSource(com.sun.star.lang.XMultiComponentFactory _rMSF,
com.sun.star.uno.XComponentContext xContext) throws com.sun.star.uno.Exception {
XSingleServiceFactory xFac = (XSingleServiceFactory) UnoRuntime.queryInterface(XSingleServiceFactory.class,
_rMSF.createInstanceWithContext("com.sun.star.sdb.DatabaseContext", xContext));
Object xDs = xFac.createInstance();
XNamingService xServ = (XNamingService) UnoRuntime.queryInterface(XNamingService.class, xFac);
XDocumentDataSource xDDS = (XDocumentDataSource) UnoRuntime.queryInterface(XDocumentDataSource.class, xDs);
XStorable store = (XStorable) UnoRuntime.queryInterface(XStorable.class, xDDS.getDatabaseDocument());
XModel model = (XModel) UnoRuntime.queryInterface(XModel.class, xDDS.getDatabaseDocument());
store.storeAsURL("file:///C:/file", model.getArgs());
xServ.revokeObject("NewDataSourceName");
xServ.registerObject("NewDataSourceName", xDDS);
XPropertySet xDsProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xDDS);
xDsProps.setPropertyValue("URL", "sdbc:flat:C:/file.csv");
store.store();
}
I'm using LibreOffice but I think there isn't much difference and it's best place to get some help.
Amongalen