에서 Excel 작업 템플리 - 라이브러리없는 (※ 필요 Excel)
1. 컴파일용 배치
※Office의 버젼에 의존하므로, 적절히 변경해 주세요.
compile.bat
csc ^
 /r:C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll ^
 /r:C:\Windows\assembly\GAC_MSIL\office\15.0.0.0__71e9bce111e9429c\Office.dll ^
 %*
 1-1. 컴파일 방법
compile.bat ほげほげ.cs
 2. 현재 열려있는 Excel 파일의 활성 시트를 조작하는 템플릿
・화면 갱신 정지
・재계산 정지
 2-1. 소스 코드
※열려 있는 엑셀 시트에 대해서 처리를 실시하므로, 함부로 실행하지 말아 주세요.
using System;
using System.Runtime.CompilerServices; // to use [MethodImpl(MethodImplOptions.NoInlining)]
using System.Runtime.InteropServices;
using Excel = Microsoft.Office.Interop.Excel;
class ExcelSample
{
    [MethodImpl(MethodImplOptions.NoInlining)] // 最適化抑制
    static void OverwriteActiveSheet()
    {
        Excel.Application oExcelApp = null;
        Excel.Worksheet oSheet = null;
        try {
            oExcelApp = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
        }
        catch ( System.Runtime.InteropServices.COMException ) {
            Console.WriteLine("Failed to get Excel.Application.");
            return;
        }
        try {
            var oBook = (Excel.Workbook)oExcelApp.ActiveWorkbook;
            if ( oBook != null ) {
                oSheet = (Excel.Worksheet)oBook.ActiveSheet;
            }
        }
        catch ( System.Runtime.InteropServices.COMException ) {
        }
        if ( oSheet == null ) {
            Console.WriteLine("Failed to get ActiveWorkbook or ActiveSheet.");
            return;
        }
        bool screenUpdatingBackup = oExcelApp.ScreenUpdating;
        Excel.XlCalculation calcModeBackup = oExcelApp.Calculation;
        try {
            oExcelApp.ScreenUpdating = false; // 画面更新の停止
            oExcelApp.Calculation = Excel.XlCalculation.xlCalculationManual; // 再計算の停止
            // 処理を追加  ここから
            // セルの読み込み
            Excel.Range oCells = oSheet.Cells;
            var oRange = oCells[3, 2] as Excel.Range; // B3セル
            Console.WriteLine(oRange.Value);
            Console.WriteLine(oRange.Value2);
            Console.WriteLine(oRange.Text);
            // セルへの書き込み
            oRange = oCells[4, 3] as Microsoft.Office.Interop.Excel.Range;
            oRange.Value = "hoge";
            // 罫線を引く
            Excel.Borders oBorders;
            Excel.Border oBorder;
            oRange = oSheet.Range[oSheet.Cells[2, 2], oSheet.Cells[4, 4]]; //  select B2 - D4
            oBorders = oRange.Borders;
            oBorder = oBorders[Excel.XlBordersIndex.xlEdgeBottom];// xlEdgeLeft xlEdgeRight xlEdgeTop
            oBorder.LineStyle = Excel.XlLineStyle.xlContinuous;
            // 処理を追加  ここまで
        }
        finally {
            if ( oExcelApp.Calculation != calcModeBackup ) {
                oExcelApp.Calculation = calcModeBackup;
            }
            if ( oExcelApp.ScreenUpdating != screenUpdatingBackup ) {
                oExcelApp.ScreenUpdating = screenUpdatingBackup;
            }
        }
    }
    [STAThread]
    static void Main(string[] args)
    {
        OverwriteActiveSheet();
    }
}
 2-2. 입력 데이터
 
 2-3. 실행 결과
2021/02/03 0:00:00
44230
2月3日
 
 3. Excel 파일 열기 - 참고 사이트
csc ^
 /r:C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll ^
 /r:C:\Windows\assembly\GAC_MSIL\office\15.0.0.0__71e9bce111e9429c\Office.dll ^
 %*
・화면 갱신 정지
・재계산 정지
2-1. 소스 코드
※열려 있는 엑셀 시트에 대해서 처리를 실시하므로, 함부로 실행하지 말아 주세요.
using System;
using System.Runtime.CompilerServices; // to use [MethodImpl(MethodImplOptions.NoInlining)]
using System.Runtime.InteropServices;
using Excel = Microsoft.Office.Interop.Excel;
class ExcelSample
{
    [MethodImpl(MethodImplOptions.NoInlining)] // 最適化抑制
    static void OverwriteActiveSheet()
    {
        Excel.Application oExcelApp = null;
        Excel.Worksheet oSheet = null;
        try {
            oExcelApp = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
        }
        catch ( System.Runtime.InteropServices.COMException ) {
            Console.WriteLine("Failed to get Excel.Application.");
            return;
        }
        try {
            var oBook = (Excel.Workbook)oExcelApp.ActiveWorkbook;
            if ( oBook != null ) {
                oSheet = (Excel.Worksheet)oBook.ActiveSheet;
            }
        }
        catch ( System.Runtime.InteropServices.COMException ) {
        }
        if ( oSheet == null ) {
            Console.WriteLine("Failed to get ActiveWorkbook or ActiveSheet.");
            return;
        }
        bool screenUpdatingBackup = oExcelApp.ScreenUpdating;
        Excel.XlCalculation calcModeBackup = oExcelApp.Calculation;
        try {
            oExcelApp.ScreenUpdating = false; // 画面更新の停止
            oExcelApp.Calculation = Excel.XlCalculation.xlCalculationManual; // 再計算の停止
            // 処理を追加  ここから
            // セルの読み込み
            Excel.Range oCells = oSheet.Cells;
            var oRange = oCells[3, 2] as Excel.Range; // B3セル
            Console.WriteLine(oRange.Value);
            Console.WriteLine(oRange.Value2);
            Console.WriteLine(oRange.Text);
            // セルへの書き込み
            oRange = oCells[4, 3] as Microsoft.Office.Interop.Excel.Range;
            oRange.Value = "hoge";
            // 罫線を引く
            Excel.Borders oBorders;
            Excel.Border oBorder;
            oRange = oSheet.Range[oSheet.Cells[2, 2], oSheet.Cells[4, 4]]; //  select B2 - D4
            oBorders = oRange.Borders;
            oBorder = oBorders[Excel.XlBordersIndex.xlEdgeBottom];// xlEdgeLeft xlEdgeRight xlEdgeTop
            oBorder.LineStyle = Excel.XlLineStyle.xlContinuous;
            // 処理を追加  ここまで
        }
        finally {
            if ( oExcelApp.Calculation != calcModeBackup ) {
                oExcelApp.Calculation = calcModeBackup;
            }
            if ( oExcelApp.ScreenUpdating != screenUpdatingBackup ) {
                oExcelApp.ScreenUpdating = screenUpdatingBackup;
            }
        }
    }
    [STAThread]
    static void Main(string[] args)
    {
        OverwriteActiveSheet();
    }
}
2-2. 입력 데이터

2-3. 실행 결과
2021/02/03 0:00:00
44230
2月3日

3. Excel 파일 열기 - 참고 사이트
【C#】Excel 조작(기동, 편집 등) | CodeTips 【링크 끊어? ]
C #에서 Excel을 조작! 열기, 닫기, 저장 - lisz-works 【링크 끊어? ]
4. 괘선 그리기 - 참고 사이트
5. 셀 결합 - 참고 사이트
요약: Range 에 대해 Merge()
참고 사이트
Microsoft.Office.Interop.Excel을 사용하는 것 이외의 옵션
Reference
이 문제에 관하여(에서 Excel 작업 템플리 - 라이브러리없는 (※ 필요 Excel)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/kob58im/items/780d5b7ddb854b57e98b텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)