Example #1
0
        /// <summary>
        /// Attaches to the process started using the file of the provided name.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        public void AttachToProcess(string fileName)
        {
            int processId = ProcessorLibrary.GetProcessID(PROCESS_NAME, fileName);

            if (processId != 0)
            {
                _xlApp = ExcelInteropService.GetExcelInterop(processId);
                Initialize(openWorkbook: false);
            }
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExcelHelper"/> class. <para/>
        /// If a process already exists from a file started at the file path, this process is attached to. <para/>
        /// Otherwise, a new process is started from the file.
        /// </summary>
        /// <param name="path">The file path.</param>
        public ExcelHelper(string path)
        {
            Path = path;
            string fileName = System.IO.Path.GetFileName(path);

            if (ProcessorLibrary.ProcessExists(PROCESS_NAME, fileName))
            {
                AttachToProcess(fileName);
                _attachedToProcess = true;
            }
            else
            {
                Load(path);
            }
        }