Who can please let me know:
How to read the excel cells having DOUBLE values into c# from worksheet1.Then do some calculation and write it back into other excel worksheet2?
tnx
Who can please let me know:
How to read the excel cells having DOUBLE values into c# from worksheet1.Then do some calculation and write it back into other excel worksheet2?
tnx
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bechir BejaouiPosted Feb 26, 2009, 5:49 AM
object myConvertingObject = oSheet2.Cells.Cells[row, col] as Range ;
double myConvertedObject = (Double)myConvertingObject;
yamidPosted Feb 23, 2009, 5:11 PM
tnx for your reply but , I could not do some mathematical operation on the value of each cell, because they are obj. would you please tell me how to convert those cell values to Double?
thanks
Bechir BejaouiPosted Feb 23, 2009, 3:51 PM
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Microsoft.Office.Interop.Excel;
namespace ConsoleApplication1
{
class Program
{
static ApplicationClass App;
static Workbooks oBooks;
static Workbook oBook;
static Worksheet oSheet;
static void Main(string[] args)
{
App = null;
oBooks = null;
oBook = null;
oSheet = null;
Console.WriteLine("Enter the Excel file path");
string filepath = Console.ReadLine();
App = new ApplicationClass();
App.Visible = true;
oBooks = App.Workbooks;
//Open a new workbook
oBook = oBooks.Open(filepath,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value);
oSheet = (Worksheet)App.ActiveSheet;
/* After that you can get your cells either by
* range */
Range myRange = oSheet.get_Range("A1", "C3");
//Or by cell
oSheet.Cells.Cells[1, 1] = 2;
//You can get or create another sheet and transmit the content
if (App.Worksheets[2] != null)
{
Worksheet oSheet2 = App.Worksheets[2] as Worksheet;
oSheet2.Cells.Cells[1, 1] = oSheet.Cells.Cells[1, 1];
}
oBook.Save();
App.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(App);
App = null;
}
}
}