CreateExportFile
- Code: Select all
function createExportFile()
{
var form = arguments[0] //string, formname
var fieldnames = arguments[1] // boolean, export with ColumnNames at top
var seperator = arguments[2] // string, choose seperator, for example: "\t" for TAB "," or ";"
var quotes = arguments[3] // boolean, ColumnNames with quotes
var columnnames = arguments[4] // string, ColumnNames seperated by: ";"
var firstrow = arguments[5] // string, ColumnNames as Descriptions seperated by: ";"
var exportfile = "" // create a text variable
// set the variable insertquotes to " or nothing
if (quotes == true) var insertquotes = '"'
else var insertquotes = "";
// split the columnames into an Array
var columnArray = columnnames.split(";")
// determine how many columns are used
var columnCount = columnArray.length
// if fieldnames is true than place the ColumnNames at top
//if(fieldnames == true)
//{
// for(var x=0;x<= columnCount-1;x++)
// {
// if(x != columnCount-1) exportfile += columnArray[x] + seperator
// else exportfile += columnArray[x]
// }
// make an 'Enter'
exportfile += firstrow + "\n"
//}
// loop thru the foundset
for(var i=1;i<= forms[form].foundset.getSize();i++)
{
var record = forms[form].foundset.getRecord(i);
for(var x=0;x<= columnCount-1;x++)
{
if(record[columnArray[x]])
{
record[columnArray[x]] = utils.stringReplace(record[columnArray[x]],'\n', '')
record[columnArray[x]] = utils.stringReplace(record[columnArray[x]],'\r', '')
if(x != columnCount-1) exportfile += insertquotes + record[columnArray[x]] + insertquotes + seperator
else exportfile += insertquotes + record[columnArray[x]] + insertquotes
}
else
{
if(x != columnCount-1) exportfile += insertquotes + seperator
else exportfile += insertquotes
}
}
exportfile += "\n"
}
//Returns a string part with other part in a string
exportfile = utils.stringReplace(exportfile,'\n\";\"','\n\"\";\"');
exportfile = utils.stringReplace(exportfile,'\";\";','\";\"\";');
exportfile = utils.stringReplace(exportfile,'\";\"\n','\";\"\"\n');
exportfile = utils.stringReplace(exportfile,';\";',';\"\";');
//open dialog, with a suggested filename
var save = application.showFileSaveDialog('file_export.xls')
if(save != null)
{
var success = application.writeTXTFile(save,exportfile);
if (success)
{
plugins.dialogs.showInfoDialog('Info', 'The File is saved!','OK');
}
else
{
plugins.dialogs.showErrorDialog('Warning', 'The File is NOT saved because of an error!','OK');
}
}
}
StartExportFile
- Code: Select all
function startExportFile()
{
//first argument: give the form name
//second argument: boolean, export with ColumnNames at top
//third argument: string, choose seperator, for example: "\t" for TAB "," or ";"
//fourth argument: boolean, ColumnNames with quotes.
//fifth argument: string, ColumnNames seperated by: ";"
//show dialog
var _AbfrageExport = plugins.dialogs.showQuestionDialog('Export', 'Soll der Export mit den aufgerufenen Datensätzen durchgeführt werden, oder soll die Datenmenge erst reduziert werden?','Abbrechen', 'Export starten');
if ( _AbfrageExport == 'Abbrechen' ){
application.beep();
} else {
createExportFile('productsDesigner',true,";",true,globals.gbl_exportfields,globals.gbl_exportfieldnames);
}
I use the globals.gbl_exportfields for all the fields.
It works pretty well with text and integer but I get an error-message because of the format with datetime-fields.
Maybe I could use convert() with the field.
Oliver