-
Copy an array to clipboard
Hi,
I hav an array MyArray
I want to copy the content of this array to clipboard, so that it can then be pasted to an excel file..
can any one help me
thnx in advance..
-
This is a new one for me but I don't think the Clipboard object accepts complex types. Since Excel accepts CSV transparently, you could loop through your array building a comma delimited list, and then copy that to the Clipboard object.
Psuedo code:
Code:
dim myListFromArray
for i = 0 to len(myArray)
{
myListFromArray = myListFromArray & ',' & myArray(i)
}
Clipboard.Clear
Clipboard.SetText myListFromArray
Good luck,
Michael Sanchez
Managing Technical Editor
Forum Moderator
FreeVBCode.com
-
MyString = Join(MyArray, vbKeyTab) & vbNewLine
Good Luck
-
Can't solve the issue
Thnx guys for d reply..
usually i copy the rows in a string and paste it to clipboard
using
clipboard.settext strData
But my actual problem is .. ihave a grid with more than 15,000 rows..
since its is large to hold in a string i created a string array and copy the data to it..
but i cannot copy this to clipboard
i tried another method, select the entire grid and copy to clipboard
grid.Col = 0
grid.row = 0
grid.ColSel = grid.Cols - 1
grid.RowSel = grid.Rows - 1
Clipboard.Clear
Clipboard.SetText grid.Clip
but here also i have a problem.. i dont need all columns some should hide..
is there any method to select som specified columns..
Pls help...
grid means MSHFlexGrid
-
Once on the clipboard, what will you do with it?
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
Why go to the clipboard.
You can communicate directly with Excel.
First add a reference to Excel in the project properties Reference tab.
Working with Excel is then pretty easy with code similar to the following:
Dim app As Excel.Application
Dim wks as Excel.Worksheet
'Start Excel
app=New Excel.Application
'Excel is invisible by default
app.Visible=true
'Excel does not create an empty workbook when started by programmation
app.Workbooks.Add
'Reference the first sheet
wks=app.Workbooks(1).Worksheets(1)
'Do whatever you want
wks.Cells(2,2).Value=Grid.Item(2,2).Value
A couple of loops will let you transfer the data, controlling what goes and what does not, even modify it before the transfer.
And you still have a contact with Excel (app), the workbook (app.Workbooks(1) or the worksheet(wks) to do any manipulation you want such as saving the file or adding formulas.
Jacques Bourgeois
JBFI
http://www3.sympatico.ca/jbfi/homeus.htm
-
I knw direct interaction with excel is better.. but the user wants the data in clipboard, so that he can copy it in any excel worksheet.
Can anyone help me to to solve the above listed 2 problems..
-
Send it to Excel, and then Copy to the clipboard from Excel.
Code:
Range("A1:F13").Copy
Since the copy is made from Excel, it will be in the right format for pasting.
Jacques Bourgeois
JBFI
http://www3.sympatico.ca/jbfi/homeus.htm
-
Hi i was trying to just this however i how found a nice easy Native Code Way to copy grid data to clipboard
all i did was copy from a grid then paste in to the following code
Code:
For i = 1 to Len(ClipText)
debug.print "asc-" & Asc(Mid$(ClipText,i,1)) & " - Char - " & Mid$(ClipText,i,1)
Next i
This then listed in the debug windows each char in Ascii
This let me see that the copied data was Tab Delimited with CRLF end of each line
therefore this follow code works great
Code:
For i = 1 To MyGrid.Rows - 1 'From First DataRow (first row has titles)
'Check For Empty Cells
If Grid1.Cell(i, 1).Text <> "" And Grid1.Cell(i, 3).Text Then
'Add To MyString as "TAB delimited
'CR and LF For Newline "Chr(13) & Chr(10)"
MyString = MyString & Grid1.Cell(i, 1).Text & Chr(9) & Grid1.Cell(i, 2).Text & Chr(13) & Chr(10)
End If
Next i
Clipboard.SetText MyString
Then You can easly just paste the data to excel, textboxs, or other grids
I'm using FlexCell Grid, so the code to get the data from the grid maybe differant for you
I Do Realise this is a Old Post however i figured someone will get some help from this
Last edited by Hack; 06-21-2012 at 06:49 AM.
Reason: Added Code Tags
Similar Threads
-
Replies: 5
Last Post: 05-27-2008, 11:17 AM
-
Replies: 6
Last Post: 12-22-2006, 05:51 AM
-
By triley35 in forum .NET
Replies: 1
Last Post: 04-03-2006, 11:55 PM
-
By Michael Bourns in forum VB Classic
Replies: 6
Last Post: 10-26-2000, 06:58 PM
-
By Michael Bourns in forum VB Classic
Replies: 0
Last Post: 10-25-2000, 09:56 PM
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks