Share via


Edit a Cell in Spreadsheet using C#

Question

Friday, March 22, 2013 11:17 AM

I want to edit a cell in my spreadsheet which is actually in sharepoint list as attachment. how do i edit cells in the spreadsheet ???

All replies (5)

Saturday, March 23, 2013 4:01 AM âś…Answered | 1 vote

You might not want to use interop if you are do web application. Use OpenXML

http://chanmingman.wordpress.com/2012/07/12/simple-same-on-export-to-excel-using-openxml-sdk-in-asp-net/

http://chanmingman.wordpress.com/2012/09/04/import-excel-using-openxml-sdk-in-asp-net-mvc/

chanmm

chanmm


Friday, March 22, 2013 12:09 PM | 1 vote

I assume you're talking about an Excel spreadsheet. If so you can use the Office interop libraries to do this. Add a reference to Microsoft.Office.Interop.Excel to your project, then you can use some code like:

string workbookPath = "put_path_here";
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);

Excel.Sheets excelSheets = excelWorkbook.Worksheets;
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item("Sheet Name");
Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("A1", "A1");

Also check out (http://www.codeproject.com/Articles/5123/Opening-and-Navigating-Excel-with-C)


Sunday, March 24, 2013 6:50 PM

You could try this:

Also, you can try Insert:

I think Update is better for you!!

Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.


Monday, November 4, 2013 5:33 AM

You may want to try this .NET library by eleriumsoft.com to edit an Excel cell, but it is a commercial project:

This simple example shows how to access to excel cell:

using System;  
using System.Collections.Generic;  
using System.Text;  
using Docs.Excel;  
  
namespace CellAddress  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            //Create a new workbook.  
            ExcelWorkbook Wbook = new ExcelWorkbook();  
  
            //Add new worksheet to workbook.  
            Wbook.Worksheets.Add("Sheet1");  
  
            //Example of getting the sheet by index and name.  
            Wbook.Worksheets[0].Cells[0, 0].Value = "A";  
            Wbook.Worksheets["Sheet1"].Cells[1, 0].Value = "B";  
  
            //Example of getting the cell by index of row.  
            Wbook.Worksheets[0].Rows[2].Cells[0].Value = "C";  
  
            //Example of getting the cell by index of column and name of column.  
            Wbook.Worksheets[0].Columns[0].Cells[3].Value = "D";  
            Wbook.Worksheets[0].Columns["A"].Cells[4].Value = "E";  
  
            //Example of simple getting the cell by index of row and index of column.  
            Wbook.Worksheets[0].Cells[5, 0].Value = "F";  
            Wbook.Worksheets[0].Cells["A7"].Value = "G";  
  
            //Example of getting the cell range by index of row and index of column.  
            Wbook.Worksheets[0].Cells["A8:C10"].IsMerged = true;  
  
            //Write text to merged cells.  
            Wbook.Worksheets[0].Cells["A8"].Value = "H";  
  
            // XLS  
            Wbook.WriteXLS(@"..\..\..\ExcelCellAddress.xls");  
  
            // XLSX  
            Wbook.WriteXLSX(@"..\..\..\ExcelCellAddress.xlsx");  
  
            //Open specified file in MS Excel.  
            System.Diagnostics.Process.Start(@"..\..\..\ExcelCellAddress.xlsx");  
  
        }  
    }  
}

 


Wednesday, October 21, 2015 4:49 PM

How to use for sharepoint document library, i tired with no of options no use when i try to open the file it shows the file is moved or deleted but iam running 64bit and also i don't want to use 32bit

for console application it is working fine.. but not for SharePoint application

 Excel.Workbook wb = app.Workbooks.Open(item.File.ToString(), m, false, m, m, m, m, m, m, m, m, m, m, m, m);

so i tried like this

Excel.Workbook wb = app.Workbooks.Open(System.Web.HttpContext.Current.Server.MapPath("http://nftw6mapd043/BOMS/siva.xlsx"),m,false, m, m, m, m, m, m, m, m, m, m, m, m);

no issue do you have any suggestion for this?

Thanks

Sivakumar.K

Sivakarunanithi