Solved

Populating data from SQL server to excel

Posted on 2011-09-27
4
285 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

729 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