Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was trying to copy paste a excel data unfortunately i got a merged cell in columns.
i want to copy only that merged cell to sql server using microsoft.interop.excel in vs
(cell present at sheet 1-69 row -b,c colomun)

Can anyone share any reference i can use for this.
Thanks in Advance!!

What I have tried:

using Microsoft.Office.Interop.Excel;

string path = "C:\\Projects\\ExcelSingleValue\\Test.xlsx ";

Application excel = new Application();
Workbook wb = excel.Workbooks.Open(path);
Worksheet excelSheet = wb.ActiveSheet;
Posted
Updated 29-Sep-22 4:30am

1 solution

You select a cell with a Range Interface (Microsoft.Office.Interop.Excel) | Microsoft Learn[^] and that allows you to extract its value.

[edit]
I have not tested this, but something like:
C#
excelSheet.Range myRange = excelSheet.get_Range("B1:C1");

[/edit]
 
Share this answer
 
v4
Comments
Yash S 2022 29-Sep-22 10:41am    
Didn't get that can u share any example !! thanks for reply
Richard MacCutchan 29-Sep-22 11:30am    
See updated solution.
Yash S 2022 29-Sep-22 11:45am    
cannot create an instance of the abstract type or interface 'Range' -error
Richard MacCutchan 29-Sep-22 11:57am    
Sorry, you also need the worksheet reference to get it. However, there is a full example at https://stackoverflow.com/questions/2627343/read-all-the-cell-values-from-an-excel-range-in-c-sharp[^].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900