Solved

Populating data from SQL server to excel

Posted on 2011-09-27
4
284 Views
Last Modified: 2012-05-12
Hi,

I need help on importing data from database to excel.

In excel file, there is a cell (A1 to A4,merged into one) named "ZZZ2".

In c# code after getting the data from database, i used the following code:

Clipboard.SetText(taxyear1_month.ToString());
xlWorkSheet.Paste(xlWorkSheet.get_Range("ZZZ2", "ZZZ2"), false);


It is not working. But if I name a single cell B4 as "zzz5" and use the code:
Clipboard.SetText(taxyear1_month.ToString());
xlWorkSheet.Paste(xlWorkSheet.get_Range("zzz5", "zzz5"), false);
It works.


Please help me to populate data into the merged cell


Regards
0
Comment
Question by:sam000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 28

Expert Comment

by:omgang
ID: 36711545
Both of these tests work for me

Public Function UpdateRange()
'assign value from a cell to a range of merged cells
On Error GoTo Err_UpdateRange

    Dim strValue As String

    strValue = Me.Cells(16, 11).Value
        'ZZZ2 refers to A1:A4 which are merged
    Me.Range("ZZZ2").Value = strValue

Exit_UpdateRange:
    Exit Function

Err_UpdateRange:
    MsgBox Err.Number & " (" & Err.Description & ") in procedure UpdateRange of VBA Document Sheet1"
    Resume Exit_UpdateRange

End Function


Public Function UpdateRange()
'copy value from a cell and paste into a range of merged cells
On Error GoTo Err_UpdateRange
   
    Me.Range("k16", "k16").Copy
   
    Me.Range("ZZZ2", "ZZZ2").PasteSpecial (xlPasteAll)

Exit_UpdateRange:
    Exit Function

Err_UpdateRange:
    MsgBox Err.Number & " (" & Err.Description & ") in procedure UpdateRange of VBA Document Sheet1"
    Resume Exit_UpdateRange

End Function

OM Gang
0
 

Author Comment

by:sam000
ID: 36711565
Could you please tell me a c# reference?
0
 
LVL 28

Accepted Solution

by:
omgang earned 500 total points
ID: 36711829
Try

String sValue = taxyear1_month.ToString();
xlWorkSheet.Range("ZZZ2", "ZZZ2").Value = sValue;

OM Gang
0
 

Author Closing Comment

by:sam000
ID: 37016040
helped a lot
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question