// Getting a collection of all documents from the database.
DocumentCollection documentcollection = database.getAllDocuments();
// Getting the first document from the database
Document document = documentcollection.getFirstDocument();
// Start to write to cells at this row.
int intRowToStart = 0;
// The current row.
int intRow = intRowToStart;
// The current column.
int intColumn = 0;
// Process all documents
while ( document != null ) {
// Getting the name of the stock.
String stringName = document.getItemValueString( "Name" );
// Inserting the name to a specified cell.
insertIntoCell( intColumn, intRow, stringName, xspreadsheet, "" );
// Getting the number of stocks.
double intNumber = document.getItemValueInteger( "Number" );
// Inserting the number of stocks to a specified cell.
insertIntoCell( intColumn + 1, intRow, String.valueOf( intNumber ),
xspreadsheet, "V" );
// Getting current share price.
double doubleSharePrice = document.getItemValueDouble( "SharePrice" );
// Inserting the current share price to a specified cell.
insertIntoCell( intColumn + 2, intRow, String.valueOf( doubleSharePrice ),
xspreadsheet, "V" );