Created
December 19, 2012 00:04
-
-
Save cofearabi/4333269 to your computer and use it in GitHub Desktop.
(C#) read and write the value of A1 cell of Excel sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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