Skip to content

Instantly share code, notes, and snippets.

@cofearabi
Created December 19, 2012 00:04
Show Gist options
  • Save cofearabi/4333269 to your computer and use it in GitHub Desktop.
Save cofearabi/4333269 to your computer and use it in GitHub Desktop.
(C#) read and write the value of A1 cell of Excel sheet
using System;
using Microsoft.Office.Interop.Excel;
namespace COMAutomation_Excel_CS
{
class Program
{
static void Main(string[] args)
{
string fileName = @"C:\mdb\temp2.xlsx";
Application xlApp = new Application();
if (xlApp != null)
{
xlApp.Visible = true;
Workbook wb = xlApp.Workbooks.Open(Filename: fileName);
((Worksheet)wb.Sheets[1]).Select();
Range aRange = xlApp.get_Range("A1") as Range;
if (aRange != null)
{
Console.WriteLine(aRange.Value2 ?? String.Empty);
aRange.Value2 = "コード レシピ Excel編";
Console.WriteLine(aRange.Value2);
}
wb.Close(true);
xlApp.Quit();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment