Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Good morning Sir,

I have one excel sheet which is on desktop. Now the excel sheet is completely blank. I want to write some value into the excel sheet using C#.net... So please provide me code or Any guidance related to that.

Thank You
Posted
Updated 1-Oct-13 18:55pm
v2

You can use either MS Office Excel interop assembly, which requires Excel installation, or Open XML SDK, which does not. Please see my past answer: How to add microsoft excel 15.0 object library from Add Reference in MS Visual Studio 2010[^].

See also this CodeProject article: Creating basic Excel workbook with Open XML[^].

On interop assembly approach, please see:
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.aspx[^],
http://msdn.microsoft.com/en-us/library/office/ff597926.aspx[^],
http://msdn.microsoft.com/en-us/library/15s06t57.aspx[^].

However, please read some words of warning from Microsoft on the use of interop:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2[^],
http://support.microsoft.com/kb/257757/en-us[^].

—SA
 
Share this answer
 
Here is the code for writing data to excel file on desktop-
C#
//path to file
string path = "C:\\Users\\[User_Name]\\Desktop\\[file_name].xls";
        
        #region Used Excel Objects
        MsExcel.ApplicationClass excelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
        MsExcel.Workbook excelWorkbook = excelApp.Workbooks.Open(path, 0, ture, 5, "", "", false, MsExcel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); ;
        MsExcel.Sheets excelSheets = excelWorkbook.Worksheets;
        //create the object of sheet1    
        MsExcel.Worksheet xlws = (MsExcel.Worksheet)excelSheets.get_Item("sheet1");
        MsExcel.Sheets anna = excelSheets;
        #endregion

        //write data to row 1 and column 1 i.e. "A"
        xlws.Cells[1, 1] = Convert.ToString(Value);
 
Share this answer
 
you do not need excel on your desktop for c#

when you have installed vs on your system and have excell in refrences of vs

you can create and write excel file and write to it for code search msdn example
 
Share this answer
 

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