--CSV export of databooks
1 post
• Page 1 of 1
--CSV export of databooks
This article is outdated - please use our new system at
https://doc.sibvisions.com
If you need a CSV export of a databook, there's already a built-in solution in JVx. Of course, it depends on your databook implementation, whether it's a RemoteDataBook or a MemDataBook, or completely different.
But usually, following snippet will help:
IFileHandle file;
if (pDataBook instanceof RemoteDataBook)
{
pDataBook.saveAllRows();
AbstractConnection pConnection = ((RemoteDataBook)pDataBook).getDataSource().
getConnection();
file = (IFileHandle)pConnection.call(pDataBook.getName(), "createCSV",
columnNames, labels, filter,
pDataBook.getSort(), LocaleUtil.getDefault().toString());
}
else
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataBookCSVExporter.writeCSV(pDataBook, bos,
columnNames, labels, filter, null);
bos.close();
file = new FileHandle(DataBookCSVExporter.formatCSVFileName(pDataBook.getName()),
bos.toByteArray());
}
ILauncher launcher = ApplicationUtil.getLauncher(pComponent);
if (pShow)
{
launcher.showFileHandle(file);
}
else
{
launcher.saveFileHandle(file, null);
}
if (pDataBook instanceof RemoteDataBook)
{
pDataBook.saveAllRows();
AbstractConnection pConnection = ((RemoteDataBook)pDataBook).getDataSource().
getConnection();
file = (IFileHandle)pConnection.call(pDataBook.getName(), "createCSV",
columnNames, labels, filter,
pDataBook.getSort(), LocaleUtil.getDefault().toString());
}
else
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataBookCSVExporter.writeCSV(pDataBook, bos,
columnNames, labels, filter, null);
bos.close();
file = new FileHandle(DataBookCSVExporter.formatCSVFileName(pDataBook.getName()),
bos.toByteArray());
}
ILauncher launcher = ApplicationUtil.getLauncher(pComponent);
if (pShow)
{
launcher.showFileHandle(file);
}
else
{
launcher.saveFileHandle(file, null);
}
You'll need a databook (pDataBook) and the launcher or a UI component (pComponent). The export of remote databooks is implemented in the remote storage, so simply call the remote method. The export of memory databooks will be done with DataBookCSVExporter.
If you want to create CSV exports of server-side storages, have a look at following project: AESStorageExport.
The project is an extension that allows CSV creation of one or more storages and it supports ZIP creation - with or without password protection.
-
Development@SIB - Posts: 325
- Joined: Mon Sep 28, 2009 1:54 pm
1 post
• Page 1 of 1