Hi,
I am new to openoffice programming in C++.
I need help, specially opening, saving and closing the spreadsheet file
like simple file operations (fopen, fread, fwrite) in C.
I got few examples in openoffice website, where it requires
to start the office application in listen mode for executing
my application, which is not my requirement.
If anyone provides me the example, it will be very helpful
for me.
Thanks in advance
Satish
[Solved] Spreadsheet programming in C++
-
SatishPindikoor
- Posts: 5
- Joined: Fri Jul 03, 2009 12:33 pm
[Solved] Spreadsheet programming in C++
Last edited by SatishPindikoor on Tue Jul 21, 2009 9:30 am, edited 1 time in total.
OOo 2.3.X on openSuse 10 + Windows XP
Re: Spreadsheet programming in C++
Your requirement or not. That's the way it is.
I moved this out of the Calc forum.
I moved this out of the Calc forum.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Spreadsheet programming in C++
Alternatively, look at the ODF Toolkit Project, but this is in Java or C#.
Ubuntu 14.10 Utopic Unicorn, LibreOffice Version: 4.3.3.2
Gurkha Welfare Trust
Gurkha Welfare Trust
-
SatishPindikoor
- Posts: 5
- Joined: Fri Jul 03, 2009 12:33 pm
Re: Spreadsheet programming in C++
Sorry, for misleading statements in the Question framed by me.Villeroy wrote:Your requirement or not. That's the way it is.
I moved this out of the Calc forum.
I just wanted to know is there any way to handle the SpreadSheet document
as a simple file and fill the data into the document.
My goal is to create and write the data into the spreadsheet document.
Please note that, no viewing of data is required.
My application will run as a background process, which
has to generate the reports in spreadsheet document format.
I have followed some steps, but i am not sure that i am correct, can someone
verify it.
Programming Language: C++
int main (int argc, char** argv)
{
Reference <XComponentContext> compContext = bootstrap();
Reference <XMultiComponentFactory> serviceManager =
compContext->getServiceManager();
Reference <XInterface> rSpreadSheetDoc =
serviceManager->createInstanceWithContext (
OUString::createFromAscii ("com.sun.star.sheet.SpreadSheetDocument"),
compContext);
Reference <XSpreadSheetDocument> spreadSheetDoc (rSpreadSheetDoc, UNO_QUERY);
-- Some statements to store the data into the spreadsheet doc reference, by extracting the cells
and filling up the cells with the data---
Reference <XStorable> spreadSheetSave (rSpreadSheetDoc, UNO_QUERY);
// Note: argv[1] provides the path with filename.
OUString savePath;
osl::FileBase::getFileURLFromSystemPath (OUString::createFromAscii (argv[1], savePath);
try
{
spreadSheetSave ->storeAsURL (savePath, Sequence <::com::sun:
}
catch (com::sun:
{
cout<<"Error code ::" << e.ErrCode << endl;
}
return 0;
}
In above executable statements each and every interface's reference is getting initialized, but
when i tried to save the document with XStorable:storeAsURL method it throws an exception
with error code : 3088.
Please let me know if any mistakes i have done, and also, let me know where i can find
the error code description. For example what error code 3088 stands for.
With Thanks
Satish
OOo 2.3.X on openSuse 10 + Windows XP
Re: Spreadsheet programming in C++
OpenOffice.org produces ODF documents, which is basically XML in a zip archive. Unzip your documents and see. The file format is free by any means. ODF is not another vendor's proprietary file format for one distinct application only.
The home of the file format: http://opendocument.xml.org/
An office independent API: http://odftoolkit.org/
Of course you are free to use the API of a running OOo instance to do the job through the UNO framework. In this case you should refer to
http://development.openoffice.org
The home of the file format: http://opendocument.xml.org/
An office independent API: http://odftoolkit.org/
Of course you are free to use the API of a running OOo instance to do the job through the UNO framework. In this case you should refer to
http://development.openoffice.org
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
-
SatishPindikoor
- Posts: 5
- Joined: Fri Jul 03, 2009 12:33 pm
Re: Spreadsheet programming in C++
Thanks for providing the links.Villeroy wrote:OpenOffice.org produces ODF documents, which is basically XML in a zip archive. Unzip your documents and see. The file format is free by any means. ODF is not another vendor's proprietary file format for one distinct application only.
The home of the file format: http://opendocument.xml.org/
An office independent API: http://odftoolkit.org/
Of course you are free to use the API of a running OOo instance to do the job through the UNO framework. In this case you should refer to
http://development.openoffice.org
I gone through the XML specifications from ODF, It doesn't support for storing the chart information, in the same XML
in which excel data is stored.
When i tried with using the API's, as shown in the code snippet of previous reply, each and every instance is getting initialized,
even XStorable is also intiailized, but while saving it throws an exception.
Can some one verify the code snippet provided in previous reply.
OOo 2.3.X on openSuse 10 + Windows XP
-
SatishPindikoor
- Posts: 5
- Joined: Fri Jul 03, 2009 12:33 pm
[SOLVED] Spreadsheet programming in C++
Hi All,
Thanks to all who helped me to solve my problem.
At last i am able to create the spreadsheet at background (hidden status) .
Below is the code. Hope, it will help for others:
Goal: A spreadsheet file has to be created with the file name specified in the command line arguments
add the data to it.
Note: No exception handling is done. Person using this code shall add the exception handling
statements to make sure application is safe.
int main (int argc, char** argv)
{
// Perform bootstrap.
Reference <XComponentContext> componentContext = bootstrap();
// Get the Service manager for retrieving the required services.
Reference <XMultiComponentFactory> serviceManager =
componentContext->getServiceManager();
// get the desktop object
Reference <XInterface> desktop =
serviceManager->createInstanceWithContext (
OUString::createFromAscii( "com.sun.star.frame.Desktop" ),
componentContext);
// Instantiate the component loader.
Reference <XComponentLoader> compLoader (desktop, UNO_QUERY);
// File properties for the blank file.
Sequence < ::com::sun:
:beans::PropertyValue > fileProperties (2);
fileProperties[0].Name = OUString::createFromAscii ("AsTemplate");
fileProperties[0].Value <<= OUString::createFromAscii ("MS Excel 97");
fileProperties[1].Name = OUString::createFromAscii ("Hidden");
fileProperties[1].Value <<= true;
// Instantiate the component.
Reference <XComponent> component = compLoader->loadComponentFromURL (
OUString::createFromAscii("private:factory/scalc"),
OUString::createFromAscii("_default"),
0,
fileProperties);
// By this a blank spreadsheet will be loaded, in hide mode i.e. spreadsheet won't be visible to the user.
// Create instance for the srpeadsheet document.
// Thir reference can be used to perform multiple operation on the spreadsheet.
Reference <XSpreadsheetDocument> spreadDoc (component, UNO_QUERY);
// Statements for storing the data into the spreadsheet.
// Note: Argv[1] contains the path with file name.
// Convert to UNO compatible URL.
OUString documentPath;
osl::FileBase::getFileURLFromSystemPath(OUString::createFromAscii(argv[1]), documentPath);
// Now store the data to the specified file.
Reference <XStorable> docStore (spreadDoc, UNO_QUERY);
doc->storeAsURL (documentPath,
Sequence < ::com::sun:
:beans::PropertyValue >());
return 0;
}
Thanks to all who helped me to solve my problem.
At last i am able to create the spreadsheet at background (hidden status) .
Below is the code. Hope, it will help for others:
Goal: A spreadsheet file has to be created with the file name specified in the command line arguments
add the data to it.
Note: No exception handling is done. Person using this code shall add the exception handling
statements to make sure application is safe.
int main (int argc, char** argv)
{
// Perform bootstrap.
Reference <XComponentContext> componentContext = bootstrap();
// Get the Service manager for retrieving the required services.
Reference <XMultiComponentFactory> serviceManager =
componentContext->getServiceManager();
// get the desktop object
Reference <XInterface> desktop =
serviceManager->createInstanceWithContext (
OUString::createFromAscii( "com.sun.star.frame.Desktop" ),
componentContext);
// Instantiate the component loader.
Reference <XComponentLoader> compLoader (desktop, UNO_QUERY);
// File properties for the blank file.
Sequence < ::com::sun:
fileProperties[0].Name = OUString::createFromAscii ("AsTemplate");
fileProperties[0].Value <<= OUString::createFromAscii ("MS Excel 97");
fileProperties[1].Name = OUString::createFromAscii ("Hidden");
fileProperties[1].Value <<= true;
// Instantiate the component.
Reference <XComponent> component = compLoader->loadComponentFromURL (
OUString::createFromAscii("private:factory/scalc"),
OUString::createFromAscii("_default"),
0,
fileProperties);
// By this a blank spreadsheet will be loaded, in hide mode i.e. spreadsheet won't be visible to the user.
// Create instance for the srpeadsheet document.
// Thir reference can be used to perform multiple operation on the spreadsheet.
Reference <XSpreadsheetDocument> spreadDoc (component, UNO_QUERY);
// Statements for storing the data into the spreadsheet.
// Note: Argv[1] contains the path with file name.
// Convert to UNO compatible URL.
OUString documentPath;
osl::FileBase::getFileURLFromSystemPath(OUString::createFromAscii(argv[1]), documentPath);
// Now store the data to the specified file.
Reference <XStorable> docStore (spreadDoc, UNO_QUERY);
doc->storeAsURL (documentPath,
Sequence < ::com::sun:
return 0;
}
OOo 2.3.X on openSuse 10 + Windows XP