Write from datagrid to Excel range
Write from datagrid to Excel range
Write from datagrid to Excel range
Write from datagrid to Excel range
Write from datagrid to Excel range
Write from datagrid to Excel range Write from datagrid to Excel range Write from datagrid to Excel range Write from datagrid to Excel range Write from datagrid to Excel range Write from datagrid to Excel range Write from datagrid to Excel range Write from datagrid to Excel range
Write from datagrid to Excel range Write from datagrid to Excel range
Write from datagrid to Excel range
Go Back  Xtreme Visual Basic Talk > > > Write from datagrid to Excel range


Reply
 
Thread Tools Display Modes
  #1  
Old 03-23-2005, 04:35 AM
staticbob's Avatar
staticbob staticbob is offline
Freshman
 
Join Date: Apr 2004
Location: Manchestershire UK
Posts: 33
Default Write from datagrid to Excel range


Folks,

I have this code that is used to copy text from a vb.net textbox into a named range in Excel, IF the names are the same. (Thanks Mike and Helen)

I would also like to transfer the contents of a datagrid into a named range on the same excel form. The named range in Excel is A6:E32. I have a column in the datagrid for each column in the excel named range.

Any starters ?

Thanks in advance,
Bob

Code:
            wkbk = xl.Workbooks.Open(TemplateLocation)
            wkst = wkbk.Sheets(1)

            For Each ctl As Control In Ucont
                For n As Integer = 1 To wkbk.Names.Count
                    Dim nm As Excel.Name = wkbk.Names.Item(n)
                    If StrComp(nm.Name, ctl.Name, CompareMethod.Text) = 0 Then
                        If TypeOf ctl Is TextBox Then
                            nm.RefersToRange.Value = CType(ctl, TextBox).Text
                        ElseIf TypeOf ctl Is ComboBox Then
                            nm.RefersToRange.Value = CType(ctl, ComboBox).Text
                        ElseIf TypeOf ctl Is DateTimePicker Then
                            nm.RefersToRange.Value = CType(ctl, DateTimePicker).Value
                        End If
                    End If
                Next
Reply With Quote
  #2  
Old 03-23-2005, 10:37 AM
herilane's Avatar
herilaneWrite from datagrid to Excel range herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

Bob, is that you asking a similar question at XtremeDotNetTalk? If yes, then I'd rather try and keep the discussion in one place only.
http://www.xtremedotnettalk.com/showthread.php?t=91819
Reply With Quote
  #3  
Old 03-23-2005, 02:41 PM
staticbob's Avatar
staticbob staticbob is offline
Freshman
 
Join Date: Apr 2004
Location: Manchestershire UK
Posts: 33
Default

Errmmmm, No !? But thanks for the link.

"If yes, the I'd rather try and keep the discussion in one place only." ...... and If No ??

Bob

PS - I've updated my profile just to clarify I'm me !
Reply With Quote
  #4  
Old 03-24-2005, 03:53 AM
herilane's Avatar
herilaneWrite from datagrid to Excel range herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

SonicBoom... StaticBob... sounded similar enough to me.
Well, if No, then we'll have a separate discussion here of course. But my initial advice is the same.

Lots of approaches discussed here:
http://support.microsoft.com/kb/306022/EN-US/

Assuming the datagrid is bound to a dataset, you should be able to use ADO.NET to push the data directly into an Excel sheet. That should be the fastest way.

If you want to create a new sheet, "SELECT * INTO" should work; if you want to replace existing data I think you'll have to open a new dataset for the Excel file and transfer the data from your bound dataset into the "Excel dataset" one record at a time. (Caveat: I've only tried this in VB6 and "ADO classic" but I don't see any reason why it would not work the same in ADO.NET).
Reply With Quote
  #5  
Old 03-24-2005, 02:48 PM
staticbob's Avatar
staticbob staticbob is offline
Freshman
 
Join Date: Apr 2004
Location: Manchestershire UK
Posts: 33
Default

I thankyou Helen,

I shall work on it over the weekend, yeah, Easter bank holiday weekend, then report back soon !

Cheers
Bob
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Write from datagrid to Excel range
Write from datagrid to Excel range
Write from datagrid to Excel range Write from datagrid to Excel range
Write from datagrid to Excel range
Write from datagrid to Excel range
Write from datagrid to Excel range Write from datagrid to Excel range Write from datagrid to Excel range Write from datagrid to Excel range Write from datagrid to Excel range Write from datagrid to Excel range Write from datagrid to Excel range
Write from datagrid to Excel range
Write from datagrid to Excel range
 
Write from datagrid to Excel range
Write from datagrid to Excel range
 
-->