Click here to Skip to main content
15,353,416 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Table name as follows Batch

In Batch table record as follows


Table name as follows Feedback

Facid Q1 Q2 Q3 Batchid

1 2 4 5 B001
2 3 3 4 B001
1 4 5 5 B002
2 3 3 4 B002

In excel i want to place Batchid in row wise from Batch table as follows

B001 B002

similarily in excel i want to place Facid in column wise from Feedback table as follows
similarily in excel i want to place Q1 Q2 and Q3 column wise from feedback table as follows

Facid Q1 Q2 Q3
1 2 4 5
2 3 3 4
1 4 5 5
2 3 3 4

in excel how to place above values in using c3, using for loop.

please help me for that how can i do in using c#.

Jegan B.
Sunasara Imdadhusen 17-Jun-14 4:52am
What you tried till. Have you search on Google? 22-Jun-14 4:31am
best way to do this bind you datatable to gridview and export it

please refer this link

1 solution

I didn't understand a single word, but it seem you need something as following
var excelApp = new ApplicationClass {Visible = false}; //use Application for .NET 4.0 and later

var excelWorkbooks = excelApp.Workbooks.Open("yourfilepath");
var excelWorkSheet = (Worksheet) excelWorkbooks.Sheets[yourWorkSheetNumber]; //be sure to cast to  Workseet explictly
excelWorkSheet.Cells[row, column] = yourvalue;
excelWorkbooks.Save(); //calling excelApp.Save(); would cause an exception
Marshal.ReleaseComObject(excelWorkSheet); //release COM-object to terminate processes
CHill60 22-Jun-14 8:08am
This code doesn't even compile.
Extra closing bracket ) on line 2
_excelWorkbooks has not been declared on lines 3 and 8(lose the underscore)
Why on earth force the garbage collection?
Where is the for loop the OP asked for?
Bohdan Stupak 22-Jun-14 8:23am
Sure it doesn't complile. Variables like 'row', 'column' etc aren't defined. That is the way examples are.
Look through stackoverflow. There are loads of issues with Interop.Excel, where garabage collection needs to be forced to force termination of Excel proccess. You might not notice, when you work with 1 file, but when you work with 15 different files it will eat out all of your memory.
About loop. Frankly speaking I just can't figure out where does he want to put it.

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