{"id":644,"date":"2008-05-18T04:15:12","date_gmt":"2008-05-18T04:15:12","guid":{"rendered":"http:\/\/6teen.ru\/?p=527"},"modified":"2008-05-18T04:15:12","modified_gmt":"2008-05-18T04:15:12","slug":"8850","status":"publish","type":"post","link":"http:\/\/pblog.ru\/lab\/?p=644","title":{"rendered":"\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430 ADO \u0442\u0430\u0431\u043b\u0438\u0446 \u0432 \u0440\u0430\u0437\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b"},"content":{"rendered":"<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430 ADO \u0442\u0430\u0431\u043b\u0438\u0446 \u0432 \u0440\u0430\u0437\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b<br \/>\n<!--more--><\/p>\n<pre class=\"alt2\" style=\"margin:0px; padding:6px; border:1px inset; width:580px; height:320px; overflow:auto\"><div>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430 ADO \u0442\u0430\u0431\u043b\u0438\u0446 \u0432 \u0440\u0430\u0437\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b\n\n\u0410\u0432\u0442\u043e\u0440: carlo Pasolini, Riccione(italy), e-mail: ccpasolini@libero.it\n{\nExporting ADO tables into various formats\n\nIn this article I want to present a component I built in order to\nsupply exporting features to the ADOTable component. ADO supplies\nan extended SQL syntax that allows exporting of data into various\nformats. I took into consideration the following formats:\n\n1)Excel\n2)Html\n3)Paradox\n4)Dbase\n5)Text\n\nYou can see all supported output formats in the registry:\n\"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Jet\\4.0\\ISAM formats\"\n\nThis is the complete source of my component }\n\nunit ExportADOTable;\n\ninterface\n\nuses\nWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,\nDb, ADODB;\n\ntype\nTExportADOTable = class(TADOTable)\nprivate\n{ Private declarations }\n\/\/TADOCommand component used to execute the SQL exporting commands\nFADOCommand: TADOCommand;\nprotected\n{ Protected declarations }\npublic\n{ Public declarations }\nconstructor Create(AOwner: TComponent); override;\n\n\/\/Export procedures\n\/\/\"FiledNames\" is a comma separated list of the names of the fields you want to export\n\/\/\"FileName\" is the name of the output file (including the complete path)\n\/\/if the dataset is filtered (Filtered = true and Filter <> ''), then I append\n\/\/the filter string to the sql command in the \"where\" directive\n\/\/if the dataset is sorted (Sort <> '') then I append the sort string to the sql command in the\n\/\/\"order by\" directive\n\nprocedure ExportToExcel(FieldNames: string; FileName: string;\nSheetName: string; IsamFormat: string);\nprocedure ExportToHtml(FieldNames: string; FileName: string);\nprocedure ExportToParadox(FieldNames: string; FileName: string; IsamFormat:\nstring);\nprocedure ExportToDbase(FieldNames: string; FileName: string; IsamFormat:\nstring);\nprocedure ExportToTxt(FieldNames: string; FileName: string);\npublished\n{ Published declarations }\nend;\n\nprocedure Register;\n\nimplementation\n\nprocedure Register;\nbegin\nRegisterComponents('Carlo Pasolini', [TExportADOTable]);\nend;\n\nconstructor TExportADOTable.Create(AOwner: TComponent);\nbegin\ninherited;\n\nFADOCommand := TADOCommand.Create(Self);\nend;\n\nprocedure TExportADOTable.ExportToExcel(FieldNames: string; FileName: string;\nSheetName: string; IsamFormat: string);\nbegin\n{IsamFormat values\nExcel 3.0\nExcel 4.0\nExcel 5.0\nExcel 8.0\n}\n\nif not Active then\nExit;\nFADOCommand.Connection := Connection;\nFADOCommand.CommandText := 'Select ' + FieldNames + ' INTO ' + '[' +\nSheetName + ']' + ' IN ' + '\"' + FileName + '\"' + '[' + IsamFormat +\n';]' + ' From ' + TableName;\nif Filtered and (Filter <> '') then\nFADOCommand.CommandText := FADOCommand.CommandText + ' where ' + Filter;\nif (Sort <> '') then\nFADOCommand.CommandText := FADOCommand.CommandText + ' order by ' + Sort;\nFADOCommand.Execute;\nend;\n\nprocedure TExportADOTable.ExportToHtml(FieldNames: string; FileName: string);\nvar\nIsamFormat: string;\nbegin\nif not Active then\nExit;\n\nIsamFormat := 'HTML Export';\n\nFADOCommand.Connection := Connection;\nFADOCommand.CommandText := 'Select ' + FieldNames + ' INTO ' + '[' +\nExtractFileName(FileName) + ']' +\n' IN ' + '\"' + ExtractFilePath(FileName) + '\"' + '[' + IsamFormat +\n';]' + ' From ' + TableName;\nif Filtered and (Filter <> '') then\nFADOCommand.CommandText := FADOCommand.CommandText + ' where ' + Filter;\nif (Sort <> '') then\nFADOCommand.CommandText := FADOCommand.CommandText + ' order by ' + Sort;\nFADOCommand.Execute;\nend;\n\nprocedure TExportADOTable.ExportToParadox(FieldNames: string;\nFileName: string; IsamFormat: string);\nbegin\n{IsamFormat values\nParadox 3.X\nParadox 4.X\nParadox 5.X\nParadox 7.X\n}\nif not Active then\nExit;\n\nFADOCommand.Connection := Connection;\nFADOCommand.CommandText := 'Select ' + FieldNames + ' INTO ' + '[' +\nExtractFileName(FileName) + ']' +\n' IN ' + '\"' + ExtractFilePath(FileName) + '\"' + '[' + IsamFormat +\n';]' + ' From ' + TableName;\nif Filtered and (Filter <> '') then\nFADOCommand.CommandText := FADOCommand.CommandText + ' where ' + Filter;\nif (Sort <> '') then\nFADOCommand.CommandText := FADOCommand.CommandText + ' order by ' + Sort;\nFADOCommand.Execute;\nend;\n\nprocedure TExportADOTable.ExportToDbase(FieldNames: string; FileName: string;\nIsamFormat: string);\nbegin\n{IsamFormat values\ndBase III\ndBase IV\ndBase 5.0\n}\nif not Active then\nExit;\n\nFADOCommand.Connection := Connection;\nFADOCommand.CommandText := 'Select ' + FieldNames + ' INTO ' + '[' +\nExtractFileName(FileName) + ']' +\n' IN ' + '\"' + ExtractFilePath(FileName) + '\"' + '[' + IsamFormat +\n';]' + ' From ' + TableName;\nif Filtered and (Filter <> '') then\nFADOCommand.CommandText := FADOCommand.CommandText + ' where ' + Filter;\nif (Sort <> '') then\nFADOCommand.CommandText := FADOCommand.CommandText + ' order by ' + Sort;\nFADOCommand.Execute;\nend;\n\nprocedure TExportADOTable.ExportToTxt(FieldNames: string; FileName: string);\nvar\nIsamFormat: string;\nbegin\nif not Active then\nExit;\n\nIsamFormat := 'Text';\n\nFADOCommand.Connection := Connection;\nFADOCommand.CommandText := 'Select ' + FieldNames + ' INTO ' + '[' +\nExtractFileName(FileName) + ']' +\n' IN ' + '\"' + ExtractFilePath(FileName) + '\"' + '[' + IsamFormat +\n';]' + ' From ' + TableName;\nif Filtered and (Filter <> '') then\nFADOCommand.CommandText := FADOCommand.CommandText + ' where ' + Filter;\nif (Sort <> '') then\nFADOCommand.CommandText := FADOCommand.CommandText + ' order by ' + Sort;\nFADOCommand.Execute;\nend;\n\nend.\n\n{\nNote that you can use an already existing database as destination but not an already existing\ntable in the database itself: if you specify an already exixting table you will receive\nan error message. You might insert a verification code inside every exporting procedure of my\ncomponent, before the execution of the sql exporting command, in order to send a request of\ndeleting the already present table or aborting the exporting process.\n}\n<\/div><\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430 ADO \u0442\u0430\u0431\u043b\u0438\u0446 \u0432 \u0440\u0430\u0437\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[392,434],"tags":[1900,808,1667,1008,1833,1871],"_links":{"self":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/644"}],"collection":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=644"}],"version-history":[{"count":0,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/644\/revisions"}],"wp:attachment":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=644"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}