Link to home
Create AccountLog in
Avatar of Victor Kimura
Victor KimuraFlag for Canada

asked on

visual C#

Hi,

I'm just wondering if this method can only open and read. I'd like to edit and update the excel file. I guess I can use the OleDbConnection instead but I'm curious. If so, can you provide a bit of code for a simple update?

http://sandeep-aparajit.blogspot.ca/2008/08/how-to-read-excel-in-c.html

  Excel.Workbook workBook = app.Workbooks.Open(...)
SOLUTION
Avatar of Mez4343
Mez4343

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Victor Kimura

ASKER

Oh, just removing duplicates from the excel sheet for now.

Thanks for that link.

do you happen to know of a link for Visual c# too?
SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Hi kaufmed,

Thanks for the link. But I'm wondering if you can provide a sample code for a quick update on an excel file. It would take me a few months to get the hang of all the code but I'm just looking for some sample code for now.

I grabbed this code from that site mentioned above:

// Add Reference
using System;
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Excel;

namespace ReadExcel
{
    /// <summary>
    /// This class will be used to read the excel and 
    /// display it in a console.
    /// </summary>
    class ReadExcelApplication
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            // Path for the test excel application
            string Path = @"c:\test.xls";
            // Initialize the Excel Application class
            Excel.ApplicationClass app = new ApplicationClass();
            // Create the workbook object by opening the excel file.
            Excel.Workbook workBook = app.Workbooks.Open(Path,
                                                         0,
                                                         true,
                                                         5,
                                                         "",
                                                         "",
                                                         true,
                                                         Excel.XlPlatform.xlWindows,
                                                         "\t",
                                                         false,
                                                         false,
                                                         0,
                                                         true,
                                                         1,
                                                         0);
            // Get the active worksheet using sheet name or active sheet
            Excel.Worksheet workSheet = (Excel.Worksheet)workBook.ActiveSheet;

            // This row,column index should be changed as per your need.
            // i.e. which cell in the excel you are interesting to read.
           

Open in new window

I'm confused. I gave you an example right above the link.
Sorry, kaufmed, I wasn't more explicit. I was wondering how to update an existing file.
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.