The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Datagrid Export into MS Excel
Posted: 20 Aug 06 12:01 PM
|
fiogf49gjkf0d I search how to export data from a datagrid into a MS Excel workbook with microsoft vbscript functions (or saleslogix functions). I have no sucess with forum solutions |
|
|
| |
|
Re: Datagrid Export into MS Excel
Posted: 21 Aug 06 12:04 AM
|
fiogf49gjkf0d I used it from the link above, and it worked like a charm (just great).
Thanks for that article Ryan! |
|
|
|
Re: Datagrid Export into MS Excel
Posted: 21 Aug 06 7:35 AM
|
fiogf49gjkf0d Here is a custom function that I wrote in VBScript a while back to export a data grid to excel. you are welcome to it. You may need to clean it up a little.
[BEGIN] Function ExportDGtoExcel(datagrid,mySheet,myBook,StartCell,FileName,shohidden) Dim Row 'Create a new workbook in Excel. 'Transfer the field names to Row 1 of the worksheet: 'Note: CopyFromRecordset copies only the data and not the field ' names, so you can transfer the fieldnames by traversing the ' fields collection. 'Get Row number from StartCell Row = Right(StartCell,len(startcell) -1) + 1 ' msgbox row Dim n For n = 1 to datagrid.Columns.Count '-1 mySheet.Cells.EntireRow.cells(Row,n).Font.Bold = "True" mySheet.columns(n).columnwidth = ((datagrid.Columns.Item(n-1).Width)/3) mySheet.Cells(row, n).Value = datagrid.Columns.Item(n-1).Caption IF shohidden =0 then IF datagrid.Columns.Item(n-1).Visible = False then mySheet.columns(n).hidden = True End IF End IF Next 'Transfer the data to Excel. mySheet.Range("A" & cstr(row +1)).CopyFromRecordset(datagrid.recordset) 'Save the workbook and quit Excel. myBook.SaveAs(FileName) 'GC.Collect() 'Close the connection ExportDGtoExcel= 1 End Function [END] |
|
|
|
Re: Datagrid Export into MS Excel
Posted: 21 Aug 06 5:59 PM
|
fiogf49gjkf0d i have already try this. when i execute the script i have an error xlApp object require i work on SalesLogix 6.2.2 French Version and Microsoft Office XP Thanks for your help
|
|
|
|
Re: Datagrid Export into MS Excel
Posted: 22 Aug 06 3:05 AM
|
fiogf49gjkf0d I don't mean to be rude, but (just to cover the basics) can you confirm that Excel is installed on the machine that is returning the error?
If so, please post the script you are running and the exact error message.
Regards Phil |
|
|
|
Re: Datagrid Export into MS Excel
Posted: 22 Aug 06 2:48 PM
|
fiogf49gjkf0d Hi
I have solve the problem
On my computer it's impossible to create a workbook instance (Set xlWb = xlApp.Workbooks.Add) with file or not file. I don't know where is the Microsoft com Problem.
On another computer i don't have the problem
Thanks
|
|
|
|
Re: Datagrid Export into MS Excel
Posted: 04 Feb 10 4:32 AM
|
Hi Ryan, i have used your script with my modifications and get my Excell document! But it is problem, after document is created program automatically switches(come back) to slx window. But I need that program stay in Excel document window. How can I do this?
Thank you |
|
|
|
Re: Datagrid Export into MS Excel
Posted: 05 Feb 10 4:42 AM
|
Hi AlexUA,
i assume that the excel application is still in the background. To make the Excel application visible you have to set the property Visible to True and to maximuze the Excel Window you have to set the WindowState property. Please have a look at the example code below:
Const xlMaximized = -4137 Const xlMinimized = -4140 Const xlNormal = -4143 Dim oExcel, oExcelWB, oExcelSheet
On Error Resume Next Set oExcel = CreateObject("Excel.Application") Set oExcelWB = oExcel.WorkBooks.Add Set oExcelSheet = oExcelWB.WorkSheets("Tabelle1")
oExcel.Visible = True
oExcel.WindowState = xlMinimized oExcel.WindowState = xlMaximized
' destroy all Excel COM Objects Set oExcel = Nothing Set oExcelWB = Nothing Set oExcelSheet = Nothing
Due to the fact that I have found a lot of issues with mamximizing the window, I do the workaround of first minimizing and then maximizing the window.
Cheers, Thomas |
|
|
|
Re: Datagrid Export into MS Excel
Posted: 05 Feb 10 7:22 AM
|
Hi, thanks for your code, but It doesnt help me Maybe because my slx window form is modal? The window realy minimizing and maximizing but at the End stops at slx window... |
|
|
|