{"id":523,"date":"2008-05-09T21:20:07","date_gmt":"2008-05-09T21:20:07","guid":{"rendered":"http:\/\/6teen.ru\/?p=727"},"modified":"2008-05-09T21:20:07","modified_gmt":"2008-05-09T21:20:07","slug":"108","status":"publish","type":"post","link":"http:\/\/pblog.ru\/lab\/?p=523","title":{"rendered":"\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c StringGrid \u0432 Excel \u0444\u0430\u0439\u043b\u0435"},"content":{"rendered":"<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c StringGrid \u0432 Excel \u0444\u0430\u0439\u043b\u0435<br \/>\n<!--more--><\/p>\n<pre class=\"alt2\" style=\"margin:0px; padding:6px; border:1px inset; width:580px; height:320px; overflow:auto\"><div>\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c StringGrid \u0432 Excel \u0444\u0430\u0439\u043b\u0435\n\nfunction saveasexcelfile(stringgrid: tstringgrid; filename: string): boolean;\nconst xlwbatworksheet = -4167;\nvar row, col: integer;\n      gridprevfile: string;\n      xlapp, sheet: olevariant;\nbegin\nresult := false;\nxlapp := createoleobject('excel.application');\ntry\nxlapp.visible := false;\nxlapp.workbooks.add(xlwbatworksheet);\nsheet := xlapp.workbooks[1].worksheets[1];\nsheet.name := 'my sheet name';\nfor col := 0 to stringgrid.colcount - 1 do\nfor row := 0 to stringgrid.rowcount - 1 do\nsheet.cells[row + 1, col + 1] := stringgrid.cells[col, row];\ntry\nxlapp.workbooks[1].saveas(filename);\nresult := true;\nexcept\n\/\/ error ?\nend;\nfinally\nif not varisempty(xlapp) then\nbegin\nxlapp.displayalerts := false;\nxlapp.quit;\nxlapp := unassigned;\nsheet := unassigned;\nend;\nend;\nend;\n\nprocedure tform1.button1click(sender: tobject);\nbegin\nif saveasexcelfile(stringgrid1, 'c:\\myexcelfile.xls') then\nshowmessage('stringgrid saved!');\nend;\n{*************************************************}\n\/\/ reiner schlay http:\/\/www.assu-assist.nl\/\n\nfunction reftocell(arow, acol: integer): string;\nbegin\nresult := chr(ord('a') + acol - 1) + i2s(arow);\nend;\n\nprocedure stringgridtoexcel(agrid: tstringgrid);\nvar\ni, j: integer;\nexcel: application_;\nbook: workbook;\nsheet: _worksheet;\ndata: olevariant;\nbegin\ndata := vararraycreate([1, agrid.rowcount, 1, agrid.colcount],\nvarvariant);\nfor i := 0 to agrid.colcount - 1 do\nfor j := 0 to agrid.rowcount - 1 do\ndata[j + 1, i + 1] := agrid.cells[i, j];\nexcel := coapplication_.create;\nbook := excel.workbooks.add(emptyparam, 0);\nsheet := excel.sheets.add(emptyparam, emptyparam, 1,\nxlworksheet, 0) as _worksheet;\nsheet.range[reftocell(1, 1), reftocell(agrid.rowcount,\nagrid.colcount)].value := data;\nexcel.visible[0] := true;\nexcel.usercontrol := true;\nend;\n<\/div><\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c StringGrid \u0432 Excel \u0444\u0430\u0439\u043b\u0435<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[62,416],"tags":[1891,1927,1756,344],"_links":{"self":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/523"}],"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=523"}],"version-history":[{"count":0,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/523\/revisions"}],"wp:attachment":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=523"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}