Member 14062287 Ответов: 2

Как вставить вывод консоли в существующий файл excel


Мой консольный код приложения выглядит следующим образом
using System;
using System.IO;

namespace Error1
{
    class ReadWErrorRecords
    {
        public static void Main()
        {
            //the path of the file
            FileStream inFile = new FileStream(@"D:\log-11.13.2018.3.crdownload", FileMode.Open, FileAccess.Read);
            StreamReader reader = new StreamReader(inFile);
            string record;
            string input;
            Console.Write("Search >> ");
            input = Console.ReadLine();
            try
            {
                //the program reads the record and displays it on the screen
                record = reader.ReadLine();
                while (record != null)
                {
                    if (record.Contains(input))
                    {
                        Console.WriteLine(record);
                    }
                    record = reader.ReadLine();
                }
            }
            finally
            {
                //after the record is done being read, the progam closes
                reader.Close();
                inFile.Close();
            }
            Console.ReadLine();
        }
    }
}


Что я уже пробовал:

My console application code as follows<pre lang="c#">using System;
using System.IO;

namespace Error1
{
    class ReadWErrorRecords
    {
        public static void Main()
        {
            //the path of the file
            FileStream inFile = new FileStream(@"D:\log-11.13.2018.3.crdownload", FileMode.Open, FileAccess.Read);
            StreamReader reader = new StreamReader(inFile);
            string record;
            string input;
            Console.Write("Search >> ");
            input = Console.ReadLine();
            try
            {
                //the program reads the record and displays it on the screen
                record = reader.ReadLine();
                while (record != null)
                {
                    if (record.Contains(input))
                    {
                        Console.WriteLine(record);
                    }
                    record = reader.ReadLine();
                }
            }
            finally
            {
                //after the record is done being read, the progam closes
                reader.Close();
                inFile.Close();
            }
            Console.ReadLine();
        }
    }
}

F-ES Sitecore

google "create excel file c#". Это уже подробно задокументировано.

Member 14062287

Теперь в этом конкретном коде какие изменения следует внести чтобы вывод консоли был вставлен в существующий файл excel

Member 14062287

Как мне это сделать без извлечения данных из базы данных

2 Ответов

Рейтинг:
1

Richard MacCutchan

Вы можете использовать буфер обмена и сделать это вручную, но я подозреваю, что это не то, что вы хотите. Чтобы автоматизировать свой код для этого вам нужно использовать Microsoft.Офис.Взаимодействие.Пространство Имен Excel | Microsoft Docs[^].


Рейтинг:
0

CHill60

Вот это CodeProject статьи по теме Работа с Excel с помощью языка Си#[^]