C# (Visual Studio 2012 express)で Excel ファイルのA1セルを読み書きする処理
参考にさせてもらったサイト
http://code.msdn.microsoft.com/office/C-Excel-Sheet-5037d251
This file contains hidden or 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(); | |
} | |
} | |
} | |
} |
0 件のコメント:
コメントを投稿